sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit 6ac5f01cc94b2a6f7b6406ddd151e7b4d8fb1d7d
parent e795946971f08b80ce9518088e590afa64bf0179
Author: Michael Forney <mforney@mforney.org>
Date:   Wed, 14 Dec 2016 19:40:05 -0800

mkdir -p: Fail if argument exists, but is not a directory

If it is a directory, we can just return straightaway.

Diffstat:
Mlibutil/mkdirp.c | 9+++++++++
1 file changed, 9 insertions(+), 0 deletions(-)

diff --git a/libutil/mkdirp.c b/libutil/mkdirp.c @@ -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++) {