BOOL PathMakePathA(LPCSTR path, LPSECURITY_ATTRIBUTES lpAttributes) { #if defined(_UWP) return FALSE; #elif defined(_WIN32) return (SHCreateDirectoryExA(NULL, path, lpAttributes) == ERROR_SUCCESS); #else const char delim = PathGetSeparatorA(PATH_STYLE_NATIVE); char* dup; char* p; /* we only operate on a non-null, absolute path */ if (!path || *path != delim) return FALSE; if (!(dup = _strdup(path))) return FALSE; for (p = dup; p;) { if ((p = strchr(p + 1, delim))) * p = '\0'; if (mkdir(dup, 0777) != 0) if (errno != EEXIST) break; if (p) *p = delim; } free(dup); return (p == NULL); #endif }
BOOL PathMakePathA(LPCSTR path, LPSECURITY_ATTRIBUTES lpAttributes) { size_t length; const char delim = PathGetSeparatorA(0); char* cur; char* copy_org = _strdup(path); char* copy = copy_org; if (!copy_org) return FALSE; length = strlen(copy_org); /* Find first path element that exists. */ while (copy) { if (!PathFileExistsA(copy)) { cur = strrchr(copy, delim); if (cur) *cur = '\0'; } else break; } /* Create directories. */ while(copy) { if (!PathFileExistsA(copy)) { if (!CreateDirectoryA(copy, NULL)) break; } if (strlen(copy) < length) copy[strlen(copy)] = delim; else break; } free (copy_org); return PathFileExistsA(path); }
int TestLibraryLoadLibrary(int argc, char* argv[]) { HINSTANCE library; LPCSTR SharedLibraryExtension; CHAR LibraryPath[PATHCCH_MAX_CCH]; PCHAR p; if (!GetModuleFileNameA(NULL, LibraryPath, PATHCCH_MAX_CCH)) { printf("%s: GetModuleFilenameA failed: 0x%08"PRIX32"\n", __FUNCTION__, GetLastError()); return -1; } /* PathCchRemoveFileSpec is not implemented in WinPR */ if (!(p = strrchr(LibraryPath, PathGetSeparatorA(PATH_STYLE_NATIVE)))) { printf("%s: Error identifying module directory path\n", __FUNCTION__); return -1; } *p = 0; NativePathCchAppendA(LibraryPath, PATHCCH_MAX_CCH, "TestLibraryA"); SharedLibraryExtension = PathGetSharedLibraryExtensionA(PATH_SHARED_LIB_EXT_WITH_DOT); NativePathCchAddExtensionA(LibraryPath, PATHCCH_MAX_CCH, SharedLibraryExtension); printf("%s: Loading Library: '%s'\n", __FUNCTION__, LibraryPath); if (!(library = LoadLibraryA(LibraryPath))) { printf("%s: LoadLibraryA failure: 0x%08"PRIX32"\n", __FUNCTION__, GetLastError()); return -1; } if (!FreeLibrary(library)) { printf("%s: FreeLibrary failure: 0x%08"PRIX32"\n", __FUNCTION__, GetLastError()); return -1; } return 0; }
int TestPathMakePath(int argc, char* argv[]) { int x; size_t baseLen; BOOL success; char tmp[64]; char* path; char* cur; char delim = PathGetSeparatorA(0); char* base = GetKnownPath(KNOWN_PATH_TEMP); if (!base) { fprintf(stderr, "Failed to get temporary directory!\n"); return -1; } baseLen = strlen(base); srand(time(NULL)); for (x = 0; x < 5; x++) { sprintf_s(tmp, ARRAYSIZE(tmp), "%08X", rand()); path = GetCombinedPath(base, tmp); free(base); if (!path) { fprintf(stderr, "GetCombinedPath failed!\n"); return -1; } base = path; } printf("Creating path %s\n", path); success = PathMakePathA(path, NULL); if (!success) { fprintf(stderr, "MakePath failed!\n"); free(path); return -1; } success = PathFileExistsA(path); if (!success) { fprintf(stderr, "MakePath lied about success!\n"); free(path); return -1; } while (strlen(path) > baseLen) { if (!RemoveDirectoryA(path)) { fprintf(stderr, "RemoveDirectoryA %s failed!\n", path); free(path); return -1; } cur = strrchr(path, delim); if (cur) *cur = '\0'; } free(path); printf("%s success!\n", __FUNCTION__); return 0; }