diff options
author | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2007-06-01 17:39:48 +0000 |
---|---|---|
committer | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2007-06-01 17:39:48 +0000 |
commit | 75dc941c443c21e28f7ff20adc09bbf77df4509f (patch) | |
tree | 317ac3813908f5f2523e67b1a4d50a663664f286 /misc | |
parent | d848300c6d0888f5df1475e761e04b233d880f17 (diff) | |
download | libapr-75dc941c443c21e28f7ff20adc09bbf77df4509f.tar.gz |
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>
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@543549 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'misc')
-rw-r--r-- | misc/unix/errorcodes.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/misc/unix/errorcodes.c b/misc/unix/errorcodes.c index e953d1092..e7c2a2ec2 100644 --- a/misc/unix/errorcodes.c +++ b/misc/unix/errorcodes.c @@ -247,14 +247,34 @@ static char *apr_os_strerror(char *buf, apr_size_t bufsize, apr_status_t errcode 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) { |