Loading cmds/incident_helper/src/ih_util.cpp +13 −8 Original line number Original line Diff line number Diff line Loading @@ -237,33 +237,38 @@ double toDouble(const std::string& s) { Reader::Reader(const int fd) Reader::Reader(const int fd) { { mFile = fdopen(fd, "r"); mFile = fdopen(fd, "r"); mBuffer = new char[1024]; mStatus = mFile == nullptr ? "Invalid fd " + std::to_string(fd) : ""; mStatus = mFile == nullptr ? "Invalid fd " + std::to_string(fd) : ""; } } Reader::~Reader() Reader::~Reader() { { if (mFile != nullptr) fclose(mFile); if (mFile != nullptr) fclose(mFile); free(mBuffer); } } bool Reader::readLine(std::string* line) { bool Reader::readLine(std::string* line) { if (mFile == nullptr) return false; if (mFile == nullptr) return false; char* buf = nullptr; size_t len = 0; size_t len = 0; ssize_t read = getline(&buf, &len, mFile); ssize_t read = getline(&mBuffer, &len, mFile); if (read != -1) { if (read != -1) { std::string s(buf); std::string s(mBuffer); line->assign(trim(s, DEFAULT_NEWLINE)); line->assign(trim(s, DEFAULT_NEWLINE)); } else if (errno == EINVAL) { return true; mStatus = "Bad Argument"; } if (!feof(mFile)) { mStatus = "Error reading file. Ferror: " + std::to_string(ferror(mFile)); } } free(buf); return false; return read != -1; } } bool Reader::ok(std::string* error) { bool Reader::ok(std::string* error) { if (mStatus.empty()) { return true; } error->assign(mStatus); error->assign(mStatus); return mStatus.empty(); return false; } } // ============================================================================== // ============================================================================== Loading cmds/incident_helper/src/ih_util.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -117,6 +117,7 @@ public: private: private: FILE* mFile; FILE* mFile; char* mBuffer; std::string mStatus; std::string mStatus; }; }; Loading Loading
cmds/incident_helper/src/ih_util.cpp +13 −8 Original line number Original line Diff line number Diff line Loading @@ -237,33 +237,38 @@ double toDouble(const std::string& s) { Reader::Reader(const int fd) Reader::Reader(const int fd) { { mFile = fdopen(fd, "r"); mFile = fdopen(fd, "r"); mBuffer = new char[1024]; mStatus = mFile == nullptr ? "Invalid fd " + std::to_string(fd) : ""; mStatus = mFile == nullptr ? "Invalid fd " + std::to_string(fd) : ""; } } Reader::~Reader() Reader::~Reader() { { if (mFile != nullptr) fclose(mFile); if (mFile != nullptr) fclose(mFile); free(mBuffer); } } bool Reader::readLine(std::string* line) { bool Reader::readLine(std::string* line) { if (mFile == nullptr) return false; if (mFile == nullptr) return false; char* buf = nullptr; size_t len = 0; size_t len = 0; ssize_t read = getline(&buf, &len, mFile); ssize_t read = getline(&mBuffer, &len, mFile); if (read != -1) { if (read != -1) { std::string s(buf); std::string s(mBuffer); line->assign(trim(s, DEFAULT_NEWLINE)); line->assign(trim(s, DEFAULT_NEWLINE)); } else if (errno == EINVAL) { return true; mStatus = "Bad Argument"; } if (!feof(mFile)) { mStatus = "Error reading file. Ferror: " + std::to_string(ferror(mFile)); } } free(buf); return false; return read != -1; } } bool Reader::ok(std::string* error) { bool Reader::ok(std::string* error) { if (mStatus.empty()) { return true; } error->assign(mStatus); error->assign(mStatus); return mStatus.empty(); return false; } } // ============================================================================== // ============================================================================== Loading
cmds/incident_helper/src/ih_util.h +1 −0 Original line number Original line Diff line number Diff line Loading @@ -117,6 +117,7 @@ public: private: private: FILE* mFile; FILE* mFile; char* mBuffer; std::string mStatus; std::string mStatus; }; }; Loading