diff --git a/libobs/util/platform-nix.c b/libobs/util/platform-nix.c index cb9f3fa84..91e4ae351 100644 --- a/libobs/util/platform-nix.c +++ b/libobs/util/platform-nix.c @@ -412,3 +412,13 @@ error: fclose(file_in); return ret; } + +char *os_getcwd(char *path, size_t size) +{ + return getcwd(path, size); +} + +int os_chdir(const char *path) +{ + return chdir(path); +} diff --git a/libobs/util/platform-windows.c b/libobs/util/platform-windows.c index ce633b4d6..568342aad 100644 --- a/libobs/util/platform-windows.c +++ b/libobs/util/platform-windows.c @@ -520,3 +520,36 @@ error: bfree(file_out_utf16); return code; } + +char *os_getcwd(char *path, size_t size) +{ + wchar_t *path_w; + DWORD len; + + len = GetCurrentDirectoryW(0, NULL); + if (!len) + return NULL; + + path_w = bmalloc((len + 1) * sizeof(wchar_t)); + GetCurrentDirectoryW(len + 1, path_w); + os_wcs_to_utf8(path_w, (size_t)len, path, size); + bfree(path_w); + + return path; +} + +int os_chdir(const char *path) +{ + wchar_t *path_w = NULL; + size_t size; + int ret; + + size = os_utf8_to_wcs_ptr(path, 0, &path_w); + if (!path_w) + return -1; + + ret = SetCurrentDirectoryW(path_w) ? 0 : -1; + bfree(path_w); + + return ret; +} diff --git a/libobs/util/platform.h b/libobs/util/platform.h index cb692db69..33982aec7 100644 --- a/libobs/util/platform.h +++ b/libobs/util/platform.h @@ -130,6 +130,9 @@ EXPORT void os_globfree(os_glob_t *pglob); EXPORT int os_unlink(const char *path); EXPORT int os_rmdir(const char *path); +EXPORT char *os_getcwd(char *path, size_t size); +EXPORT int os_chdir(const char *path); + #define MKDIR_EXISTS 1 #define MKDIR_SUCCESS 0 #define MKDIR_ERROR -1