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

If it is a directory, we can just return straightaway.
This commit is contained in:
Michael Forney 2016-12-14 19:40:05 -08:00 committed by Anselm R Garbe
parent e795946971
commit 6ac5f01cc9

View File

@ -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++) {