aboutsummaryrefslogtreecommitdiff
path: root/libbb/make_directory.c
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2002-11-24 22:48:20 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2002-11-24 22:48:20 +0000
commit822e7fd587d603b3a47e09d9be5305ccd9cc4c43 (patch)
treeede36c0fb879eabac998523f7a44a828cacbc159 /libbb/make_directory.c
parenteda4f53f2ebf3d9565c3d7aa500a2e1d9cfd9774 (diff)
downloadbusybox-w32-822e7fd587d603b3a47e09d9be5305ccd9cc4c43.tar.gz
busybox-w32-822e7fd587d603b3a47e09d9be5305ccd9cc4c43.tar.bz2
busybox-w32-822e7fd587d603b3a47e09d9be5305ccd9cc4c43.zip
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 ca3eb495c..e25ac21ee 100644
--- a/libbb/make_directory.c
+++ b/libbb/make_directory.c
@@ -38,24 +38,41 @@
38 * Also create parent directories as necessary if flags contains 38 * Also create parent directories as necessary if flags contains
39 * FILEUTILS_RECUR. */ 39 * FILEUTILS_RECUR. */
40 40
41static mode_t default_permission(char *path, mode_t old_permision)
42{
43 struct stat statbuf;
44 char *pp;
45
46 statbuf.st_mode = 0777;
47
48 /* stat the directory */
49 pp = strrchr(path, '/');
50 if ((pp) && (pp != path)) {
51 *pp = '\0';
52 stat(path, &statbuf);
53 *pp = '/';
54 }
55
56 return(statbuf.st_mode & old_permision);
57}
58
41int make_directory (char *path, long mode, int flags) 59int make_directory (char *path, long mode, int flags)
42{ 60{
43 int ret; 61 int ret;
44 62
45 /* Calling apps probably should use 0777 instead of -1
46 * then we dont need this condition
47 */
48 if (mode == -1) {
49 mode = 0777;
50 }
51 if (flags == FILEUTILS_RECUR) { 63 if (flags == FILEUTILS_RECUR) {
52 char *pp = strrchr(path, '/'); 64 char *pp = strrchr(path, '/');
53 if ((pp) && (pp != path)) { 65 if ((pp) && (pp != path)) {
54 *pp = '\0'; 66 *pp = '\0';
55 make_directory(path, mode, flags); 67 make_directory(path, -1, flags);
56 *pp = '/'; 68 *pp = '/';
57 } 69 }
58 } 70 }
71
72 if (mode == -1) {
73 mode = default_permission(path, 07777);
74 }
75
59 ret = mkdir(path, mode); 76 ret = mkdir(path, mode);
60 if (ret == -1) { 77 if (ret == -1) {
61 if ((flags == FILEUTILS_RECUR) && (errno == EEXIST)) { 78 if ((flags == FILEUTILS_RECUR) && (errno == EEXIST)) {
@@ -64,5 +81,6 @@ int make_directory (char *path, long mode, int flags)
64 perror_msg_and_die("Cannot create directory '%s'", path); 81 perror_msg_and_die("Cannot create directory '%s'", path);
65 } 82 }
66 } 83 }
84
67 return(ret); 85 return(ret);
68} 86}