summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b7e2980)
raw | patch | inline | side by side (parent: b7e2980)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 29 Jun 2014 19:52:30 +0000 (21:52 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sun, 29 Jun 2014 19:56:25 +0000 (21:56 +0200) |
This behaves badly when trying to create base directories like /var/run/ ;-)
src/utils/os.c | patch | blob | history |
diff --git a/src/utils/os.c b/src/utils/os.c
index b1e143a6a651d140e0ee10ce36fdff7f05da421b..ecca206a1e57c11d98343c680531373cfd918f24 100644 (file)
--- a/src/utils/os.c
+++ b/src/utils/os.c
#include <libgen.h>
/*
- * private helper functions
+ * public API
*/
-/*
- * Recursively create the directory 'pathname' using the specified 'mode'. If
- * 'enforce_mode' is true, the mode will be enforced even if the directory
- * exists already.
- */
-static int
-mkdir_rec(const char *pathname, mode_t mode, _Bool enforce_mode)
+int
+sdb_mkdir_all(const char *pathname, mode_t mode)
{
struct stat st;
char *base_dir;
errno = ENOTDIR;
return -1;
}
-
- if ((st.st_mode != mode) && enforce_mode)
- return chmod(pathname, mode);
return 0;
}
return -1;
base_dir = dirname(base_dir);
- /* don't enforce the mode on parent directories */
- status = mkdir_rec(base_dir, mode, 0);
+ status = sdb_mkdir_all(base_dir, mode);
if (! status)
status = mkdir(pathname, mode);
free(base_dir);
return status;
-} /* mkdir_rec */
-
-/*
- * public API
- */
-
-int
-sdb_mkdir_all(const char *pathname, mode_t mode)
-{
- return mkdir_rec(pathname, mode, 1);
} /* sdb_mkdir_all */
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */