diff --git a/libobs/util/platform-nix.c b/libobs/util/platform-nix.c index 75ba4a903..181fa5640 100644 --- a/libobs/util/platform-nix.c +++ b/libobs/util/platform-nix.c @@ -21,6 +21,9 @@ distribution. ******************************************************************************/ +#include +#include +#include #include #include "dstr.h" @@ -71,3 +74,12 @@ char *os_get_home_path(void) /* TODO */ return NULL; } + +int os_mkdir(const char *path) +{ + int errorcode = mkdir(path, S_IRWXU); + if (errorcode == 0) + return MKDIR_SUCCESS; + + return (errno == EEXIST) ? MKDIR_EXISTS : MKDIR_ERROR; +} diff --git a/libobs/util/platform-windows.c b/libobs/util/platform-windows.c index 62da8bd50..0d464eda1 100644 --- a/libobs/util/platform-windows.c +++ b/libobs/util/platform-windows.c @@ -153,6 +153,7 @@ char *os_get_home_path(void) { char *out; wchar_t path_utf16[MAX_PATH]; + SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path_utf16); @@ -160,6 +161,24 @@ char *os_get_home_path(void) return out; } +int os_mkdir(const char *path) +{ + wchar_t *path_utf16; + BOOL success; + + if (!os_utf8_to_wcs(path, 0, &path_utf16)) + return MKDIR_ERROR; + + success = CreateDirectory(path_utf16, NULL); + bfree(path_utf16); + + if (!success) + return (GetLastError() == ERROR_ALREADY_EXISTS) ? + MKDIR_EXISTS : MKDIR_ERROR; + + return MKDIR_SUCCESS; +} + #ifdef PTW32_STATIC_LIB BOOL WINAPI DllMain(HINSTANCE hinst_dll, DWORD reason, LPVOID reserved) diff --git a/libobs/util/platform.h b/libobs/util/platform.h index 2dfe1b0fe..219fdebe8 100644 --- a/libobs/util/platform.h +++ b/libobs/util/platform.h @@ -72,6 +72,12 @@ EXPORT uint64_t os_gettime_ms(void); EXPORT char *os_get_home_path(void); +#define MKDIR_EXISTS 1 +#define MKDIR_SUCCESS 0 +#define MKDIR_ERROR -1 + +EXPORT int os_mkdir(const char *path); + #ifdef _MSC_VER EXPORT int fseeko(FILE *stream, off_t offset, int whence); EXPORT off_t ftello(FILE *stream);