diff options
author | Glenn L McGrath | 2002-08-23 17:19:26 +0000 |
---|---|---|
committer | Glenn L McGrath | 2002-08-23 17:19:26 +0000 |
commit | fbef225c4b8d0fd3f1d34e3b0f80bf8e236861e6 (patch) | |
tree | 5df157074cf4a2a9198a159c02cff8a1850198c2 /libbb/make_directory.c | |
parent | 192ff35d9c068d105d350d9e9e822ff0db520646 (diff) | |
download | busybox-fbef225c4b8d0fd3f1d34e3b0f80bf8e236861e6.zip busybox-fbef225c4b8d0fd3f1d34e3b0f80bf8e236861e6.tar.gz |
Rewrite, its smaller
Diffstat (limited to 'libbb/make_directory.c')
-rw-r--r-- | libbb/make_directory.c | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/libbb/make_directory.c b/libbb/make_directory.c index a06a410..ca5ce7d 100644 --- a/libbb/make_directory.c +++ b/libbb/make_directory.c @@ -3,6 +3,10 @@ * Mini make_directory implementation for busybox * * Copyright (C) 2001 Matt Kraai. + * + * Rewriten in 2002 + * Copyright (C) 2002 Glenn McGrath + * Copyright (C) 2002 Vladimir N. Oleynik * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,37 +39,25 @@ int make_directory (char *path, long mode, int flags) { - if (!(flags & FILEUTILS_RECUR)) { - if (mkdir (path, 0777) < 0) { - perror_msg ("Cannot create directory `%s'", path); - return -1; - } - - if (mode != -1 && chmod (path, mode) < 0) { - perror_msg ("Cannot set permissions of directory `%s'", path); - return -1; - } - } else { - struct stat st; - - if (stat (path, &st) < 0 && errno == ENOENT) { - int status; - char *buf, *parent; - mode_t mask; - - mask = umask (0); - umask (mask); + int ret; - buf = xstrdup (path); - parent = dirname (buf); - status = make_directory (parent, (0777 & ~mask) | 0300, - FILEUTILS_RECUR); - free (buf); - - if (status < 0 || make_directory (path, mode, 0) < 0) - return -1; + /* 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 = '\0'; + make_directory(path, mode, flags); + *pp = '/'; } } - - return 0; + ret = mkdir(path, mode); + if ( (ret == -1) && (errno != EEXIST) ) { + perror_msg("Cannot create directory %s", path); + } + return ret; } |