MakeSureDirectoryPathExists improvement take 2
Wolfgang Schwotzer
wolfgang.schwotzer at gmx.net
Wed Sep 29 08:12:01 CDT 2004
Description: Recursively create path up to last '\\'
Algorithm improved to skip drive root and not ignoring
ERROR_ACCESS_DENIED
-------------- next part --------------
Index: dlls/dbghelp/path.c
===================================================================
RCS file: /home/wine/wine/dlls/dbghelp/path.c,v
retrieving revision 1.2
diff -u -r1.2 path.c
--- dlls/dbghelp/path.c 14 Jun 2004 17:58:31 -0000 1.2
+++ dlls/dbghelp/path.c 29 Sep 2004 17:06:44 -0000
@@ -91,13 +91,28 @@
*/
BOOL WINAPI MakeSureDirectoryPathExists(LPCSTR DirPath)
{
- if (CreateDirectoryA(DirPath, NULL)) return TRUE;
- if (GetLastError() == ERROR_ALREADY_EXISTS)
+ char path[MAX_PATH];
+ const char *p = DirPath;
+ int n;
+
+ if (strchr(p, ':') != NULL)
+ p = strchr(p, ':') + 1;
+ if (*p == '\\') /* skip drive root */
+ p++;
+ while ((p = strchr(p, '\\')) != NULL)
{
- SetLastError(ERROR_SUCCESS);
- return TRUE;
+ n = p - DirPath + 1;
+ strncpy(path, DirPath, n);
+ path[n] = '\0';
+ if( !CreateDirectoryA(path, NULL) &&
+ (GetLastError() != ERROR_ALREADY_EXISTS))
+ return FALSE;
+ p++;
}
- return FALSE;
+ if (GetLastError() == ERROR_ALREADY_EXISTS)
+ SetLastError(ERROR_SUCCESS);
+
+ return TRUE;
}
/******************************************************************
More information about the wine-patches
mailing list