diff --git a/osdep/io.c b/osdep/io.c index 8c114c066c..bdf79f8894 100644 --- a/osdep/io.c +++ b/osdep/io.c @@ -484,6 +484,20 @@ int mp_creat(const char *filename, int mode) return mp_open(filename, _O_CREAT | _O_WRONLY | _O_TRUNC, mode); } +int mp_rename(const char *oldpath, const char *newpath) +{ + wchar_t *woldpath = mp_from_utf8(NULL, oldpath), + *wnewpath = mp_from_utf8(NULL, newpath); + BOOL ok = MoveFileExW(woldpath, wnewpath, MOVEFILE_REPLACE_EXISTING); + talloc_free(woldpath); + talloc_free(wnewpath); + if (!ok) { + set_errno_from_lasterror(); + return -1; + } + return 0; +} + FILE *mp_fopen(const char *filename, const char *mode) { if (!mode[0]) { diff --git a/osdep/io.h b/osdep/io.h index 6f398c7f95..db711fb265 100644 --- a/osdep/io.h +++ b/osdep/io.h @@ -98,6 +98,7 @@ int mp_printf(const char *format, ...); int mp_fprintf(FILE *stream, const char *format, ...); int mp_open(const char *filename, int oflag, ...); int mp_creat(const char *filename, int mode); +int mp_rename(const char *oldpath, const char *newpath); FILE *mp_fopen(const char *filename, const char *mode); DIR *mp_opendir(const char *path); struct dirent *mp_readdir(DIR *dir); @@ -164,6 +165,7 @@ void mp_globfree(mp_glob_t *pglob); #define fprintf(...) mp_fprintf(__VA_ARGS__) #define open(...) mp_open(__VA_ARGS__) #define creat(...) mp_creat(__VA_ARGS__) +#define rename(...) mp_rename(__VA_ARGS__) #define fopen(...) mp_fopen(__VA_ARGS__) #define opendir(...) mp_opendir(__VA_ARGS__) #define readdir(...) mp_readdir(__VA_ARGS__)