Convert message to UTF-8. Technically this breaks API, but the actual use
authorTor Lillqvist <tml@iki.fi>
Wed, 15 Sep 2004 19:12:19 +0000 (19:12 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Wed, 15 Sep 2004 19:12:19 +0000 (19:12 +0000)
2004-09-15  Tor Lillqvist  <tml@iki.fi>

* glib/gwin32.c (g_win32_error_message): Convert message to
UTF-8. Technically this breaks API, but the actual use cases in
gdk/win32 have assumed it is UTF-8 anyway. Fix
documentation. (#152618, Kazuki Iwamoto)

* glib/gwin32.h: Don't define ftruncate as a macro. Was never a
good idea, and it clashes with newest mingw headers, which have a
ftruncate implementation as an inline function. Thanks to Dominik R.

* glib/gwin32.c (g_win32_ftruncate): Simplify implementation, just
call _chsize() in the C library.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gwin32.c
glib/gwin32.h

index c6b2628..5bd3ead 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2004-09-15  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gwin32.c (g_win32_error_message): Convert message to
+       UTF-8. Technically this breaks API, but the actual use cases in
+       gdk/win32 have assumed it is UTF-8 anyway. Fix
+       documentation. (#152618, Kazuki Iwamoto)
+
+       * glib/gwin32.h: Don't define ftruncate as a macro. Was never a
+       good idea, and it clashes with newest mingw headers, which have a
+       ftruncate implementation as an inline function. Thanks to Dominik R.
+
+       * glib/gwin32.c (g_win32_ftruncate): Simplify implementation, just
+       call _chsize() in the C library.
+
 2004-09-15  Matthias Clasen  <mclasen@redhat.com>
 
        * NEWS: Update.
index c6b2628..5bd3ead 100644 (file)
@@ -1,3 +1,17 @@
+2004-09-15  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gwin32.c (g_win32_error_message): Convert message to
+       UTF-8. Technically this breaks API, but the actual use cases in
+       gdk/win32 have assumed it is UTF-8 anyway. Fix
+       documentation. (#152618, Kazuki Iwamoto)
+
+       * glib/gwin32.h: Don't define ftruncate as a macro. Was never a
+       good idea, and it clashes with newest mingw headers, which have a
+       ftruncate implementation as an inline function. Thanks to Dominik R.
+
+       * glib/gwin32.c (g_win32_ftruncate): Simplify implementation, just
+       call _chsize() in the C library.
+
 2004-09-15  Matthias Clasen  <mclasen@redhat.com>
 
        * NEWS: Update.
index c6b2628..5bd3ead 100644 (file)
@@ -1,3 +1,17 @@
+2004-09-15  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gwin32.c (g_win32_error_message): Convert message to
+       UTF-8. Technically this breaks API, but the actual use cases in
+       gdk/win32 have assumed it is UTF-8 anyway. Fix
+       documentation. (#152618, Kazuki Iwamoto)
+
+       * glib/gwin32.h: Don't define ftruncate as a macro. Was never a
+       good idea, and it clashes with newest mingw headers, which have a
+       ftruncate implementation as an inline function. Thanks to Dominik R.
+
+       * glib/gwin32.c (g_win32_ftruncate): Simplify implementation, just
+       call _chsize() in the C library.
+
 2004-09-15  Matthias Clasen  <mclasen@redhat.com>
 
        * NEWS: Update.
index c6b2628..5bd3ead 100644 (file)
@@ -1,3 +1,17 @@
+2004-09-15  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gwin32.c (g_win32_error_message): Convert message to
+       UTF-8. Technically this breaks API, but the actual use cases in
+       gdk/win32 have assumed it is UTF-8 anyway. Fix
+       documentation. (#152618, Kazuki Iwamoto)
+
+       * glib/gwin32.h: Don't define ftruncate as a macro. Was never a
+       good idea, and it clashes with newest mingw headers, which have a
+       ftruncate implementation as an inline function. Thanks to Dominik R.
+
+       * glib/gwin32.c (g_win32_ftruncate): Simplify implementation, just
+       call _chsize() in the C library.
+
 2004-09-15  Matthias Clasen  <mclasen@redhat.com>
 
        * NEWS: Update.
index c6b2628..5bd3ead 100644 (file)
@@ -1,3 +1,17 @@
+2004-09-15  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gwin32.c (g_win32_error_message): Convert message to
+       UTF-8. Technically this breaks API, but the actual use cases in
+       gdk/win32 have assumed it is UTF-8 anyway. Fix
+       documentation. (#152618, Kazuki Iwamoto)
+
+       * glib/gwin32.h: Don't define ftruncate as a macro. Was never a
+       good idea, and it clashes with newest mingw headers, which have a
+       ftruncate implementation as an inline function. Thanks to Dominik R.
+
+       * glib/gwin32.c (g_win32_ftruncate): Simplify implementation, just
+       call _chsize() in the C library.
+
 2004-09-15  Matthias Clasen  <mclasen@redhat.com>
 
        * NEWS: Update.
index b8c69df..14509e4 100644 (file)
@@ -62,33 +62,7 @@ gint
 g_win32_ftruncate (gint  fd,
                   guint size)
 {
-  HANDLE hfile;
-  guint curpos;
-
-  g_return_val_if_fail (fd >= 0, -1);
-  
-  hfile = (HANDLE) _get_osfhandle (fd);
-  curpos = SetFilePointer (hfile, 0, NULL, FILE_CURRENT);
-  if (curpos == 0xFFFFFFFF
-      || SetFilePointer (hfile, size, NULL, FILE_BEGIN) == 0xFFFFFFFF
-      || !SetEndOfFile (hfile))
-    {
-      gint error = GetLastError ();
-
-      switch (error)
-       {
-       case ERROR_INVALID_HANDLE:
-         errno = EBADF;
-         break;
-       default:
-         errno = EIO;
-         break;
-       }
-
-      return -1;
-    }
-
-  return 0;
+  return _chsize (fd, size);
 }
 
 #endif
@@ -1068,15 +1042,16 @@ g_win32_getlocale (void)
  * Translate a Win32 error code (as returned by GetLastError()) into
  * the corresponding message. The message is either language neutral,
  * or in the thread's language, or the user's language, the system's
- * language, or US English (see docs for FormatMessage()). *
- * The returned string should be deallocated with g_free().
+ * language, or US English (see docs for FormatMessage()). The
+ * returned string is in UTF-8. It should be deallocated with
+ * g_free().
  *
  * Returns: newly-allocated error message
  **/
 gchar *
 g_win32_error_message (gint error)
 {
-  gchar *msg;
+  gchar *msg = NULL;
   gchar *retval;
   int nbytes;
 
@@ -1085,15 +1060,19 @@ g_win32_error_message (gint error)
                 |FORMAT_MESSAGE_FROM_SYSTEM,
                 NULL, error, 0,
                 (LPTSTR) &msg, 0, NULL);
-  nbytes = strlen (msg);
+  if (msg != NULL)
+    {
+      nbytes = strlen (msg);
 
-  if (nbytes > 2 && msg[nbytes-1] == '\n' && msg[nbytes-2] == '\r')
-    msg[nbytes-2] = '\0';
+      if (nbytes > 2 && msg[nbytes-1] == '\n' && msg[nbytes-2] == '\r')
+       msg[nbytes-2] = '\0';
   
-  retval = g_strdup (msg);
+      retval = g_locale_to_utf8 (msg, -1, NULL, NULL, NULL);
 
-  if (msg != NULL)
-    LocalFree (msg);
+      LocalFree (msg);
+    }
+  else
+    retval = g_strdup ("");
 
   return retval;
 }
index 0bc7320..cbe0cb9 100644 (file)
@@ -64,10 +64,10 @@ typedef int pid_t;
 #define pipe(phandles) _pipe (phandles, 4096, _O_BINARY)
 
 /* For some POSIX functions that are not provided by the MS runtime,
- * we provide emulators in glib, which are prefixed with g_win32_.
+ * we provide emulation functions in glib, which are prefixed with
+ * g_win32_. Or that was the idea at some time, but there is just one
+ * of those:
  */
-#    define ftruncate(fd, size)        g_win32_ftruncate (fd, size)
-
 gint           g_win32_ftruncate       (gint            f,
                                         guint           size);
 #endif /* G_OS_WIN32 */