MakeSureDirectoryPathExists improvement
Alexandre Julliard
julliard at winehq.org
Mon Sep 27 22:01:44 CDT 2004
Wolfgang Schwotzer <wolfgang.schwotzer at gmx.net> writes:
> @@ -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, ':');
> + 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_ACCESS_DENIED) &&
> + (GetLastError() != ERROR_ALREADY_EXISTS))
> + return FALSE;
> + p++;
> }
> - return FALSE;
> + if (GetLastError() == ERROR_ACCESS_DENIED ||
> + (GetLastError() == ERROR_ALREADY_EXISTS))
> + SetLastError(ERROR_SUCCESS);
> +
> + return TRUE;
I don't think you want to simply ignore ERROR_ACCESS_DENIED. You
should fix your algorithm to not try to create the drive root and then
ignore only ERROR_ALREADY_EXISTS.
--
Alexandre Julliard
julliard at winehq.org
More information about the wine-devel
mailing list