libobs/util: Add os_rename function

Allows moving/renaming of files.
master
jp9000 2015-06-21 22:33:48 -07:00
parent 7766f5a42f
commit 50f4793c99
3 changed files with 27 additions and 0 deletions

View File

@ -14,6 +14,7 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -303,6 +304,11 @@ int os_mkdir(const char *path)
return (errno == EEXIST) ? MKDIR_EXISTS : MKDIR_ERROR;
}
int os_rename(const char *old_path, const char *new_path)
{
return rename(old_path, new_path);
}
#if !defined(__APPLE__)
os_performance_token_t *os_request_high_performance(const char *reason)
{

View File

@ -413,6 +413,26 @@ int os_mkdir(const char *path)
return MKDIR_SUCCESS;
}
int os_rename(const char *old_path, const char *new_path)
{
wchar_t *old_path_utf16 = NULL;
wchar_t *new_path_utf16 = NULL;
int code = -1;
if (!os_utf8_to_wcs_ptr(old_path, 0, &old_path_utf16)) {
return -1;
}
if (!os_utf8_to_wcs_ptr(new_path, 0, &new_path_utf16)) {
goto error;
}
code = MoveFileW(old_path_utf16, new_path_utf16) ? 0 : -1;
error:
bfree(old_path_utf16);
bfree(new_path_utf16);
return code;
}
BOOL WINAPI DllMain(HINSTANCE hinst_dll, DWORD reason, LPVOID reserved)
{

View File

@ -134,6 +134,7 @@ EXPORT int os_unlink(const char *path);
#define MKDIR_ERROR -1
EXPORT int os_mkdir(const char *path);
EXPORT int os_rename(const char *old_path, const char *new_path);
#ifdef _MSC_VER
#define strtoll _strtoi64