mirror of
https://github.com/mpv-player/mpv
synced 2024-12-26 00:42:57 +00:00
win32: rewrite getcwd() using GetFullPathNameW
_wgetcwd is apparently not available in all runtimes. Well, whatever.
This commit is contained in:
parent
4c516a064a
commit
7497b633e9
13
osdep/io.c
13
osdep/io.c
@ -337,9 +337,18 @@ int mp_mkdir(const char *path, int mode)
|
||||
|
||||
char *mp_win32_getcwd(char *buf, size_t size)
|
||||
{
|
||||
wchar_t *wres = _wgetcwd(NULL, 0);
|
||||
if (!wres)
|
||||
if (size >= SIZE_MAX / 3 - 1) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
size_t wbuffer = size * 3 + 1;
|
||||
wchar_t *wres = talloc_array(NULL, wchar_t, wbuffer);
|
||||
DWORD wlen = GetFullPathNameW(L".", wbuffer, wres, NULL);
|
||||
if (wlen >= wbuffer || wlen == 0) {
|
||||
talloc_free(wres);
|
||||
errno = wlen ? ERANGE : ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
char *t = mp_to_utf8(NULL, wres);
|
||||
free(wres);
|
||||
size_t st = strlen(t);
|
||||
|
Loading…
Reference in New Issue
Block a user