#include #include #include #include #include #include using namespace std; extern "C" { int GetString(int fd, char * buffer, int maxBufSize); } int GetString(int fd, char * buffer, int maxBufSize) { static FILE * theFile {fdopen(fd, "r")}; if (theFile == nullptr) { cerr << "Failed to open the file descriptor" << endl; throw system_error(errno, generic_category(), "Failed to open the file descriptor"); } string fmtString = "%" + to_string(maxBufSize) + "s"; int len = fscanf(theFile, fmtString.c_str(), buffer); return len; }