Skip to content

Commit

Permalink
osdep/io: add mp_unlink()
Browse files Browse the repository at this point in the history
unlink() was never wrapped in win32, so all usages of it were referring
the ANSI version of the function. This doesn't work properly for Windows
versions before 1903 (where the UTF-8 codepage is requested).

Fix this by adding mp_unlink() which wraps over _wunlink().
  • Loading branch information
na-na-hi authored and sfan5 committed Feb 25, 2024
1 parent 748504d commit ab3a632
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions osdep/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,14 @@ int mp_mkdir(const char *path, int mode)
return res;
}

int mp_unlink(const char *path)
{
wchar_t *wpath = mp_from_utf8(NULL, path);
int res = _wunlink(wpath);
talloc_free(wpath);
return res;
}

char *mp_win32_getcwd(char *buf, size_t size)
{
if (size >= SIZE_MAX / 3 - 1) {
Expand Down
2 changes: 2 additions & 0 deletions osdep/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ DIR *mp_opendir(const char *path);
struct dirent *mp_readdir(DIR *dir);
int mp_closedir(DIR *dir);
int mp_mkdir(const char *path, int mode);
int mp_unlink(const char *path);
char *mp_win32_getcwd(char *buf, size_t size);
char *mp_getenv(const char *name);

Expand Down Expand Up @@ -183,6 +184,7 @@ void mp_globfree(mp_glob_t *pglob);
#define readdir(...) mp_readdir(__VA_ARGS__)
#define closedir(...) mp_closedir(__VA_ARGS__)
#define mkdir(...) mp_mkdir(__VA_ARGS__)
#define unlink(...) mp_unlink(__VA_ARGS__)
#define getcwd(...) mp_win32_getcwd(__VA_ARGS__)
#define getenv(...) mp_getenv(__VA_ARGS__)

Expand Down

0 comments on commit ab3a632

Please sign in to comment.