summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-08-03 21:31:16 -0400
committerJakob Kaivo <jkk@ung.org>2019-08-03 21:31:16 -0400
commit0d18b3fa7174987698596d718adb9f4c6b47ad70 (patch)
tree26d7946fdafc1763a5450be10e45fb08e333d32d
parentafd96cc52e5c1ec955527cce5c33b4cd1ad0d8f9 (diff)
now with 100% fewer gotos
-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;