summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bin/mkdir/mkdir.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/bin/mkdir/mkdir.c b/bin/mkdir/mkdir.c
index 417f7a3..bc06ff9 100644
--- a/bin/mkdir/mkdir.c
+++ b/bin/mkdir/mkdir.c
@@ -173,25 +173,28 @@ build(char *path, mode_t omode)
}
if (last)
(void)umask(oumask);
- if (stat(path, &sb)) {
- if (errno != ENOENT ||
- mkdir(path, last ? omode :
- S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
+ if (mkdir(path, last ? omode : S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
+ if (errno == EEXIST) {
+ if (stat(path, &sb) < 0) {
+ warn("%s", path);
+ retval = 1;
+ break;
+ } else if (!S_ISDIR(sb.st_mode)) {
+ if (last)
+ errno = EEXIST;
+ else
+ errno = ENOTDIR;
+ warn("%s", path);
+ retval = 1;
+ break;
+ }
+ } else {
warn("%s", path);
retval = 1;
break;
- } else if (vflag)
- printf("%s\n", path);
- }
- else if ((sb.st_mode & S_IFMT) != S_IFDIR) {
- if (last)
- errno = EEXIST;
- else
- errno = ENOTDIR;
- warn("%s", path);
- retval = 1;
- break;
- }
+ }
+ } else if (vflag)
+ printf("%s\n", path);
if (!last)
*p = '/';
}
OpenPOWER on IntegriCloud