aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMikhail Kashkarov <m.kashkarov@samsung.com>2021-10-18 18:52:29 +0300
committerRob Landley <rob@landley.net>2021-10-18 19:59:10 -0500
commitb8418383a033a5bb6967889b3d1502e15127250b (patch)
tree4f4b5433a0fcf18ad86abcd9591fb867eaa84b0b /lib
parent4c450efa50222450f1d30413553496fb8808ed88 (diff)
downloadtoybox-b8418383a033a5bb6967889b3d1502e15127250b.tar.gz
mkdir: return error for existing directories without -p flag
Existing directories should be ignored without errors only with -p flag (according to POSIX). Signed-off-by: Mikhail Kashkarov <m.kashkarov@samsung.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 0c1b5c37..7af44173 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -178,7 +178,8 @@ int mkpathat(int atfd, char *dir, mode_t lastmode, int flags)
// test for. Might as well do it up front.
if (!fstatat(atfd, dir, &buf, 0)) {
- if ((flags&MKPATHAT_MKLAST) && !S_ISDIR(buf.st_mode)) {
+ // Note that mkdir should return EEXIST for already existed directory/file.
+ if (!(flags&MKPATHAT_MAKE) || ((flags&MKPATHAT_MKLAST) && !S_ISDIR(buf.st_mode))) {
errno = EEXIST;
return 1;
} else return 0;