Replaced ifstreams with file read inside the config and patch config read. (#220)

This commit is contained in:
Chalith Desaman
2021-01-15 11:50:26 +05:30
committed by GitHub
parent b15d8260cc
commit 0914994772
4 changed files with 65 additions and 13 deletions

View File

@@ -364,6 +364,23 @@ namespace util
return name;
}
/**
* Reads from a given file discriptor.
* @param fd File descriptor to be read.
* @param buf String buffer to be populated.
* @return Returns number of bytes read in a successful read and -1 on error.
*/
int read_from_fd(const int fd, std::string &buf)
{
struct stat st;
if (fstat(fd, &st) == -1)
return -1;
buf.resize(st.st_size);
return read(fd, buf.data(), buf.size());
}
/**
* Create a record lock for the file descriptor. Lock is associated with the process (Not for forked child processes).
* @param fd File descriptor to be locked.