diff -rcN glib2.0-2.18.2-orig/glib/goption.c glib2.0-2.18.2/glib/goption.c
*** glib2.0-2.18.2-orig/glib/goption.c	2008-10-16 16:31:58.000000000 +0200
--- glib2.0-2.18.2/glib/goption.c	2008-12-10 18:39:04.000000000 +0100
***************
*** 33,38 ****
--- 33,44 ----
  #include <stdio.h>
  #include <errno.h>
  
+ #ifdef G_OS_WIN32
+ #define STRICT
+ #include <windows.h>
+ #undef STRICT
+ #endif
+ 
  #define TRANSLATE(group, str) (((group)->translate_func ? (* (group)->translate_func) ((str), (group)->translate_data) : (str)))
  
  #define NO_ARG(entry) ((entry)->arg == G_OPTION_ARG_NONE ||       \
***************
*** 1001,1009 ****
        }	     
      case G_OPTION_ARG_STRING:
        {
! 	gchar *data;
! 	
  	data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
  
  	if (!data)
  	  return FALSE;
--- 1007,1021 ----
        }	     
      case G_OPTION_ARG_STRING:
        {
! 	gchar *data;	
! #ifndef G_OS_WIN32
  	data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
+ 	
+ 	if (!data)
+ 	  return FALSE;
+ #else
+ 	data = g_strdup (value);
+ #endif
  
  	if (!data)
  	  return FALSE;
***************
*** 1021,1028 ****
      case G_OPTION_ARG_STRING_ARRAY:
        {
  	gchar *data;
! 
  	data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
  
  	if (!data)
  	  return FALSE;
--- 1033,1046 ----
      case G_OPTION_ARG_STRING_ARRAY:
        {
  	gchar *data;
! #ifndef G_OS_WIN32
  	data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
+ 	
+ 	if (!data)
+ 	  return FALSE;
+ #else
+ 	data = g_strdup (value);
+ #endif
  
  	if (!data)
  	  return FALSE;
***************
*** 1054,1067 ****
        {
  	gchar *data;
  
- #ifdef G_OS_WIN32
- 	data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
- 	
- 	if (!data)
- 	  return FALSE;
- #else
  	data = g_strdup (value);
! #endif
  	change = get_change (context, G_OPTION_ARG_FILENAME,
  			     entry->arg_data);
  	g_free (change->allocated.str);
--- 1072,1079 ----
        {
  	gchar *data;
  
  	data = g_strdup (value);
! 
  	change = get_change (context, G_OPTION_ARG_FILENAME,
  			     entry->arg_data);
  	g_free (change->allocated.str);
***************
*** 1077,1090 ****
        {
  	gchar *data;
  	
- #ifdef G_OS_WIN32
- 	data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
- 	
- 	if (!data)
- 	  return FALSE;
- #else
  	data = g_strdup (value);
! #endif
  	change = get_change (context, G_OPTION_ARG_STRING_ARRAY,
  			     entry->arg_data);
  
--- 1089,1096 ----
        {
  	gchar *data;
  	
  	data = g_strdup (value);
! 
  	change = get_change (context, G_OPTION_ARG_STRING_ARRAY,
  			     entry->arg_data);
  
***************
*** 1134,1147 ****
  	  data = NULL;
  	else if (entry->flags & G_OPTION_FLAG_FILENAME)
  	  {
! #ifdef G_OS_WIN32
!   	    data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
  #else
  	    data = g_strdup (value);
  #endif
  	  }
- 	else
- 	  data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
  
  	if (!(entry->flags & (G_OPTION_FLAG_NO_ARG|G_OPTION_FLAG_OPTIONAL_ARG)) && 
  	    !data)
--- 1140,1158 ----
  	  data = NULL;
  	else if (entry->flags & G_OPTION_FLAG_FILENAME)
  	  {
! 	    data = g_strdup (value);
! 	  }
! 	else
! 	  {
! #ifndef G_OS_WIN32
! 	    data = g_locale_to_utf8 (value, -1, NULL, NULL, error);
! 
! 	    if (!data)
! 	      return FALSE;
  #else
  	    data = g_strdup (value);
  #endif
  	  }
  
  	if (!(entry->flags & (G_OPTION_FLAG_NO_ARG|G_OPTION_FLAG_OPTIONAL_ARG)) && 
  	    !data)
***************
*** 1530,1536 ****
   * Note that function depends on the 
   * <link linkend="setlocale">current locale</link> for 
   * automatic character set conversion of string and filename
!  * arguments.
   * 
   * Return value: %TRUE if the parsing was successful, 
   *               %FALSE if an error occurred
--- 1541,1552 ----
   * Note that function depends on the 
   * <link linkend="setlocale">current locale</link> for 
   * automatic character set conversion of string and filename
!  * arguments - it assumes that @argv is in locale encoding.
!  *
!  * On Windows, the current process's Unicode command line is
!  * used, and the contents of @argc and @argv are ignored.
!  * When the parsing is successful, the locations they point to
!  * are overwritten with the unparsed arguments.
   * 
   * Return value: %TRUE if the parsing was successful, 
   *               %FALSE if an error occurred
***************
*** 1546,1551 ****
--- 1562,1602 ----
    gint i, j, k;
    GList *list;
  
+ #ifdef G_OS_WIN32
+   /* For Windows, get the real Unicode command line, and ignore the params. */
+   gint *passed_argc = argc;
+   gchar ***passed_argv = argv;
+ 
+   /* probably the result of GetCommandLineW should be freed after use, but
+      MSDN docs don't say anything about this.
+ 
+      GetCommandLineW():	returns the UTF-16 encoded command line of the process,
+ 			and should never fail.
+      wcslen():		returns the count of two-byte characters in an UTF-16
+ 			string.
+   */
+   LPWSTR windows_cmdline = GetCommandLineW ();
+   gchar *cmdline = g_convert ((gchar*) windows_cmdline, wcslen (windows_cmdline) * 2,
+                               "UTF-8", "UTF-16", NULL, NULL, NULL);
+ 
+   /* This may theoretically happen when the command line is invalid UTF-16,
+      e.g. when it has lone surrogate characters. */
+   if (!cmdline)
+     {
+       g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+ 		   _("Failed to convert the command line to UTF-8"), option_name);
+       goto fail;
+     }
+ 
+   /* This may happen when the command line is incorrectly quoted. */
+   if (!g_shell_parse_argv (cmdline, argc, argv, NULL))
+     {
+       g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+ 		   _("Failed to parse the command line"), option_name);
+       goto fail;
+     }
+ #endif
+ 
    /* Set program name */
    if (!g_get_prgname())
      {
***************
*** 1831,1836 ****
--- 1882,1893 ----
  	}      
      }
  
+ #ifdef G_OS_WIN32
+   /* return unparsed arguments */
+   *passed_argc = *argc;
+   *passed_argv = *argv;
+ #endif
+ 
    return TRUE;
  
   fail:
