From: Tor Lillqvist Date: Wed, 15 Sep 2004 19:12:19 +0000 (+0000) Subject: Convert message to UTF-8. Technically this breaks API, but the actual use X-Git-Tag: GLIB_2_5_3~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1852bc0da7c0aea5d41ea9efe394e866663eaee2;p=platform%2Fupstream%2Fglib.git Convert message to UTF-8. Technically this breaks API, but the actual use 2004-09-15 Tor Lillqvist * 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. --- diff --git a/ChangeLog b/ChangeLog index c6b2628..5bd3ead 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2004-09-15 Tor Lillqvist + + * 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 * NEWS: Update. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index c6b2628..5bd3ead 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,17 @@ +2004-09-15 Tor Lillqvist + + * 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 * NEWS: Update. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index c6b2628..5bd3ead 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,17 @@ +2004-09-15 Tor Lillqvist + + * 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 * NEWS: Update. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index c6b2628..5bd3ead 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,17 @@ +2004-09-15 Tor Lillqvist + + * 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 * NEWS: Update. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index c6b2628..5bd3ead 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,17 @@ +2004-09-15 Tor Lillqvist + + * 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 * NEWS: Update. diff --git a/glib/gwin32.c b/glib/gwin32.c index b8c69df..14509e4 100644 --- a/glib/gwin32.c +++ b/glib/gwin32.c @@ -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; } diff --git a/glib/gwin32.h b/glib/gwin32.h index 0bc7320..cbe0cb9 100644 --- a/glib/gwin32.h +++ b/glib/gwin32.h @@ -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 */