win32: rewrite getcwd() using GetFullPathNameW

_wgetcwd is apparently not available in all runtimes. Well, whatever.
This commit is contained in:
wm4 committed 2017-04-11 13:54:10 +02:00
1 parent 4c516a064a
commit 7497b633e9
1 file changed
+11 -2
+11 -2
View File
@@ -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);