6#include <winpr/crypto.h>
10static UINT32 prand(UINT32 max)
15 if (winpr_RAND(&tmp,
sizeof(tmp)) < 0)
20 return tmp % (max - 1) + 1;
23int TestPathMakePath(
int argc,
char* argv[])
27 char tmp[64] = WINPR_C_ARRAY_INIT;
30 char delim = PathGetSeparatorA(0);
31 char* base = GetKnownPath(KNOWN_PATH_TEMP);
38 (void)fprintf(stderr,
"Failed to get temporary directory!\n");
42 baseLen = strlen(base);
44 for (
int x = 0; x < 5; x++)
46 (void)sprintf_s(tmp, ARRAYSIZE(tmp),
"%08" PRIX32, prand(UINT32_MAX));
47 path = GetCombinedPath(base, tmp);
52 (void)fprintf(stderr,
"GetCombinedPath failed!\n");
59 printf(
"Creating path %s\n", path);
60 success = winpr_PathMakePath(path,
nullptr);
64 (void)fprintf(stderr,
"MakePath failed!\n");
69 success = winpr_PathFileExists(path);
73 (void)fprintf(stderr,
"MakePath lied about success!\n");
78 while (strlen(path) > baseLen)
80 if (!winpr_RemoveDirectory(path))
82 (void)fprintf(stderr,
"winpr_RemoveDirectory %s failed!\n", path);
87 cur = strrchr(path, delim);
94 printf(
"%s success!\n", __func__);