filesystem: Added SDL_GetCurrentDirectory().

Fixes #11531.
This commit is contained in:
Ryan C. Gordon
2024-11-27 19:41:37 -05:00
parent 16113374ff
commit f852038384
10 changed files with 101 additions and 2 deletions

View File

@@ -345,4 +345,32 @@ done:
}
return result;
}
char *SDL_SYS_GetCurrentDirectory(void)
{
WCHAR *wstr = NULL;
DWORD buflen = 0;
while (true) {
const DWORD bw = GetCurrentDirectoryW(buflen, wstr);
if (bw == 0) {
WIN_SetError("GetCurrentDirectoryW failed");
return NULL;
} else if (bw < buflen) {
break; // we got it!
}
void *ptr = SDL_realloc(wstr, bw * sizeof (WCHAR));
if (!ptr) {
SDL_free(wstr);
return NULL;
}
wstr = (WCHAR *) ptr;
buflen = bw;
}
char *retval = WIN_StringToUTF8W(wstr);
SDL_free(wstr);
return retval;
}
#endif // SDL_FILESYSTEM_WINDOWS