mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 06:28:19 +00:00
Merge pull request #8153 from Robyt3/Base-Makedir-Rec-Windows-Fix
Fix recursive folder creation with mixed slashes and drive letters
This commit is contained in:
commit
e26ccdd921
|
@ -2293,17 +2293,20 @@ int fs_storage_path(const char *appname, char *path, int max)
|
|||
|
||||
int fs_makedir_rec_for(const char *path)
|
||||
{
|
||||
char buffer[1024 * 2];
|
||||
char *p;
|
||||
char buffer[IO_MAX_PATH_LENGTH];
|
||||
str_copy(buffer, path);
|
||||
for(p = buffer + 1; *p != '\0'; p++)
|
||||
for(int index = 1; buffer[index] != '\0'; ++index)
|
||||
{
|
||||
if(*p == '/' && *(p + 1) != '\0')
|
||||
// Do not try to create folder for drive letters on Windows,
|
||||
// as this is not necessary and may fail for system drives.
|
||||
if((buffer[index] == '/' || buffer[index] == '\\') && buffer[index + 1] != '\0' && buffer[index - 1] != ':')
|
||||
{
|
||||
*p = '\0';
|
||||
buffer[index] = '\0';
|
||||
if(fs_makedir(buffer) < 0)
|
||||
{
|
||||
return -1;
|
||||
*p = '/';
|
||||
}
|
||||
buffer[index] = '/';
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -1839,11 +1839,11 @@ int fs_makedir(const char *path);
|
|||
int fs_removedir(const char *path);
|
||||
|
||||
/**
|
||||
* Recursively create directories for a file.
|
||||
* Recursively creates parent directories for a file or directory.
|
||||
*
|
||||
* @ingroup Filesystem
|
||||
*
|
||||
* @param path - File for which to create directories.
|
||||
* @param path File or directory for which to create parent directories.
|
||||
*
|
||||
* @return 0 on success. Negative value on failure.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue