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:
parent
e795946971
commit
6ac5f01cc9
|
@ -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++) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user