X-Git-Url: http://wpitchoune.net/gitweb/?p=psensor-pkg-debian.git;a=blobdiff_plain;f=src%2Flib%2Fpio.c;h=ef0c90134c038c4864d029780ce6e6334531fcd6;hp=4a1a6ce5b479f96dd8baf6a40fabdc6e9d891fdc;hb=bd7036af56a4b61b2b473dccbeac5e26f78b57da;hpb=e248180cc4ebc258fdd5778a26c08287089165b1 diff --git a/src/lib/pio.c b/src/lib/pio.c index 4a1a6ce..ef0c901 100644 --- a/src/lib/pio.c +++ b/src/lib/pio.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014 jeanfi@gmail.com + * Copyright (C) 2010-2016 jeanfi@gmail.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -30,7 +30,8 @@ #include /* Directory separator is \ when cross-compiling for MS Windows - systems */ + * systems + */ #if defined(__MINGW32__) #define DIRSEP ('\\') #else @@ -63,7 +64,7 @@ int is_file(const char *path) return 0; } -char *dir_normalize(const char *dpath) +static char *dir_normalize(const char *dpath) { char *npath; int n; @@ -164,15 +165,16 @@ char *file_get_content(const char *fpath) } else { FILE *fp = fopen(fpath, "rb"); + if (fp) { page = malloc(size + 1); if (!page || size != fread(page, 1, size, fp)) { free(page); - return NULL; + page = NULL; + } else { + *(page + size) = '\0'; } - *(page + size) = '\0'; - fclose(fp); } else { page = NULL; @@ -185,25 +187,24 @@ char *file_get_content(const char *fpath) long file_get_size(const char *path) { FILE *fp; + long size; if (!is_file(path)) return -1; fp = fopen(path, "rb"); if (fp) { - long size; - if (fseek(fp, 0, SEEK_END) == -1) - return -1; - - size = ftell(fp); + size = -1; + else + size = ftell(fp); fclose(fp); - - return size; + } else { + size = -1; } - return -1; + return size; } #define FCOPY_BUF_SZ 4096