Skip to content

Commit

Permalink
win32: rewrite getcwd() using GetFullPathNameW
Browse files Browse the repository at this point in the history
_wgetcwd is apparently not available in all runtimes. Well, whatever.
  • Loading branch information
wm4 committed Apr 11, 2017
1 parent 4c516a0 commit 7497b63
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions osdep/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7497b63

Please sign in to comment.