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 9bd60be2b6..36250e4ec0 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -173,7 +173,7 @@ static int32_t taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { char line[1024]; ssize_t bytes = taosGetsFile(pFile, sizeof(line), line); - if (bytes < 0) { + if (bytes <= 0) { taosCloseFile(&pFile); return -1; } @@ -215,7 +215,7 @@ static int32_t taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { char line[1024] = {0}; ssize_t bytes = taosGetsFile(pFile, sizeof(line), line); - if (bytes < 0) { + if (bytes <= 0) { taosCloseFile(&pFile); return -1; } @@ -378,7 +378,7 @@ int32_t taosGetOsReleaseName(char *releaseName, char* sName, char* ver, int32_t TdFilePtr pFile = taosOpenFile("/etc/os-release", TD_FILE_READ | TD_FILE_STREAM); if (pFile == NULL) return code; - while ((size = taosGetsFile(pFile, sizeof(line), line)) != -1) { + while ((size = taosGetsFile(pFile, sizeof(line), line)) > 0) { line[size - 1] = '\0'; if (strncmp(line, "NAME", 4) == 0) { dest = sName; @@ -456,7 +456,7 @@ int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores) { TdFilePtr pFile = taosOpenFile("/proc/cpuinfo", TD_FILE_READ | TD_FILE_STREAM); if (pFile == NULL) return code; - while (done != 3 && (size = taosGetsFile(pFile, sizeof(line), line)) != -1) { + while (done != 3 && (size = taosGetsFile(pFile, sizeof(line), line)) > 0) { line[size - 1] = '\0'; if (((done & 1) == 0) && strncmp(line, "model name", 10) == 0) { const char *v = strchr(line, ':') + 2; @@ -516,7 +516,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; } @@ -530,7 +530,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; } @@ -691,7 +691,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) { @@ -895,7 +895,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);