diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 8573dd38bb..d94bddcea4 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -1442,7 +1442,12 @@ int64_t taosGetsFile(TdFilePtr pFile, int32_t maxSize, char *__restrict buf) { } if (fgets(buf, maxSize, pFile->fp) == NULL) { - return 0; + if (feof(pFile->fp)) { + return 0; + } else { + terrno = TAOS_SYSTEM_ERROR(ferror(pFile->fp)); + return terrno; + } } return strlen(buf); diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index a055d1b655..d7da9c7b3c 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -538,7 +538,7 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) { goto _sys; } char qline[32] = {0}; - if (taosGetsFile(pFile, sizeof(qline), qline) < 0) { + if (taosGetsFile(pFile, sizeof(qline), qline) <= 0) { taosCloseFile(&pFile); goto _sys; } @@ -552,7 +552,7 @@ static int32_t taosCntrGetCpuCores(float *numOfCores) { goto _sys; } char pline[32] = {0}; - if (taosGetsFile(pFile, sizeof(pline), pline) < 0) { + if (taosGetsFile(pFile, sizeof(pline), pline) <= 0) { taosCloseFile(&pFile); goto _sys; } @@ -713,7 +713,7 @@ int32_t taosGetProcMemory(int64_t *usedKB) { char line[1024] = {0}; while (!taosEOFFile(pFile)) { bytes = taosGetsFile(pFile, sizeof(line), line); - if (bytes < 0) { + if (bytes <= 0) { break; } if (strstr(line, "VmRSS:") != NULL) { @@ -917,7 +917,7 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { char nouse0[200] = {0}; _bytes = taosGetsFile(pFile, sizeof(line), line); - if (_bytes < 0) { + if (_bytes <= 0) { break; } diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index e04566aadb..dbaf108e6a 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -1118,7 +1118,7 @@ void shellSourceFile(const char *file) { } char *line = taosMemoryMalloc(TSDB_MAX_ALLOWED_SQL_LEN + 1); - while ((read_len = taosGetsFile(pFile, TSDB_MAX_ALLOWED_SQL_LEN, line)) != -1) { + while ((read_len = taosGetsFile(pFile, TSDB_MAX_ALLOWED_SQL_LEN, line)) > 0) { if ( cmd_len + read_len >= TSDB_MAX_ALLOWED_SQL_LEN) { printf("read command line too long over 1M, ignore this line. cmd_len = %d read_len=%d \n", (int32_t)cmd_len, read_len); cmd_len = 0; diff --git a/utils/tsim/src/simParse.c b/utils/tsim/src/simParse.c index fbaf08bf3b..951a3ee903 100644 --- a/utils/tsim/src/simParse.c +++ b/utils/tsim/src/simParse.c @@ -198,7 +198,7 @@ SScript *simParseScript(char *fileName) { simResetParser(); while (!taosEOFFile(pFile)) { - if (taosGetsFile(pFile, sizeof(buffer) - 1, buffer) == -1) continue; + if (taosGetsFile(pFile, sizeof(buffer) - 1, buffer) <= 0) continue; lineNum++; int32_t cmdlen = (int32_t)strlen(buffer);