diff options
author | wm4 <wm4@nowhere> | 2017-04-11 13:51:16 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2017-04-11 13:54:10 +0200 |
commit | 7497b633e9ffbc48cda46215b2d5b1194a3b3a5f (patch) | |
tree | b8b664b2808056d49e16270666d16fea843c29a7 /osdep/io.c | |
parent | 4c516a064a8246c9067eee32578a7a78feb371dc (diff) | |
download | mpv-7497b633e9ffbc48cda46215b2d5b1194a3b3a5f.tar.bz2 mpv-7497b633e9ffbc48cda46215b2d5b1194a3b3a5f.tar.xz |
win32: rewrite getcwd() using GetFullPathNameW
_wgetcwd is apparently not available in all runtimes. Well, whatever.
Diffstat (limited to 'osdep/io.c')
-rw-r--r-- | osdep/io.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/osdep/io.c b/osdep/io.c index 1e1bf19ccf..cee5acd605 100644 --- a/osdep/io.c +++ b/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); |