diff --git a/src/base/system.cpp b/src/base/system.cpp index 79e712af8..3d97b3fef 100644 --- a/src/base/system.cpp +++ b/src/base/system.cpp @@ -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; diff --git a/src/base/system.h b/src/base/system.h index d7425a512..85127f112 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -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. *