Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 25e300af authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "Handle EOF explicitly in incident_helper" into rvc-dev am: 755ce9ed am: 73c4afa4

Change-Id: I974ea9408c59ba53b7d515ac5f42f41b688c910b
parents bb15c56b 73c4afa4
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -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);
    free(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;
    }
    if (!feof(mFile)) {
        mStatus = "Error reading file. Ferror: " + std::to_string(ferror(mFile));
    }
    free(buf);
    return read != -1;
    return false;
}

bool Reader::ok(std::string* error) {
    if (mStatus.empty()) {
        return true;
    }
    error->assign(mStatus);
    return mStatus.empty();
    return false;
}

// ==============================================================================
+1 −0
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@ public:

private:
    FILE* mFile;
    char* mBuffer;
    std::string mStatus;
};