From 78c96188073ac429d54f2efb5f13355d425e65ac Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Tue, 26 Sep 2017 11:07:02 -0400 Subject: [PATCH] Test chdir. --- platform-independent/cli-c/cli/mpw-cli-util.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/platform-independent/cli-c/cli/mpw-cli-util.c b/platform-independent/cli-c/cli/mpw-cli-util.c index 8fc71ad8..b338dce3 100644 --- a/platform-independent/cli-c/cli/mpw-cli-util.c +++ b/platform-independent/cli-c/cli/mpw-cli-util.c @@ -220,17 +220,18 @@ bool mpw_mkdirs(const char *filePath) { if (!filePath) 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. char *pathEnd = strrchr( filePath, '/' ); char *path = pathEnd? mpw_strndup( filePath, (size_t)(pathEnd - filePath) ): NULL; if (!path) return false; - // Save the cwd and for absolute paths, start at the root. - char *cwd = getcwd( NULL, 0 ); - if (*filePath == '/') - chdir( "/" ); - // Walk the path. bool success = true; for (char *dirName = strtok( path, "/" ); success && dirName; dirName = strtok( NULL, "/" )) {