#if defined(WIN32)
#include <Shlobj.h>
+#else
+#include <errno.h>
#endif
static char* GetPath_XDG_CONFIG_HOME(void);
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;
+#ifdef _WIN32
+ return (SHCreateDirectoryExA(NULL, path, lpAttributes) == ERROR_SUCCESS);
+#else
+ const char delim = PathGetSeparatorA(PATH_STYLE_NATIVE);
+ char* dup;
+ char* p;
- if (!copy_org)
+ /* we only operate on a non-null, absolute path */
+ if (!path || *path != delim)
return FALSE;
- length = strlen(copy_org);
+ if (!(dup = _strdup(path)))
+ return FALSE;
- /* Find first path element that exists. */
- while (copy)
+ for (p = dup; p;)
{
- if (!PathFileExistsA(copy))
- {
- cur = strrchr(copy, delim);
- if (cur)
- *cur = '\0';
- }
- else
- break;
- }
+ if ((p = strchr(p + 1, delim)))
+ *p = '\0';
- /* Create directories. */
- while(copy)
- {
- if (!PathFileExistsA(copy))
- {
- if (!CreateDirectoryA(copy, NULL))
+ if (mkdir(dup, 0777) != 0)
+ if (errno != EEXIST)
break;
- }
- if (strlen(copy) < length)
- copy[strlen(copy)] = delim;
- else
- break;
+ if (p)
+ *p = delim;
}
- free (copy_org);
- return PathFileExistsA(path);
+ free(dup);
+ return (p == NULL);
+#endif
}
#if !defined(_WIN32) || defined(_UWP)
#include <winpr/crt.h>
#include <winpr/tchar.h>
#include <winpr/path.h>
+#include <winpr/file.h>
#include <winpr/wlog.h>
int TestWLog(int argc, char* argv[])
wLog* logB;
wLogLayout* layout;
wLogAppender* appender;
+ char* tmp_path;
+ char* wlog_file;
+
+ if (!(tmp_path = GetKnownPath(KNOWN_PATH_TEMP)))
+ {
+ fprintf(stderr, "Failed to get temporary directory!\n");
+ return -1;
+ }
WLog_Init();
appender = WLog_GetLogAppender(root);
if(!WLog_ConfigureAppender(appender, "outputfilename", "test_w.log"))
return 1;
- if(!WLog_ConfigureAppender(appender, "outputfilepath", "/tmp/"))
+ if(!WLog_ConfigureAppender(appender, "outputfilepath", tmp_path))
return 1;
layout = WLog_GetLogLayout(root);
WLog_Uninit();
+ if ((wlog_file = GetCombinedPath(tmp_path, "test_w.log")))
+ {
+ DeleteFileA(wlog_file);
+ free(wlog_file);
+ }
+
return 0;
}