+ return windows_version;
+}
+
+/**
+ * g_win32_locale_filename_from_utf8:
+ * @utf8filename: a UTF-8 encoded filename.
+ *
+ * Converts a filename from UTF-8 to the system codepage.
+ *
+ * On NT-based Windows, on NTFS file systems, file names are in
+ * Unicode. It is quite possible that Unicode file names contain
+ * characters not representable in the system codepage. (For instance,
+ * Greek or Cyrillic characters on Western European or US Windows
+ * installations, or various less common CJK characters on CJK Windows
+ * installations.)
+ *
+ * In such a case, and if the filename refers to an existing file, and
+ * the file system stores alternate short (8.3) names for directory
+ * entries, the short form of the filename is returned. Note that the
+ * "short" name might in fact be longer than the Unicode name if the
+ * Unicode name has very short pathname components containing
+ * non-ASCII characters. If no system codepage name for the file is
+ * possible, %NULL is returned.
+ *
+ * The return value is dynamically allocated and should be freed with
+ * g_free() when no longer needed.
+ *
+ * Returns: The converted filename, or %NULL on conversion
+ * failure and lack of short names.
+ *
+ * Since: 2.8
+ */
+gchar *
+g_win32_locale_filename_from_utf8 (const gchar *utf8filename)
+{
+ gchar *retval = g_locale_from_utf8 (utf8filename, -1, NULL, NULL, NULL);
+
+ if (retval == NULL)
+ {
+ /* Conversion failed, so convert to wide chars, check if there
+ * is a 8.3 version, and use that.
+ */
+ wchar_t *wname = g_utf8_to_utf16 (utf8filename, -1, NULL, NULL, NULL);
+ if (wname != NULL)
+ {
+ wchar_t wshortname[MAX_PATH + 1];
+ if (GetShortPathNameW (wname, wshortname, G_N_ELEMENTS (wshortname)))
+ {
+ gchar *tem = g_utf16_to_utf8 (wshortname, -1, NULL, NULL, NULL);
+ retval = g_locale_from_utf8 (tem, -1, NULL, NULL, NULL);
+ g_free (tem);
+ }
+ g_free (wname);
+ }
+ }
+ return retval;
+}
+
+/**
+ * g_win32_get_command_line:
+ *
+ * Gets the command line arguments, on Windows, in the GLib filename
+ * encoding (ie: UTF-8).
+ *
+ * Normally, on Windows, the command line arguments are passed to main()
+ * in the system codepage encoding. This prevents passing filenames as
+ * arguments if the filenames contain characters that fall outside of
+ * this codepage. If such filenames are passed, then substitutions
+ * will occur (such as replacing some characters with '?').
+ *
+ * GLib's policy of using UTF-8 as a filename encoding on Windows was
+ * designed to localise the pain of dealing with filenames outside of
+ * the system codepage to one area: dealing with commandline arguments
+ * in main().
+ *
+ * As such, most GLib programs should ignore the value of argv passed to
+ * their main() function and call g_win32_get_command_line() instead.
+ * This will get the "full Unicode" commandline arguments using
+ * GetCommandLineW() and convert it to the GLib filename encoding (which
+ * is UTF-8 on Windows).
+ *
+ * The strings returned by this function are suitable for use with
+ * functions such as g_open() and g_file_new_for_commandline_arg() but
+ * are not suitable for use with g_option_context_parse(), which assumes
+ * that its input will be in the system codepage. The return value is
+ * suitable for use with g_option_context_parse_strv(), however, which
+ * is a better match anyway because it won't leak memory.
+ *
+ * Unlike argv, the returned value is a normal strv and can (and should)
+ * be freed with g_strfreev() when no longer needed.
+ *
+ * Returns: (transfer full): the commandline arguments in the GLib
+ * filename encoding (ie: UTF-8)
+ *
+ * Since: 2.40
+ **/
+gchar **
+g_win32_get_command_line (void)
+{
+ gchar **result;
+ LPWSTR *args;
+ gint i, n;
+
+ args = CommandLineToArgvW (GetCommandLineW(), &n);
+
+ result = g_new (gchar *, n + 1);
+ for (i = 0; i < n; i++)
+ result[i] = g_utf16_to_utf8 (args[i], -1, NULL, NULL, NULL);
+ result[i] = NULL;
+
+ return result;