diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2021-05-17 11:52:11 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2021-05-17 11:52:11 +0000 |
commit | f1040dd40c54889242457f2272512fe5b03da810 (patch) | |
tree | 831fc17a64e41ba5b371b8c926fb4729de0367d6 /usr.bin | |
parent | 34a59873f49720a9228231c74585e6a5883902f6 (diff) |
Sync code with the original from mkdir(1).
OK benno@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/rsync/mkpath.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/usr.bin/rsync/mkpath.c b/usr.bin/rsync/mkpath.c index c8c7bd4477e..1625508ac6b 100644 --- a/usr.bin/rsync/mkpath.c +++ b/usr.bin/rsync/mkpath.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkpath.c,v 1.4 2019/05/08 21:30:11 benno Exp $ */ +/* $OpenBSD: mkpath.c,v 1.5 2021/05/17 11:52:10 claudio Exp $ */ /* * Copyright (c) 1983, 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -46,29 +46,35 @@ mkpath(char *path) { struct stat sb; char *slash; - int done = 0; + int done; slash = path; - while (!done) { + for (;;) { slash += strspn(slash, "/"); slash += strcspn(slash, "/"); done = (*slash == '\0'); *slash = '\0'; - if (stat(path, &sb)) { - if (errno != ENOENT || (mkdir(path, 0777) && - errno != EEXIST)) { - ERR("%s: stat", path); + if (mkdir(path, 0777) != 0) { + int mkdir_errno = errno; + + if (stat(path, &sb) == -1) { + /* Not there; use mkdir()s errno */ + errno = mkdir_errno; + return (-1); + } + if (!S_ISDIR(sb.st_mode)) { + /* Is there, but isn't a directory */ + errno = ENOTDIR; return (-1); } - } else if (!S_ISDIR(sb.st_mode)) { - errno = ENOTDIR; - ERR("%s: stat", path); - return (-1); } + if (done) + break; + *slash = '/'; } |