Test chdir.
This commit is contained in:
parent
bed8939b8a
commit
78c9618807
@ -220,17 +220,18 @@ bool mpw_mkdirs(const char *filePath) {
|
|||||||
if (!filePath)
|
if (!filePath)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Save the cwd and for absolute paths, start at the root.
|
||||||
|
char *cwd = getcwd( NULL, 0 );
|
||||||
|
if (*filePath == '/')
|
||||||
|
if (!chdir( "/" ))
|
||||||
|
return false;
|
||||||
|
|
||||||
// The path to mkdir is the filePath without the last path component.
|
// The path to mkdir is the filePath without the last path component.
|
||||||
char *pathEnd = strrchr( filePath, '/' );
|
char *pathEnd = strrchr( filePath, '/' );
|
||||||
char *path = pathEnd? mpw_strndup( filePath, (size_t)(pathEnd - filePath) ): NULL;
|
char *path = pathEnd? mpw_strndup( filePath, (size_t)(pathEnd - filePath) ): NULL;
|
||||||
if (!path)
|
if (!path)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Save the cwd and for absolute paths, start at the root.
|
|
||||||
char *cwd = getcwd( NULL, 0 );
|
|
||||||
if (*filePath == '/')
|
|
||||||
chdir( "/" );
|
|
||||||
|
|
||||||
// Walk the path.
|
// Walk the path.
|
||||||
bool success = true;
|
bool success = true;
|
||||||
for (char *dirName = strtok( path, "/" ); success && dirName; dirName = strtok( NULL, "/" )) {
|
for (char *dirName = strtok( path, "/" ); success && dirName; dirName = strtok( NULL, "/" )) {
|
||||||
|
Loading…
Reference in New Issue
Block a user