mirror of
https://github.com/troglobit/libite.git
synced 2026-10-07 15:54:20 +07: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:
+4
-1
@@ -25,12 +25,14 @@
|
||||
|
||||
int mkpath(char *dir, mode_t mode)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (!dir) {
|
||||
errno = EINVAL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (strlen(dir) == 1 && dir[0] == '/')
|
||||
if (!stat(dir, &sb))
|
||||
return 0;
|
||||
|
||||
mkpath(dirname(strdupa(dir)), mode);
|
||||
@@ -96,6 +98,7 @@ int main(void)
|
||||
"/tmp/a/",
|
||||
"/tmp/a/b",
|
||||
"/tmp/a/c/",
|
||||
"../../sometestdir/arpa/inet",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user