mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-11 07:11:54 +00:00
Rewrote directory creation function for Windows
Previous implementation had several security issues https://forum.zdoom.org/viewtopic.php?t=56622
This commit is contained in:
parent
b7295775b9
commit
0f936f39d8
1 changed files with 38 additions and 9 deletions
|
@ -477,16 +477,45 @@ const char *myasctime ()
|
||||||
void DoCreatePath(const char *fn)
|
void DoCreatePath(const char *fn)
|
||||||
{
|
{
|
||||||
char drive[_MAX_DRIVE];
|
char drive[_MAX_DRIVE];
|
||||||
char path[PATH_MAX];
|
char dir[_MAX_DIR];
|
||||||
char p[PATH_MAX];
|
_splitpath_s(fn, drive, sizeof drive, dir, sizeof dir, nullptr, 0, nullptr, 0);
|
||||||
int i;
|
|
||||||
|
|
||||||
_splitpath(fn,drive,path,NULL,NULL);
|
if ('\0' == *dir)
|
||||||
_makepath(p,drive,path,NULL,NULL);
|
{
|
||||||
i=(int)strlen(p);
|
// Root/current/parent directory always exists
|
||||||
if (p[i-1]=='/' || p[i-1]=='\\') p[i-1]=0;
|
return;
|
||||||
if (*path) DoCreatePath(p);
|
}
|
||||||
_mkdir(p);
|
|
||||||
|
char path[PATH_MAX];
|
||||||
|
_makepath_s(path, sizeof path, drive, dir, nullptr, nullptr);
|
||||||
|
|
||||||
|
if ('\0' == *path)
|
||||||
|
{
|
||||||
|
// No need to process empty relative path
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove trailing path separator(s)
|
||||||
|
for (size_t i = strlen(path); 0 != i; --i)
|
||||||
|
{
|
||||||
|
char& lastchar = path[i - 1];
|
||||||
|
|
||||||
|
if ('/' == lastchar || '\\' == lastchar)
|
||||||
|
{
|
||||||
|
lastchar = '\0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create all directories for given path
|
||||||
|
if ('\0' != *path)
|
||||||
|
{
|
||||||
|
DoCreatePath(path);
|
||||||
|
_mkdir(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreatePath(const char *fn)
|
void CreatePath(const char *fn)
|
||||||
|
|
Loading…
Reference in a new issue