diff options
author | Xin Li <delphij@google.com> | 2020-09-10 17:22:01 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-09-10 17:22:01 +0000 |
commit | 8ac6741e47c76bde065f868ea64d2f04541487b9 (patch) | |
tree | 1a679458fdbd8d370692d56791e2bf83acee35b5 /cmds/incident_helper/src/ih_util.cpp | |
parent | 3de940cc40b1e3fdf8224e18a8308a16768cbfa8 (diff) | |
parent | c64112eb974e9aa7638aead998f07a868acfb5a7 (diff) |
Merge "Merge Android R"
Diffstat (limited to 'cmds/incident_helper/src/ih_util.cpp')
-rw-r--r-- | cmds/incident_helper/src/ih_util.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/cmds/incident_helper/src/ih_util.cpp b/cmds/incident_helper/src/ih_util.cpp index 77a56e55045b..557fe9fc400f 100644 --- a/cmds/incident_helper/src/ih_util.cpp +++ b/cmds/incident_helper/src/ih_util.cpp @@ -237,33 +237,38 @@ double toDouble(const std::string& s) { Reader::Reader(const int fd) { mFile = fdopen(fd, "r"); + mBuffer = new char[1024]; mStatus = mFile == nullptr ? "Invalid fd " + std::to_string(fd) : ""; } Reader::~Reader() { if (mFile != nullptr) fclose(mFile); + delete[] mBuffer; } bool Reader::readLine(std::string* line) { if (mFile == nullptr) return false; - char* buf = nullptr; size_t len = 0; - ssize_t read = getline(&buf, &len, mFile); + ssize_t read = getline(&mBuffer, &len, mFile); if (read != -1) { - std::string s(buf); + std::string s(mBuffer); line->assign(trim(s, DEFAULT_NEWLINE)); - } else if (errno == EINVAL) { - mStatus = "Bad Argument"; + return true; } - free(buf); - return read != -1; + if (!feof(mFile)) { + mStatus = "Error reading file. Ferror: " + std::to_string(ferror(mFile)); + } + return false; } bool Reader::ok(std::string* error) { + if (mStatus.empty()) { + return true; + } error->assign(mStatus); - return mStatus.empty(); + return false; } // ============================================================================== |