diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2002-08-23 17:19:26 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2002-08-23 17:19:26 +0000 |
commit | fbef225c4b8d0fd3f1d34e3b0f80bf8e236861e6 (patch) | |
tree | 5df157074cf4a2a9198a159c02cff8a1850198c2 /libbb/make_directory.c | |
parent | 192ff35d9c068d105d350d9e9e822ff0db520646 (diff) | |
download | busybox-w32-fbef225c4b8d0fd3f1d34e3b0f80bf8e236861e6.tar.gz busybox-w32-fbef225c4b8d0fd3f1d34e3b0f80bf8e236861e6.tar.bz2 busybox-w32-fbef225c4b8d0fd3f1d34e3b0f80bf8e236861e6.zip |
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 a06a410d2..ca5ce7dc2 100644 --- a/libbb/make_directory.c +++ b/libbb/make_directory.c | |||
@@ -3,6 +3,10 @@ | |||
3 | * Mini make_directory implementation for busybox | 3 | * Mini make_directory implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 2001 Matt Kraai. | 5 | * Copyright (C) 2001 Matt Kraai. |
6 | * | ||
7 | * Rewriten in 2002 | ||
8 | * Copyright (C) 2002 Glenn McGrath | ||
9 | * Copyright (C) 2002 Vladimir N. Oleynik | ||
6 | * | 10 | * |
7 | * This program is free software; you can redistribute it and/or modify | 11 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by | 12 | * it under the terms of the GNU General Public License as published by |
@@ -35,37 +39,25 @@ | |||
35 | 39 | ||
36 | int make_directory (char *path, long mode, int flags) | 40 | int make_directory (char *path, long mode, int flags) |
37 | { | 41 | { |
38 | if (!(flags & FILEUTILS_RECUR)) { | 42 | int ret; |
39 | if (mkdir (path, 0777) < 0) { | ||
40 | perror_msg ("Cannot create directory `%s'", path); | ||
41 | return -1; | ||
42 | } | ||
43 | |||
44 | if (mode != -1 && chmod (path, mode) < 0) { | ||
45 | perror_msg ("Cannot set permissions of directory `%s'", path); | ||
46 | return -1; | ||
47 | } | ||
48 | } else { | ||
49 | struct stat st; | ||
50 | |||
51 | if (stat (path, &st) < 0 && errno == ENOENT) { | ||
52 | int status; | ||
53 | char *buf, *parent; | ||
54 | mode_t mask; | ||
55 | |||
56 | mask = umask (0); | ||
57 | umask (mask); | ||
58 | 43 | ||
59 | buf = xstrdup (path); | 44 | /* Calling apps probably should use 0777 instead of -1 |
60 | parent = dirname (buf); | 45 | * then we dont need this condition |
61 | status = make_directory (parent, (0777 & ~mask) | 0300, | 46 | */ |
62 | FILEUTILS_RECUR); | 47 | if (mode == -1) { |
63 | free (buf); | 48 | mode = 0777; |
64 | 49 | } | |
65 | if (status < 0 || make_directory (path, mode, 0) < 0) | 50 | if (flags == FILEUTILS_RECUR) { |
66 | return -1; | 51 | char *pp = strrchr(path, '/'); |
52 | if (pp) { | ||
53 | *pp = '\0'; | ||
54 | make_directory(path, mode, flags); | ||
55 | *pp = '/'; | ||
67 | } | 56 | } |
68 | } | 57 | } |
69 | 58 | ret = mkdir(path, mode); | |
70 | return 0; | 59 | if ( (ret == -1) && (errno != EEXIST) ) { |
60 | perror_msg("Cannot create directory %s", path); | ||
61 | } | ||
62 | return ret; | ||
71 | } | 63 | } |