summaryrefslogtreecommitdiff
path: root/libbb/make_directory.c
diff options
context:
space:
mode:
authorGlenn L McGrath2002-11-24 22:48:20 +0000
committerGlenn L McGrath2002-11-24 22:48:20 +0000
commit822e7fd587d603b3a47e09d9be5305ccd9cc4c43 (patch)
treeede36c0fb879eabac998523f7a44a828cacbc159 /libbb/make_directory.c
parenteda4f53f2ebf3d9565c3d7aa500a2e1d9cfd9774 (diff)
downloadbusybox-822e7fd587d603b3a47e09d9be5305ccd9cc4c43.zip
busybox-822e7fd587d603b3a47e09d9be5305ccd9cc4c43.tar.gz
When making parent directories set permissions based on the base parent tree rather than the new directory to be created.
Diffstat (limited to 'libbb/make_directory.c')
-rw-r--r--libbb/make_directory.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/libbb/make_directory.c b/libbb/make_directory.c
index ca3eb49..e25ac21 100644
--- a/libbb/make_directory.c
+++ b/libbb/make_directory.c
@@ -38,24 +38,41 @@
* Also create parent directories as necessary if flags contains
* FILEUTILS_RECUR. */
+static mode_t default_permission(char *path, mode_t old_permision)
+{
+ struct stat statbuf;
+ char *pp;
+
+ statbuf.st_mode = 0777;
+
+ /* stat the directory */
+ pp = strrchr(path, '/');
+ if ((pp) && (pp != path)) {
+ *pp = '\0';
+ stat(path, &statbuf);
+ *pp = '/';
+ }
+
+ return(statbuf.st_mode & old_permision);
+}
+
int make_directory (char *path, long mode, int flags)
{
int ret;
-
- /* Calling apps probably should use 0777 instead of -1
- * then we dont need this condition
- */
- if (mode == -1) {
- mode = 0777;
- }
+
if (flags == FILEUTILS_RECUR) {
char *pp = strrchr(path, '/');
if ((pp) && (pp != path)) {
*pp = '\0';
- make_directory(path, mode, flags);
+ make_directory(path, -1, flags);
*pp = '/';
}
}
+
+ if (mode == -1) {
+ mode = default_permission(path, 07777);
+ }
+
ret = mkdir(path, mode);
if (ret == -1) {
if ((flags == FILEUTILS_RECUR) && (errno == EEXIST)) {
@@ -64,5 +81,6 @@ int make_directory (char *path, long mode, int flags)
perror_msg_and_die("Cannot create directory '%s'", path);
}
}
+
return(ret);
}