X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fio.c;h=a7c46af213306a4291d753ca07383cb7062f90c9;hb=04e8520815632d17a6705219ad8301c1352058f6;hp=aeeed8c962c3f9e8c57f29fa57d93b461f18d6f8;hpb=df19eac22b08c4793607679e2ea471ae64b824fd;p=ppastats.git diff --git a/src/io.c b/src/io.c index aeeed8c..a7c46af 100644 --- a/src/io.c +++ b/src/io.c @@ -20,9 +20,18 @@ #include #include #include +#include #include "io.h" +/* Directory separator is \ when cross-compiling for MS Windows + systems */ +#if defined(__MINGW32__) +#define DIRSEP '\\' +#else +#define DIRSEP '/' +#endif + #define FCOPY_BUF_SZ 4096 static int file_copy(FILE *src, FILE *dst) @@ -88,3 +97,24 @@ char *path_append(const char *odir, const char *name) return dir; } +void mkdirs(const char *dirs, mode_t mode) +{ + char *c = (char *)dirs; + char *dir = malloc(strlen(dirs) + 1); + + int i = 0; + while (*c) { + if ((*c == DIRSEP || *c == '\0') && c != dirs) { + strncpy(dir, dirs, i); + dir[i] = '\0'; + mkdir(dir, mode); + } + + c++; + i++; + } + + mkdir(dirs, mode); + + free(dir); +}