From 2bcce893274f3f4a69af2c955e15176cf49bec52 Mon Sep 17 00:00:00 2001
From: Mark Salisbury <mark.salisbury@hp.com>
Date: Wed, 13 Jun 2012 14:14:18 -0600
Subject: [PATCH 8/8] strerror.c, setup.h - fixed a couple of compile issues on WinCE.

---
 lib/setup.h    |    2 ++
 lib/strerror.c |   34 ++++++++++++++++++++++++----------
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/lib/setup.h b/lib/setup.h
index 8bb9bed..0623d5d 100644
--- a/lib/setup.h
+++ b/lib/setup.h
@@ -349,6 +349,7 @@
 #  include <io.h>
 #  include <sys/types.h>
 #  include <sys/stat.h>
+#ifndef _WIN32_WCE
 #  undef  lseek
 #  define lseek(fdes,offset,whence)  _lseek(fdes, (long)offset, whence)
 #  define fstat(fdes,stp)            _fstat(fdes, stp)
@@ -356,6 +357,7 @@
 #  define struct_stat                struct _stat
 #  define LSEEK_ERROR                (long)-1
 #endif
+#endif
 
 #ifndef struct_stat
 #  define struct_stat struct stat
diff --git a/lib/strerror.c b/lib/strerror.c
index 8690b84..b0e0229 100644
--- a/lib/strerror.c
+++ b/lib/strerror.c
@@ -1057,18 +1057,32 @@ const char *Curl_sspi_strerror (struct connectdata *conn, int err)
     snprintf(txtbuf, sizeof(txtbuf), "%s (0x%04X%04X)",
              txt, (err >> 16) & 0xffff, err & 0xffff);
     txtbuf[sizeof(txtbuf)-1] = '\0';
-    if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
+
+    {
+      char *p;
+#ifdef _WIN32_WCE
+      wchar_t wbuf[256];
+      wbuf[0] = L'\0';
+
+      if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
                      FORMAT_MESSAGE_IGNORE_INSERTS,
                      NULL, err, LANG_NEUTRAL,
-                     msgbuf, sizeof(msgbuf)-1, NULL)) {
-      char *p;
-      msgbuf[sizeof(msgbuf)-1] = '\0';
-      /* strip trailing '\r\n' or '\n' */
-      if((p = strrchr(msgbuf,'\n')) != NULL && (p - msgbuf) >= 2)
-         *p = '\0';
-      if((p = strrchr(msgbuf,'\r')) != NULL && (p - msgbuf) >= 1)
-         *p = '\0';
-      msg = msgbuf;
+                     wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL)) {
+        wcstombs(msgbuf,wbuf,sizeof(msgbuf)-1);
+#else
+      if(FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
+                      FORMAT_MESSAGE_IGNORE_INSERTS,
+                      NULL, err, LANG_NEUTRAL,
+                      msgbuf, sizeof(msgbuf)-1, NULL)) {
+#endif
+        msgbuf[sizeof(msgbuf)-1] = '\0';
+        /* strip trailing '\r\n' or '\n' */
+        if((p = strrchr(msgbuf,'\n')) != NULL && (p - msgbuf) >= 2)
+           *p = '\0';
+        if((p = strrchr(msgbuf,'\r')) != NULL && (p - msgbuf) >= 1)
+           *p = '\0';
+        msg = msgbuf;
+      }
     }
     if(msg)
       snprintf(outbuf, outmax, "%s - %s", str, msg);
-- 
1.7.4.msysgit.0

