From: oetiker Date: Wed, 23 Nov 2011 08:52:37 +0000 (+0000) Subject: make rrd_mkdir_p work on bsd* unixes too ... their dirname call works differently... X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=commitdiff_plain;h=0b3205462f58dc3d59fe016563629e0bd03f8ae3;hp=fd168f7d90fe82bb26a41c5831dc0661f67f3d1a make rrd_mkdir_p work on bsd* unixes too ... their dirname call works differently ... #305 git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@2217 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/src/rrd_utils.c b/src/rrd_utils.c index 3c4930f..add19c3 100644 --- a/src/rrd_utils.c +++ b/src/rrd_utils.c @@ -177,23 +177,33 @@ int rrd_mkdir_p(const char *pathname, mode_t mode) return -1; #ifndef _MSC_VER - base_dir = dirname(pathname_copy); + /* 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); + _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)) + if (0 != mkdir(pathname)) return -1; #else if (0 != mkdir(pathname, mode))