[hackers] [sbase] mkdir -p: Fail if argument exists, but is not a directory || Michael Forney

From: <git_AT_suckless.org>
Date: Mon, 3 Jul 2017 21:06:19 +0200 (CEST)

commit 6ac5f01cc94b2a6f7b6406ddd151e7b4d8fb1d7d
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Wed Dec 14 19:40:05 2016 -0800
Commit: Anselm R Garbe <anselm_AT_garbe.us>
CommitDate: Mon Jul 3 21:03:09 2017 +0200

    mkdir -p: Fail if argument exists, but is not a directory
    
    If it is a directory, we can just return straightaway.

diff --git a/libutil/mkdirp.c b/libutil/mkdirp.c
index 7796e24..2ef94a3 100644
--- a/libutil/mkdirp.c
+++ b/libutil/mkdirp.c
_AT_@ -10,6 +10,15 @@ int
 mkdirp(const char *path)
 {
         char tmp[PATH_MAX], *p;
+ struct stat st;
+
+ if (stat(path, &st) == 0) {
+ if (S_ISDIR(st.st_mode))
+ return 0;
+ errno = ENOTDIR;
+ weprintf("%s:", path);
+ return -1;
+ }
 
         estrlcpy(tmp, path, sizeof(tmp));
         for (p = tmp + (tmp[0] == '/'); *p; p++) {
Received on Mon Jul 03 2017 - 21:06:19 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 03 2017 - 21:12:57 CEST