X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_utils.c;h=add19c31af61027762f10aa3e658e9e5419a2066;hp=6853c66dacef29fd655d9c60d90d80597c1313ba;hb=0b3205462f58dc3d59fe016563629e0bd03f8ae3;hpb=9e2eb0abd095264f584490ede57ae5afe8beb748 diff --git a/src/rrd_utils.c b/src/rrd_utils.c index 6853c66..add19c3 100644 --- a/src/rrd_utils.c +++ b/src/rrd_utils.c @@ -25,19 +25,24 @@ #include #include -#include #include #include #include #include +#ifndef _MSC_VER +#include #include - +#endif #ifdef WIN32 # define random() rand() # define srandom(x) srand(x) # define getpid() 0 #endif /* WIN32 */ +#ifndef S_ISDIR +#define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR) +#endif + /* make sure that the random number generator seeded EXACTLY ONCE */ long rrd_random(void) { @@ -171,20 +176,39 @@ int rrd_mkdir_p(const char *pathname, mode_t mode) if (NULL == (pathname_copy = strdup(pathname))) return -1; - base_dir = dirname(pathname_copy); +#ifndef _MSC_VER + /* the data pointedd too by dirname might change too (bsd) */ + if (NULL == (base_dir = strdup(dirname(pathname_copy)))) { + free(pathname_copy); + return -1; + } +#else + _splitpath(pathname_copy, NULL, base_dir, NULL, NULL); +#endif if (0 != rrd_mkdir_p(base_dir, mode)) { int orig_errno = errno; free(pathname_copy); +#ifndef _MSC_VER + free(base_dir); +#endif errno = orig_errno; return -1; } free(pathname_copy); +#ifndef _MSC_VER + free(base_dir); +#endif /* keep errno as set by mkdir() */ +#ifdef _MSC_VER + if (0 != mkdir(pathname)) + return -1; +#else if (0 != mkdir(pathname, mode)) return -1; +#endif return 0; } /* rrd_mkdir_p */