mkdir: Fix mkdir error handling
This commit is contained in:
parent
a00695bdac
commit
bc11469a0b
|
|
@ -16,9 +16,10 @@ int create_directory(const char* path, bool create_parents)
|
||||||
if (!create_parents)
|
if (!create_parents)
|
||||||
{
|
{
|
||||||
const int ret = mkdir(path, 0755);
|
const int ret = mkdir(path, 0755);
|
||||||
if (ret == -1)
|
if (ret == 0)
|
||||||
perror("mkdir");
|
return 0;
|
||||||
return -ret;
|
perror("mkdir");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
@ -30,7 +31,11 @@ int create_directory(const char* path, bool create_parents)
|
||||||
for (; path[i] && path[i] == '/'; i++)
|
for (; path[i] && path[i] == '/'; i++)
|
||||||
buffer[i] = path[i];
|
buffer[i] = path[i];
|
||||||
buffer[i] = '\0';
|
buffer[i] = '\0';
|
||||||
ret = mkdir(buffer, 0755);
|
if (mkdir(buffer, 0755) == -1 && errno != EEXIST)
|
||||||
|
{
|
||||||
|
perror("mkdir");
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue