Some more debugging output. (g_io_channel_win32_poll): Remove unused vars.
[platform/upstream/glib.git] / glib / gwin32.c
index eb13759..b45b265 100644 (file)
@@ -3,23 +3,23 @@
  * Copyright (C) 1998-1999  Tor Lillqvist
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
 
 /*
- * Modified by the GLib Team and others 1997-1999.  See the AUTHORS
+ * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
  * file for a list of people on the GLib Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
@@ -101,7 +101,6 @@ g_win32_opendir (const char *dirname)
   if (k && result->dir_name[k - 1] == '\\')
     {
       result->dir_name[k - 1] = '\0';
-      k--;
     }
   mask = g_strdup_printf ("%s\\*", result->dir_name);
 
@@ -131,7 +130,7 @@ g_win32_opendir (const char *dirname)
 struct dirent*
 g_win32_readdir (DIR *dir)
 {
-  static struct dirent result;
+  gchar *basename;
 
   g_return_val_if_fail (dir != NULL, NULL);
 
@@ -154,9 +153,14 @@ g_win32_readdir (DIR *dir)
            }
        }
     }
-  strcpy (result.d_name, g_basename (((LPWIN32_FIND_DATA) dir->find_file_data)->cFileName));
+  
+  basename = g_path_get_basename (((LPWIN32_FIND_DATA) dir->find_file_data)->cFileName);
+
+  strcpy (dir->readdir_result.d_name, basename);
+
+  g_free (basename);
       
-  return &result;
+  return &dir->readdir_result;
 }
 
 void
@@ -525,11 +529,18 @@ g_win32_closedir (DIR *dir)
 gchar *
 g_win32_getlocale (void)
 {
-  LCID lcid = GetThreadLocale ();
+  LCID lcid;
+  gchar *ev;
   gint primary, sub;
   gchar *l = NULL, *sl = NULL;
   gchar bfr[20];
 
+  if ((ev = getenv ("LC_ALL")) != NULL
+      || (ev = getenv ("LC_CTYPE")) != NULL
+      || (ev = getenv ("LANG")) != NULL)
+    return g_strdup (ev);
+
+  lcid = GetThreadLocale ();
   primary = PRIMARYLANGID (LANGIDFROMLCID (lcid));
   sub = SUBLANGID (LANGIDFROMLCID (lcid));
   switch (primary)
@@ -587,7 +598,7 @@ g_win32_getlocale (void)
                                 */
       switch (sub)
        {
-       case SUBLANG_SERBIAN_LATIN: l = "hr"; break;
+       case SUBLANG_SERBIAN_LATIN: l = "sp"; break;
        case SUBLANG_SERBIAN_CYRILLIC: l = "sr"; break;
        default: l = "hr";      /* ??? */
        }
@@ -605,7 +616,10 @@ g_win32_getlocale (void)
       l = "en";
       switch (sub)
        {
-       case SUBLANG_ENGLISH_US: sl = "US"; break;
+       /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought
+        * English was the language spoken in England.
+        * Oh well.
+        */
        case SUBLANG_ENGLISH_UK: sl = "GB"; break;
        case SUBLANG_ENGLISH_AUS: sl = "AU"; break;
        case SUBLANG_ENGLISH_CAN: sl = "CA"; break;
@@ -679,7 +693,6 @@ g_win32_getlocale (void)
       l = "ms";
       switch (sub)
        {
-       case SUBLANG_MALAY_MALAYSIA: sl = "MY"; break;
        case SUBLANG_MALAY_BRUNEI_DARUSSALAM: sl = "BN"; break;
        }
       break;
@@ -697,7 +710,7 @@ g_win32_getlocale (void)
       l = "no";
       switch (sub)
        {
-       case SUBLANG_NORWEGIAN_BOKMAL: sl = "@bokmal"; break;
+       /* SUBLANG_NORWEGIAN_BOKMAL == SUBLANG_DEFAULT */
        case SUBLANG_NORWEGIAN_NYNORSK: sl = "@nynorsk"; break;
        }
       break;
@@ -707,6 +720,7 @@ g_win32_getlocale (void)
       l = "pt";
       switch (sub)
        {
+       /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT */
        case SUBLANG_PORTUGUESE_BRAZILIAN: sl = "BR"; break;
        }
       break;
@@ -768,7 +782,6 @@ g_win32_getlocale (void)
       l = "uz";
       switch (sub)
        {
-       case SUBLANG_UZBEK_LATIN: sl = "2latin"; break;
        case SUBLANG_UZBEK_CYRILLIC: sl = "@cyrillic"; break;
        }
       break;
@@ -784,3 +797,28 @@ g_win32_getlocale (void)
 
   return g_strdup (bfr);
 }
+
+gchar *
+g_win32_error_message (gint error)
+{
+  gchar *msg;
+  gchar *retval;
+  int nbytes;
+
+  FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER
+                |FORMAT_MESSAGE_IGNORE_INSERTS
+                |FORMAT_MESSAGE_FROM_SYSTEM,
+                NULL, error, 0,
+                (LPTSTR) &msg, 0, NULL);
+  nbytes = strlen (msg);
+
+  if (nbytes > 2 && msg[nbytes-1] == '\n' && msg[nbytes-2] == '\r')
+    msg[nbytes-2] = '\0';
+  
+  retval = g_strdup (msg);
+
+  if (msg != NULL)
+    LocalFree (msg);
+
+  return retval;
+}