X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_tail.c;h=365bf558b55065fdae6327401495e5b1751ef878;hb=ce2eb567629eb21d650d5c27fefe607837c061fd;hp=b5dc5af98d598027106f833e8add0f5d81bd1acc;hpb=5a32acd88719481cc22aaecd36f3cbc11f3a3489;p=collectd.git diff --git a/src/utils_tail.c b/src/utils_tail.c index b5dc5af9..365bf558 100644 --- a/src/utils_tail.c +++ b/src/utils_tail.c @@ -43,13 +43,11 @@ struct cu_tail_s { static int cu_tail_reopen(cu_tail_t *obj) { int seek_end = 0; - FILE *fh; struct stat stat_buf = {0}; - int status; - status = stat(obj->file, &stat_buf); + int status = stat(obj->file, &stat_buf); if (status != 0) { - ERROR("utils_tail: stat (%s) failed: %s", obj->file, STRERRNO); + P_ERROR("utils_tail: stat (%s) failed: %s", obj->file, STRERRNO); return -1; } @@ -57,10 +55,10 @@ static int cu_tail_reopen(cu_tail_t *obj) { if ((obj->fh != NULL) && (stat_buf.st_ino == obj->stat.st_ino)) { /* Seek to the beginning if file was truncated */ if (stat_buf.st_size < obj->stat.st_size) { - INFO("utils_tail: File `%s' was truncated.", obj->file); + P_INFO("utils_tail: File `%s' was truncated.", obj->file); status = fseek(obj->fh, 0, SEEK_SET); if (status != 0) { - ERROR("utils_tail: fseek (%s) failed: %s", obj->file, STRERRNO); + P_ERROR("utils_tail: fseek (%s) failed: %s", obj->file, STRERRNO); fclose(obj->fh); obj->fh = NULL; return -1; @@ -75,16 +73,16 @@ static int cu_tail_reopen(cu_tail_t *obj) { if ((obj->stat.st_ino == 0) || (obj->stat.st_ino == stat_buf.st_ino)) seek_end = 1; - fh = fopen(obj->file, "r"); + FILE *fh = fopen(obj->file, "r"); if (fh == NULL) { - ERROR("utils_tail: fopen (%s) failed: %s", obj->file, STRERRNO); + P_ERROR("utils_tail: fopen (%s) failed: %s", obj->file, STRERRNO); return -1; } if (seek_end != 0) { status = fseek(fh, 0, SEEK_END); if (status != 0) { - ERROR("utils_tail: fseek (%s) failed: %s", obj->file, STRERRNO); + P_ERROR("utils_tail: fseek (%s) failed: %s", obj->file, STRERRNO); fclose(fh); return -1; } @@ -144,7 +142,7 @@ int cu_tail_readline(cu_tail_t *obj, char *buf, int buflen) { * be fine and we can return. */ clearerr(obj->fh); if (fgets(buf, buflen, obj->fh) != NULL) { - buf[buflen - 1] = 0; + buf[buflen - 1] = '\0'; return 0; } @@ -170,7 +168,7 @@ int cu_tail_readline(cu_tail_t *obj, char *buf, int buflen) { /* If we get here: file was re-opened and there may be more to read.. Let's * try again. */ if (fgets(buf, buflen, obj->fh) != NULL) { - buf[buflen - 1] = 0; + buf[buflen - 1] = '\0'; return 0; }