X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fcommon.c;h=79e4c02c631841334307222430e02d4bc381153d;hb=5d9ad0bcb8b1ae1b7b0994f51237c04273f5cfbc;hp=d617832ca48d6a29680ea7482df8b67e13255b5f;hpb=f19f64d583ab6e1ccf6f4b5e312425330ec1d97c;p=collectd.git diff --git a/src/common.c b/src/common.c index d617832c..79e4c02c 100644 --- a/src/common.c +++ b/src/common.c @@ -1213,18 +1213,25 @@ int walk_directory (const char *dir, dirwalk_callback_f callback, return (0); } -int read_file_contents (const char *filename, char *buf, int bufsize) +ssize_t read_file_contents (const char *filename, char *buf, size_t bufsize) { FILE *fh; - int n; + ssize_t ret; - if ((fh = fopen (filename, "r")) == NULL) - return -1; + fh = fopen (filename, "r"); + if (fh == NULL) + return (-1); - n = fread(buf, 1, bufsize, fh); - fclose(fh); + ret = (ssize_t) fread (buf, 1, bufsize, fh); + if ((ret == 0) && (ferror (fh) != 0)) + { + ERROR ("read_file_contents: Reading file \"%s\" failed.", + filename); + ret = -1; + } - return n; + fclose(fh); + return (ret); } counter_t counter_diff (counter_t old_value, counter_t new_value)