mirror of
https://github.com/troglobit/libite.git
synced 2026-11-10 16:31:15 +00:00
Fix mkpath() to handle relative dirs
After input from both StackOverflow and Valery Frolov. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
7df1b75fa0
commit
613d397161
1 file changed
+4
-1
+4
-1
@@ -25,12 +25,14 @@
|
|||||||
|
|
||||||
int mkpath(char *dir, mode_t mode)
|
int mkpath(char *dir, mode_t mode)
|
||||||
{
|
{
|
||||||
|
struct stat sb;
|
||||||
|
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(dir) == 1 && dir[0] == '/')
|
if (!stat(dir, &sb))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
mkpath(dirname(strdupa(dir)), mode);
|
mkpath(dirname(strdupa(dir)), mode);
|
||||||
@@ -96,6 +98,7 @@ int main(void)
|
|||||||
"/tmp/a/",
|
"/tmp/a/",
|
||||||
"/tmp/a/b",
|
"/tmp/a/b",
|
||||||
"/tmp/a/c/",
|
"/tmp/a/c/",
|
||||||
|
"../../sometestdir/arpa/inet",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user