W32: swap special g_get_prgname() for platform_get_argv0()

Commit 398008da added a W32-only code (from commit 7e0e251a)
to g_get_prgname() that makes this function never return NULL. This
is inconsistent with the other platforms. Revert the change, and add an
implementation for platform_get_argv0(), which is used by GOption when
g_get_prgname() == NULL.

The W32 platform_get_argv0() code is different from the one that was in
g_get_prgname(), because it should be getting argv0, not the name
of the executable that is being run (although most of the time they are
one and the same).

Adjust thest option-argv0 test to expect it to pass on W32.
This commit is contained in:
LRN
2019-04-16 08:40:55 +00:00
committed by Philip Withnall
parent c95e2ae9c9
commit cf39fbd08d
3 changed files with 55 additions and 25 deletions

View File

@@ -1047,29 +1047,6 @@ g_get_prgname (void)
gchar* retval;
G_LOCK (g_prgname);
#ifdef G_OS_WIN32
if (g_prgname == NULL)
{
static gboolean beenhere = FALSE;
if (!beenhere)
{
gchar *utf8_buf = NULL;
wchar_t buf[MAX_PATH+1];
beenhere = TRUE;
if (GetModuleFileNameW (GetModuleHandle (NULL),
buf, G_N_ELEMENTS (buf)) > 0)
utf8_buf = g_utf16_to_utf8 (buf, -1, NULL, NULL, NULL);
if (utf8_buf)
{
g_prgname = g_path_get_basename (utf8_buf);
g_free (utf8_buf);
}
}
}
#endif
retval = g_prgname;
G_UNLOCK (g_prgname);