osdep/io: implement rename() wrapper

This is needed to provide the POSIX behaviour of transparently
overwriting existing paths.
This commit is contained in:
sfan5
2023-11-06 22:24:10 +01:00
parent cad24deea1
commit 8f8b63d622
2 changed files with 16 additions and 0 deletions

View File

@@ -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]) {