X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fhtml.c;fp=src%2Fhtml.c;h=9eb0bcf65f272a4588cdf4da8d301f064313486a;hb=6b077ee78bd064474b576e076383503e682a1dd2;hp=7f8a8d39af8ad02bbf4d351725bb1a8209ee6d25;hpb=73d3e7f2451b8e30d39185529fd69bf2765a6d8f;p=ppastats.git diff --git a/src/html.c b/src/html.c index 7f8a8d3..9eb0bcf 100644 --- a/src/html.c +++ b/src/html.c @@ -27,18 +27,11 @@ #include #include "html.h" +#include "io.h" #include "lp.h" #include "lp_ws.h" #include "ppastats.h" -enum file_copy_error { - FILE_COPY_ERROR_OPEN_SRC = 1, - FILE_COPY_ERROR_OPEN_DST, - FILE_COPY_ERROR_READ, - FILE_COPY_ERROR_WRITE, - FILE_COPY_ERROR_ALLOC_BUFFER -}; - #define HTML_FOOTER \ "
Generated by \ ppastats
\n\ @@ -152,63 +145,6 @@ enum file_copy_error { \n\ %s" -#define FCOPY_BUF_SZ 4096 -static int file_copy(FILE * src, FILE * dst) -{ - int ret = 0; - char *buf = malloc(FCOPY_BUF_SZ); - int n; - - if (!buf) - return FILE_COPY_ERROR_ALLOC_BUFFER; - - while (!ret) { - n = fread(buf, 1, FCOPY_BUF_SZ, src); - if (n) { - if (fwrite(buf, 1, n, dst) != n) - ret = FILE_COPY_ERROR_WRITE; - } else { - if (!feof(src)) - ret = FILE_COPY_ERROR_READ; - else - break; - } - } - - free(buf); - - return ret; -} - -int -fcopy(const char *src, const char *dst) -{ - FILE *fsrc, *fdst; - int ret = 0; - - if (debug) - printf("DEBUG: copy: %s to %s\n", src, dst); - - fsrc = fopen(src, "r"); - - if (fsrc) { - fdst = fopen(dst, "w+"); - - if (fdst) { - ret = file_copy(fsrc, fdst); - fclose(fdst); - } else { - ret = FILE_COPY_ERROR_OPEN_DST; - } - - fclose(fsrc); - } else { - ret = FILE_COPY_ERROR_OPEN_SRC; - } - - return ret; -} - static char *path_new(const char *dir, const char *file, const char *suffixe) { char *path = malloc(strlen(dir)+1+