moved copy fcts to separate file
[ppastats.git] / src / html.c
index 7f8a8d3..9eb0bcf 100644 (file)
 #include <json/json.h>
 
 #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 \
 " <div id=\"footer\">Generated by \
 <a href='http://wpitchoune.net/ppastats'>ppastats</a></div>\n\
@@ -152,63 +145,6 @@ enum file_copy_error {
     </div>\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+