MakeSureDirectoryPathExists improvement
Wolfgang Schwotzer
wolfgang.schwotzer at gmx.net
Mon Sep 6 15:35:03 CDT 2004
Description: Recursively create path up to last '\\'
Depends on other patch CreateDirectoryW.diff
-------------- 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 6 Sep 2004 20:22:24 -0000
@@ -91,13 +91,25 @@
*/
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;
+
+ while ((p = strchr(p, '\\')) != NULL)
{
- SetLastError(ERROR_SUCCESS);
- return TRUE;
+ n = p - DirPath;
+ strncpy(path, DirPath, n);
+ path[n] = '\0';
+ if( !CreateDirectoryA(path, NULL) &&
+ (GetLastError() != ERROR_SUCCESS) &&
+ (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