diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-08-03 21:31:16 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-08-03 21:31:16 -0400 |
commit | 0d18b3fa7174987698596d718adb9f4c6b47ad70 (patch) | |
tree | 26d7946fdafc1763a5450be10e45fb08e333d32d | |
parent | afd96cc52e5c1ec955527cce5c33b4cd1ad0d8f9 (diff) |
now with 100% fewer gotos
-rw-r--r-- | mkdir.c | 14 |
1 files changed, 5 insertions, 9 deletions
@@ -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; |