You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by wr...@apache.org on 2007/06/01 19:39:49 UTC

svn commit: r543549 - /apr/apr/trunk/misc/unix/errorcodes.c

Author: wrowe
Date: Fri Jun  1 10:39:48 2007
New Revision: 543549

URL: http://svn.apache.org/viewvc?view=rev&rev=543549
Log:
Explicitly call out FormatMessageA in the general case (we only return char* text)
and in the WINCE case, fall into FormatMessageW and perform uglyness to transcode
this into 7 bit ascii + '?' patterns for unrepresentable bytes.  The right solution
is to transcode to utf-8, but that's not possible while we have one fixed-size
buffer to work with.  Using a TLS utf-8/unicode buffer would be lovely but it's
not reentrant, so defer closing PR 39895 for now (as an enhancement not a blocker).

PR: 39895/Attachment 
Submitted by: Curt Arnold <carnold apache.org>

Modified:
    apr/apr/trunk/misc/unix/errorcodes.c

Modified: apr/apr/trunk/misc/unix/errorcodes.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/misc/unix/errorcodes.c?view=diff&rev=543549&r1=543548&r2=543549
==============================================================================
--- apr/apr/trunk/misc/unix/errorcodes.c (original)
+++ apr/apr/trunk/misc/unix/errorcodes.c Fri Jun  1 10:39:48 2007
@@ -247,14 +247,34 @@
     apr_size_t len=0, i;
 
 #ifndef NETWARE
-    len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM 
+#ifndef _WIN32_WCE
+    len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM 
                       | FORMAT_MESSAGE_IGNORE_INSERTS,
                         NULL,
                         errcode,
                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
-                        (LPTSTR) buf,
+                        buf,
                         (DWORD)bufsize,
                         NULL);
+#else /* _WIN32_WCE speaks unicode */
+     LPTSTR msg = (LPTSTR) buf;
+     len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM 
+                       | FORMAT_MESSAGE_IGNORE_INSERTS,
+                         NULL,
+                         errcode,
+                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
+                         msg,
+                         (DWORD) (bufsize/sizeof(TCHAR)),
+                         NULL);
+     /* in-place convert to US-ASCII, substituting '?' for non ASCII   */
+     for(i = 0; i <= len; i++) {
+        if (msg[i] < 0x80 && msg[i] >= 0) {
+            buf[i] = (char) msg[i];
+        } else {
+            buf[i] = '?';
+        }
+    }
+#endif
 #endif
 
     if (!len) {