libobs/util: Add functions to get/set the cwd

Adds functions to get or set the current working directory.
This commit is contained in:
jp9000
2015-07-16 00:50:21 -07:00
parent 7bd5147074
commit 5c0f4546ea
3 changed files with 46 additions and 0 deletions

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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