Skip to content

Commit

Permalink
Fixed compilation of get_utf8_argv() for Windows UWP.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrykos committed Apr 3, 2023
1 parent bacc9d8 commit b97f113
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/share/win_utf8_io/win_utf8_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,22 @@ static wchar_t *wchar_from_utf8(const char *str)
/* retrieve WCHAR commandline, expand wildcards and convert everything to UTF-8 */
int get_utf8_argv(int *argc, char ***argv)
{
#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
typedef int (__cdecl *wgetmainargs_t)(int*, wchar_t***, wchar_t***, int, int*);
wgetmainargs_t wgetmainargs;
HMODULE handle;
#endif
int wargc;
wchar_t **wargv;
wchar_t **wenv;
char **utf8argv;
int ret, i;

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
wargc = __argc;
wargv = __wargv;
wenv = _wenviron;
#else
if ((handle = LoadLibraryW(L"msvcrt.dll")) == NULL) return 1;
if ((wgetmainargs = (wgetmainargs_t)GetProcAddress(handle, "__wgetmainargs")) == NULL) {
FreeLibrary(handle);
Expand All @@ -126,8 +133,11 @@ int get_utf8_argv(int *argc, char ***argv)
FreeLibrary(handle);
return 1;
}
#endif
if ((utf8argv = (char **)calloc(wargc, sizeof(char*))) == NULL) {
#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
FreeLibrary(handle);
#endif
return 1;
}

Expand All @@ -139,7 +149,9 @@ int get_utf8_argv(int *argc, char ***argv)
}
}

#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
FreeLibrary(handle); /* do not free it when wargv or wenv are still in use */
#endif

if (ret == 0) {
*argc = wargc;
Expand Down

0 comments on commit b97f113

Please sign in to comment.