diff options
author | sfan5 <sfan5@live.de> | 2023-11-06 22:24:10 +0100 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2023-11-10 11:26:10 +0100 |
commit | 8f8b63d6227e82da52f280f25d29f53fb30b7ecf (patch) | |
tree | 9d7e61bccabf7c34424dd9ec88fa17819767bba1 /osdep | |
parent | cad24deea1e2670b8116e869a3aa27b2853f2cc6 (diff) | |
download | mpv-8f8b63d6227e82da52f280f25d29f53fb30b7ecf.tar.bz2 mpv-8f8b63d6227e82da52f280f25d29f53fb30b7ecf.tar.xz |
osdep/io: implement rename() wrapper
This is needed to provide the POSIX behaviour of transparently
overwriting existing paths.
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/io.c | 14 | ||||
-rw-r--r-- | osdep/io.h | 2 |
2 files changed, 16 insertions, 0 deletions
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__) |