2015-06-03 12:47:40 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
2015-06-03 13:35:45 +03:00
|
|
|
#include <winpr/file.h>
|
2015-06-03 12:47:40 +03:00
|
|
|
#include <winpr/path.h>
|
|
|
|
|
|
|
|
int TestPathMakePath(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
int x;
|
2015-06-03 13:35:45 +03:00
|
|
|
size_t baseLen;
|
2015-06-03 12:47:40 +03:00
|
|
|
BOOL success;
|
|
|
|
char tmp[64];
|
|
|
|
char* path;
|
2015-06-03 13:35:45 +03:00
|
|
|
char* cur;
|
|
|
|
char delim = PathGetSeparatorA(0);
|
2015-06-03 12:47:40 +03:00
|
|
|
char* base = GetKnownPath(KNOWN_PATH_TEMP);
|
|
|
|
if (!base)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to get temporary directory!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-06-03 13:35:45 +03:00
|
|
|
baseLen = strlen(base);
|
2015-06-03 12:47:40 +03:00
|
|
|
srand(time(NULL));
|
|
|
|
for (x=0; x<5; x++)
|
|
|
|
{
|
|
|
|
sprintf(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;
|
|
|
|
}
|
|
|
|
|
2015-06-03 13:35:45 +03:00
|
|
|
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__);
|
2015-06-03 12:47:40 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|