diff --git a/winpr/include/winpr/file.h b/winpr/include/winpr/file.h index 80f89507f..45ec3e698 100644 --- a/winpr/include/winpr/file.h +++ b/winpr/include/winpr/file.h @@ -291,6 +291,9 @@ WINPR_API BOOL FindClose(HANDLE hFindFile); WINPR_API BOOL CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes); WINPR_API BOOL CreateDirectoryW(LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes); +WINPR_API BOOL RemoveDirectoryA(LPCSTR lpPathName); +WINPR_API BOOL RemoveDirectoryW(LPCWSTR lpPathName); + #ifdef __cplusplus } #endif @@ -302,6 +305,7 @@ WINPR_API BOOL CreateDirectoryW(LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecu #define FindFirstFileEx FindFirstFileExW #define FindNextFile FindNextFileW #define CreateDirectory CreateDirectoryW +#define RemoveDirectory RemoveDirectoryW #else #define CreateFile CreateFileA #define DeleteFile DeleteFileA @@ -309,6 +313,7 @@ WINPR_API BOOL CreateDirectoryW(LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecu #define FindFirstFileEx FindFirstFileExA #define FindNextFile FindNextFileA #define CreateDirectory CreateDirectoryA +#define RemoveDirectory RemoveDirectoryA #endif diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c index 05fb444ba..291ee23e0 100644 --- a/winpr/libwinpr/file/file.c +++ b/winpr/libwinpr/file/file.c @@ -788,7 +788,20 @@ BOOL CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttribu BOOL CreateDirectoryW(LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes) { - return TRUE; + return FALSE; +} + +BOOL RemoveDirectoryA(LPCSTR lpPathName) +{ + if (!rmdir(lpPathName)) + return TRUE; + + return FALSE; +} + +BOOL RemoveDirectoryW(LPCWSTR lpPathName) +{ + return FALSE; } #endif diff --git a/winpr/libwinpr/path/test/TestPathMakePath.c b/winpr/libwinpr/path/test/TestPathMakePath.c index 081aa60aa..e69b396bd 100644 --- a/winpr/libwinpr/path/test/TestPathMakePath.c +++ b/winpr/libwinpr/path/test/TestPathMakePath.c @@ -3,14 +3,18 @@ #include #include +#include #include 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) { @@ -18,6 +22,7 @@ int TestPathMakePath(int argc, char* argv[]) return -1; } + baseLen = strlen(base); srand(time(NULL)); for (x=0; x<5; x++) { @@ -49,9 +54,22 @@ int TestPathMakePath(int argc, char* argv[]) free (path); return -1; } - free (path); - printf("%s success!", __FUNCTION__); + 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; }