Skip to content

Commit

Permalink
fix zsv_mkdirs not working for network drive paths with leading // or…
Browse files Browse the repository at this point in the history
… \\ (#148)
  • Loading branch information
liquidaty authored Feb 21, 2024
1 parent afe09ab commit 7790279
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions app/utils/dirs.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,20 @@ int zsv_mkdirs(const char *path, char path_is_filename) {
#ifdef WIN32
if(len > 1) {
// starts with two slashes
if(strchr("/\\", tmp[0]) && strchr("/\\", tmp[1]))
if(strchr("/\\", tmp[0]) && strchr("/\\", tmp[1])) {
offset = 2;

// find the next slash
char *path_end = tmp + 3;
while(*path_end && !strchr("/\\", *path_end))
path_end++;
if(*path_end) path_end++;
if(*path_end)
offset = path_end - tmp;
else {
fprintf(stderr, "Invalid path: %s\n", path);
return -1;
}
}
// starts with *:
else if(tmp[1] == ':')
offset = 2;
Expand All @@ -116,13 +127,16 @@ int zsv_mkdirs(const char *path, char path_is_filename) {
char tmp_c = p[1];
p[0] = FILESLASH;
p[1] = '\0';
if(*tmp && !zsv_dir_exists(tmp) && mkdir(tmp
if(*tmp && !zsv_dir_exists(tmp)
&& mkdir(tmp
#ifndef WIN32
, S_IRWXU
, S_IRWXU
#endif
))
)) {
rc = -1;
else
fprintf(stderr, "Error creating directory: ");
perror(tmp);
} else
p[1] = tmp_c;
}

Expand Down

0 comments on commit 7790279

Please sign in to comment.