summaryrefslogtreecommitdiff
path: root/mkdir.c
diff options
context:
space:
mode:
Diffstat (limited to 'mkdir.c')
-rw-r--r--mkdir.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/mkdir.c b/mkdir.c
index 9ae2dca..47e6bc8 100644
--- a/mkdir.c
+++ b/mkdir.c
@@ -45,22 +45,18 @@ static int mk_dir(char *path, int mode, int flags)
char parent[strlen(path) + 1];
strcpy(parent, path);
char *p = dirname(parent);
- if (!strcmp(p, "/") || !strcmp(p, ".") || !strcmp(p, "..")) {
- goto MKDIR;
- }
struct stat st;
- if (stat(p, &st) == 0 && !S_ISDIR(st.st_mode)) {
+ if (stat(p, &st) != 0) {
+ if (mk_dir(p, mode, flags) != 0) {
+ return 1;
+ }
+ } else if (!S_ISDIR(st.st_mode)) {
fprintf(stderr, "mkdir: %s: %s\n", path, strerror(EEXIST));
return 1;
}
-
- if (mk_dir(p, mode, flags) != 0) {
- return 1;
- }
}
- MKDIR:
if (mkdir(path, mode) != 0) {
fprintf(stderr, "mkdir: %s: %s\n", path, strerror(errno));
return 1;