File 0003-Add-g_win32_get_utf8_argv.patch of Package mingw32-glib2
From 777aae5ff711d68c8a2e9b4d19bfb4cbde5dc6b4 Mon Sep 17 00:00:00 2001
From: Hib Eris <hib@hiberis.nl>
Date: Wed, 6 Feb 2013 09:45:03 +0100
Subject: [PATCH 3/4] Add g_win32_get_utf8_argv()
Based on patch by Christian Persch.
https://bugzilla.gnome.org/show_bug.cgi?id=522131
---
docs/reference/glib/glib-sections.txt | 1 +
glib/gwin32.c | 58 +++++++++++++++++++++++++++++++++++
glib/gwin32.h | 3 ++
3 files changed, 62 insertions(+)
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index b7915d3..eee5647 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -1997,6 +1997,7 @@ g_win32_get_package_installation_directory_of_module
g_win32_get_package_installation_subdirectory
g_win32_get_windows_version
g_win32_locale_filename_from_utf8
+g_win32_get_utf8_argv
G_WIN32_DLLMAIN_FOR_DLL_NAME
G_WIN32_HAVE_WIDECHAR_API
G_WIN32_IS_NT_BASED
diff --git a/glib/gwin32.c b/glib/gwin32.c
index 97eccd7..f5be5fc 100644
--- a/glib/gwin32.c
+++ b/glib/gwin32.c
@@ -575,3 +575,61 @@ g_win32_locale_filename_from_utf8 (const gchar *utf8filename)
}
return retval;
}
+
+/**
+ * g_win32_get_utf8_argv():
+ * @expand_wildcards: %TRUE if wildcards should be expanded.
+ * @argc: (allow-none): a location to store the array length
+ *
+ * Creates an array containing the Windows Unicode command line arguments
+ * retrieved with __wgetmainargs.
+ *
+ * Unlike the arguments that the system passes to main and WinMain,
+ * the Unicode command line contains sufficient information
+ * to correctly open files with names that are not representable
+ * in the system codepage. This situation can arise when e.g. files
+ * with Chinese names are opened on an English version of Windows.
+ *
+ * Returns: (array length=argc) (element-type utf-8): the newly allocated array of
+ * command line arguments
+ *
+ * Since: 2.36
+ */
+
+typedef struct {
+ int newmode;
+} _startupinfo;
+
+extern void __wgetmainargs(int *argc,
+ wchar_t ***wargv,
+ wchar_t ***wenviron,
+ int expand_wildcards,
+ _startupinfo *startupinfo);
+
+gchar**
+g_win32_get_utf8_argv (gboolean expand_wildcards, gint *argc)
+{
+ gchar **argv;
+ wchar_t **wargv, **wenviron;
+ gint i, n;
+ int dowildcard;
+ _startupinfo si = { 0 };
+
+ if (expand_wildcards)
+ dowildcard = -1;
+ else
+ dowildcard = 0;
+
+ __wgetmainargs (&n, &wargv, &wenviron, dowildcard, &si);
+
+ if (argc)
+ *argc = n;
+
+ argv = g_new0 (gchar *, n + 1);
+
+ for (i = 0; i < n; ++i)
+ argv[i] = g_utf16_to_utf8 ((gunichar2 *) wargv[i], -1, NULL, NULL, NULL);
+ argv[n] = NULL;
+
+ return argv;
+}
diff --git a/glib/gwin32.h b/glib/gwin32.h
index ae87a45..2300532 100644
--- a/glib/gwin32.h
+++ b/glib/gwin32.h
@@ -106,6 +106,9 @@ guint g_win32_get_windows_version (void);
GLIB_AVAILABLE_IN_ALL
gchar* g_win32_locale_filename_from_utf8 (const gchar *utf8filename);
+GLIB_AVAILABLE_IN_2_36
+gchar** g_win32_get_utf8_argv (gboolean expand_wildcards, gint *argc);
+
/* As of GLib 2.14 we only support NT-based Windows */
#define G_WIN32_IS_NT_BASED() TRUE
#define G_WIN32_HAVE_WIDECHAR_API() TRUE
--
1.8.1.2