Ioan Popescu wrote:
> I've checked the libapriconv and libaprutil patches and both apply cleanly
> to trunk. Not all patches to libapr are clean, but the ones that are, I've
> reattached. I've also found a couple errors in my own previous patches to
> libapr and updated the use of _WIN32_WCE. APIs existing before or including
> CE 3 default to checking whether it's defined. APIs existing afterwards are
> used only if they exist (depends on _WIN32_WCE version).

Here's the rest.

Index: file_io/win32/filedup.c
===================================================================
--- file_io/win32/filedup.c     (revision 584782)
+++ file_io/win32/filedup.c     (working copy)
@@ -20,7 +20,9 @@
 #include "apr_strings.h"
 #include <string.h>
 #include "apr_arch_inherit.h"
+#ifndef _WIN32_WCE
 #include <io.h> /* for [_open/_get]_osfhandle */
+#endif
 
 
 APR_DECLARE(apr_status_t) apr_file_dup(apr_file_t **new_file,
Index: file_io/win32/open.c
===================================================================
--- file_io/win32/open.c        (revision 584782)
+++ file_io/win32/open.c        (working copy)
@@ -31,7 +31,9 @@
 #endif
 #include "apr_arch_misc.h"
 #include "apr_arch_inherit.h"
+#ifndef _WIN32_WCE
 #include <io.h>
+#endif
 #include <WinIoCtl.h>
 
 #if APR_HAS_UNICODE_FS
@@ -223,6 +225,9 @@
 
 static apr_status_t make_sparse_file(apr_file_t *file)
 {
+#ifdef _WIN32_WCE
+    return APR_ENOTIMPL;
+#else
     BY_HANDLE_FILE_INFORMATION info;
     apr_status_t rv;
     DWORD bytesread = 0;
@@ -269,6 +274,7 @@
         }
     }
     return rv;
+#endif
 }
 
 apr_status_t file_cleanup(void *thefile)
@@ -290,6 +296,7 @@
          */
         if (file->flags & APR_STD_FLAGS)
         {
+#ifndef _WIN32_WCE
             if ((file->flags & APR_STD_FLAGS) == APR_STDERR_FLAG) {
                 _close(2);
                 SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE);
@@ -302,6 +309,7 @@
                 _close(0);
                 SetStdHandle(STD_INPUT_HANDLE, INVALID_HANDLE_VALUE);
             }
+#endif
         }
         else
             CloseHandle(file->filehand);
@@ -332,8 +340,10 @@
     if (flag & APR_WRITE) {
         oflags |= GENERIC_WRITE;
     }
-    if (flag & APR_WRITEATTRS) {
-        oflags |= FILE_WRITE_ATTRIBUTES;
+    if (apr_os_level < APR_WIN_CE_3 || apr_os_level >= APR_WIN_NT) {
+        if (flag & APR_WRITEATTRS) {
+            oflags |= FILE_WRITE_ATTRIBUTES;
+        }
     }
 
     if (apr_os_level >= APR_WIN_NT) 
@@ -362,12 +372,14 @@
         return APR_EACCES;
     }   
     
-    if (flag & APR_DELONCLOSE) {
-        attributes |= FILE_FLAG_DELETE_ON_CLOSE;
-    }
+    if (apr_os_level < APR_WIN_CE_3 || apr_os_level >= APR_WIN_NT) {
+        if (flag & APR_DELONCLOSE) {
+            attributes |= FILE_FLAG_DELETE_ON_CLOSE;
+        }
 
-    if (flag & APR_OPENLINK) {
-       attributes |= FILE_FLAG_OPEN_REPARSE_POINT;
+        if (flag & APR_OPENLINK) {
+           attributes |= FILE_FLAG_OPEN_REPARSE_POINT;
+        }
     }
 
     /* Without READ or WRITE, we fail unless apr called apr_file_open
@@ -386,15 +398,19 @@
         else {
             return APR_EACCES;
         }
-        if (flag & APR_READCONTROL)
-            oflags |= READ_CONTROL;
+        if (apr_os_level < APR_WIN_CE_3 || apr_os_level >= APR_WIN_NT) {
+            if (flag & APR_READCONTROL)
+                oflags |= READ_CONTROL;
+        }
     }
 
-    if (flag & APR_XTHREAD) {
-        /* This win32 specific feature is required 
-         * to allow multiple threads to work with the file.
-         */
-        attributes |= FILE_FLAG_OVERLAPPED;
+    if (apr_os_level < APR_WIN_CE_3 || apr_os_level >= APR_WIN_NT) {
+        if (flag & APR_XTHREAD) {
+            /* This win32 specific feature is required 
+             * to allow multiple threads to work with the file.
+             */
+            attributes |= FILE_FLAG_OVERLAPPED;
+        }
     }
 
 #if APR_HAS_UNICODE_FS
@@ -537,6 +553,23 @@
         if (MoveFileExW(wfrompath, wtopath, MOVEFILE_REPLACE_EXISTING |
                                             MOVEFILE_COPY_ALLOWED))
 #else
+        /* Windows CE does not support MoveFileEx, so we'll use
+         * the old MoveFile function.  However, MoveFile requires that
+         * the new file not already exist...so we have to delete that
+         * file if it does.  Perhaps we should back up the to-be-deleted
+         * file in case something happens?
+         */
+        do {
+            HANDLE handle = INVALID_HANDLE_VALUE;
+
+            if ((handle = CreateFileW(wtopath, GENERIC_WRITE, 0, 0,  
+                OPEN_EXISTING, 0, 0 )) != INVALID_HANDLE_VALUE )
+            {
+                CloseHandle(handle);
+                if (!DeleteFileW(wtopath))
+                    return apr_get_os_error();
+            }
+        } while (0);
         if (MoveFileW(wfrompath, wtopath))
 #endif
             return APR_SUCCESS;
@@ -635,57 +668,57 @@
                                                      apr_int32_t flags, 
                                                      apr_pool_t *pool)
 {
-#ifdef _WIN32_WCE
-    return APR_ENOTIMPL;
-#else
     apr_os_file_t file_handle;
 
     apr_set_os_error(APR_SUCCESS);
+#ifndef _WIN32_WCE
     file_handle = GetStdHandle(STD_ERROR_HANDLE);
+#else
+    file_handle = STDERR_FILENO;
+#endif
     if (!file_handle)
         file_handle = INVALID_HANDLE_VALUE;
 
     return apr_os_file_put(thefile, &file_handle,
                            flags | APR_WRITE | APR_STDERR_FLAG, pool);
-#endif
 }
 
 APR_DECLARE(apr_status_t) apr_file_open_flags_stdout(apr_file_t **thefile, 
                                                      apr_int32_t flags,
                                                      apr_pool_t *pool)
 {
-#ifdef _WIN32_WCE
-    return APR_ENOTIMPL;
-#else
     apr_os_file_t file_handle;
 
     apr_set_os_error(APR_SUCCESS);
+#ifndef _WIN32_WCE
     file_handle = GetStdHandle(STD_OUTPUT_HANDLE);
+#else
+    file_handle = STDOUT_FILENO;
+#endif
     if (!file_handle)
         file_handle = INVALID_HANDLE_VALUE;
 
     return apr_os_file_put(thefile, &file_handle,
                            flags | APR_WRITE | APR_STDOUT_FLAG, pool);
-#endif
 }
 
 APR_DECLARE(apr_status_t) apr_file_open_flags_stdin(apr_file_t **thefile, 
                                                     apr_int32_t flags,
                                                     apr_pool_t *pool)
 {
-#ifdef _WIN32_WCE
-    return APR_ENOTIMPL;
-#else
     apr_os_file_t file_handle;
 
     apr_set_os_error(APR_SUCCESS);
+#ifndef _WIN32_WCE
     file_handle = GetStdHandle(STD_INPUT_HANDLE);
+#else
+    file_handle = STDIN_FILENO;
+#endif
     if (!file_handle)
         file_handle = INVALID_HANDLE_VALUE;
 
     return apr_os_file_put(thefile, &file_handle,
                            flags | APR_READ | APR_STDIN_FLAG, pool);
-#endif
 }
 
 APR_DECLARE(apr_status_t) apr_file_open_stderr(apr_file_t **thefile, 
apr_pool_t *pool)
Index: file_io/win32/readwrite.c
===================================================================
--- file_io/win32/readwrite.c   (revision 584782)
+++ file_io/win32/readwrite.c   (working copy)
@@ -31,7 +31,9 @@
 static apr_status_t read_with_timeout(apr_file_t *file, void *buf, apr_size_t 
len_in, apr_size_t *nbytes)
 {
     apr_status_t rv;
+#ifndef _WIN32_WCE
     DWORD res;
+#endif
     DWORD len = (DWORD)len_in;
     DWORD bytesread = 0;
 
@@ -41,6 +43,7 @@
          * If data is available, go ahead and read it.
          */
         if (file->pipe) {
+#ifndef _WIN32_WCE
             DWORD bytes;
             if (!PeekNamedPipe(file->filehand, NULL, 0, NULL, &bytes, NULL)) {
                 rv = apr_get_os_error();
@@ -59,6 +62,7 @@
                     len = bytes;
                 }
             }
+#endif
         }
         else {
             /* ToDo: Handle zero timeout non-blocking file i/o 
@@ -73,12 +77,18 @@
         file->pOverlapped->OffsetHigh = (DWORD)(file->filePtr >> 32);
     }
 
+#ifndef _WIN32_WCE
     if (ReadFile(file->filehand, buf, len, 
                  &bytesread, file->pOverlapped)) {
+#else
+    if (ReadFile(file->filehand, buf, len, 
+                 &bytesread, NULL)) {
+#endif
         rv = APR_SUCCESS;
     }
     else {
         rv = apr_get_os_error();
+#ifndef _WIN32_WCE
         if (rv == APR_FROM_OS_ERROR(ERROR_IO_PENDING)) {
             /* Wait for the pending i/o, timeout converted from us to ms
              * Note that we loop if someone gives up the event, since
@@ -120,6 +130,7 @@
                     rv = APR_TIMEUP;
             }
         }
+#endif
         if (rv == APR_FROM_OS_ERROR(ERROR_BROKEN_PIPE)) {
             /* Assume ERROR_BROKEN_PIPE signals an EOF reading from a pipe */
             rv = APR_EOF;
@@ -150,6 +161,10 @@
         return APR_SUCCESS;
     }
 
+    /* CE doesn't support overlapped I/O, but "supports" thread-safe
+     * file access natively.
+     */
+#ifndef _WIN32_WCE
     /* If the file is open for xthread support, allocate and
      * initialize the overlapped and io completion event (hEvent). 
      * Threads should NOT share an apr_file_t or its hEvent.
@@ -163,6 +178,7 @@
             return rv;
         }
     }
+#endif
 
     /* Handle the ungetchar if there is one */
     if (thefile->ungetchar != -1) {
@@ -241,6 +257,10 @@
     apr_status_t rv;
     DWORD bwrote;
 
+    /* CE doesn't support overlapped I/O, but "supports" thread-safe
+     * file access natively.
+     */
+#ifndef _WIN32_WCE
     /* If the file is open for xthread support, allocate and
      * initialize the overlapped and io completion event (hEvent). 
      * Threads should NOT share an apr_file_t or its hEvent.
@@ -254,6 +274,7 @@
             return rv;
         }
     }
+#endif
 
     if (thefile->buffered) {
         char *pos = (char *)buf;
@@ -314,16 +335,37 @@
                 thefile->pOverlapped->Offset     = (DWORD)thefile->filePtr;
                 thefile->pOverlapped->OffsetHigh = (DWORD)(thefile->filePtr >> 
32);
             }
+#ifndef _WIN32_WCE
             rv = WriteFile(thefile->filehand, buf, (DWORD)*nbytes, &bwrote,
                            thefile->pOverlapped);
+#else
+            rv = WriteFile(thefile->filehand, buf, (DWORD)*nbytes, &bwrote,
+                           NULL);
+            /* WriteFile() fails upon writing zero amount when "appending" to
+             * a file. Succeeds in writing zero amount in all other cases.
+             * Most likely has something to do with SetFilePointer() being
+             * called. Tried using SetEndOfFile(), but didn't help.
+             *
+             * Just pretend it succeeded in, essentially, not doing anything.
+             */
+            if (rv == 0 && *nbytes == 0) {
+                rv = 1;
+                bwrote = 0;
+            }
+#endif
             if (thefile->append) {
                 apr_file_unlock(thefile);
                 apr_thread_mutex_unlock(thefile->mutex);
             }
         }
         else {
+#ifndef _WIN32_WCE
             rv = WriteFile(thefile->filehand, buf, (DWORD)*nbytes, &bwrote,
                            thefile->pOverlapped);
+#else
+            rv = WriteFile(thefile->filehand, buf, (DWORD)*nbytes, &bwrote,
+                           NULL);
+#endif
         }
         if (rv) {
             *nbytes = bwrote;
@@ -332,6 +374,7 @@
         else {
             (*nbytes) = 0;
             rv = apr_get_os_error();
+#ifndef _WIN32_WCE
 
             /* XXX: This must be corrected, per the apr_file_read logic!!! */
             if (rv == APR_FROM_OS_ERROR(ERROR_IO_PENDING)) {
@@ -370,6 +413,7 @@
                         CancelIo(thefile->filehand);
                 }
             }
+#endif
         }
         if (rv == APR_SUCCESS && thefile->pOverlapped && !thefile->pipe) {
             thefile->filePtr += *nbytes;
@@ -501,6 +545,10 @@
                 bytesleft -= written;
                 buffer += written;
 
+                if (!FlushFileBuffers(thefile->filehand)) {
+                  rc = apr_get_os_error();
+                  break;
+                }
             } while (bytesleft > 0);
 
             if (rc == 0)
Index: file_io/win32/seek.c
===================================================================
--- file_io/win32/seek.c        (revision 584782)
+++ file_io/win32/seek.c        (working copy)
@@ -16,7 +16,9 @@
 
 #include "apr_arch_file_io.h"
 #include "apr_file_io.h"
+#if APR_HAVE_ERRNO_H
 #include <errno.h>
+#endif
 #include <string.h>
 
 static apr_status_t setptr(apr_file_t *thefile, apr_off_t pos )
@@ -100,6 +102,10 @@
         *offset = thefile->filePtr - thefile->dataRead + thefile->bufpos;
         return rc;
     }
+    /* CE doesn't support overlapped i/o, therefore, fallback to letting the
+     * OS handle the file pointer.
+     */
+#ifndef _WIN32_WCE
     /* A file opened with APR_XTHREAD has been opened for overlapped i/o. 
      * APR must explicitly track the file pointer in this case.
      */
@@ -125,6 +131,7 @@
         *offset = thefile->filePtr;
         return rc;
     }
+#endif
     else {
         DWORD howmove;
         DWORD offlo = (DWORD)*offset;
Index: include/apr.hw
===================================================================
--- include/apr.hw      (revision 584782)
+++ include/apr.hw      (working copy)
@@ -96,13 +90,9 @@
  * winsock headers were excluded by WIN32_LEAN_AND_MEAN, so include them now
  */
 #define SW_HIDE             0
-#ifndef _WIN32_WCE
 #include <winsock2.h>
 #include <mswsock.h>
 #include <ws2tcpip.h>
-#else
-#include <winsock.h>
-#endif
 #endif /* !_WINDOWS_ */
 
 /**
@@ -217,7 +207,7 @@
 #define APR_HAVE_IN_ADDR        1
 #define APR_HAVE_INET_ADDR      1
 #define APR_HAVE_INET_NETWORK   0
-#define APR_HAVE_IPV6           0
+#define APR_HAVE_IPV6           1
 #define APR_HAVE_MEMMOVE        1
 #define APR_HAVE_SETRLIMIT      0
 #define APR_HAVE_SIGACTION      0
@@ -231,14 +221,12 @@
 #define APR_HAVE_STRUCT_RLIMIT  0
 #define APR_HAVE_UNION_SEMUN    0
 #define APR_HAVE_SCTP           0
-
-#ifndef _WIN32_WCE
 #define APR_HAVE_STRICMP        1
 #define APR_HAVE_STRNICMP       1
+
+#ifndef _WIN32_WCE
 #define APR_PROCATTR_USER_SET_REQUIRES_PASSWORD 1
 #else
-#define APR_HAVE_STRICMP        0
-#define APR_HAVE_STRNICMP       0
 #define APR_PROCATTR_USER_SET_REQUIRES_PASSWORD 0
 #endif
 
@@ -565,7 +553,7 @@
 #define STDOUT_FILENO 1
 #define STDERR_FILENO 2
 
-#if APR_HAS_UNICODE_FS
+#if APR_HAS_UNICODE_FS && !defined(_WIN32_WCE)
 /* An arbitrary size that is digestable. True max is a bit less than 32000 */
 #define APR_PATH_MAX 8192
 #else /* !APR_HAS_UNICODE_FS */
Index: include/apr_errno.h
===================================================================
--- include/apr_errno.h (revision 584782)
+++ include/apr_errno.h (working copy)
@@ -393,9 +393,13 @@
  * APR was unable to open the dso object.  
  * For more information call apr_dso_error().
  */
-#if defined(WIN32)
+#if defined(_WIN32_WCE)
 #define APR_STATUS_IS_EDSOOPEN(s)       ((s) == APR_EDSOOPEN \
+                       || APR_TO_OS_ERROR(s) == ERROR_INVALID_PARAMETER \
                        || APR_TO_OS_ERROR(s) == ERROR_MOD_NOT_FOUND)
+#elif defined(WIN32)
+#define APR_STATUS_IS_EDSOOPEN(s)       ((s) == APR_EDSOOPEN \
+                       || APR_TO_OS_ERROR(s) == ERROR_MOD_NOT_FOUND)
 #else
 #define APR_STATUS_IS_EDSOOPEN(s)       ((s) == APR_EDSOOPEN)
 #endif
@@ -414,9 +418,13 @@
 /** Could not find the requested symbol.
  * For more information call apr_dso_error().
  */
-#if defined(WIN32)
+#if defined(_WIN32_WCE)
 #define APR_STATUS_IS_ESYMNOTFOUND(s)   ((s) == APR_ESYMNOTFOUND \
+                       || APR_TO_OS_ERROR(s) == ERROR_INVALID_HANDLE \
                        || APR_TO_OS_ERROR(s) == ERROR_PROC_NOT_FOUND)
+#elif defined(WIN32)
+#define APR_STATUS_IS_ESYMNOTFOUND(s)   ((s) == APR_ESYMNOTFOUND \
+                       || APR_TO_OS_ERROR(s) == ERROR_PROC_NOT_FOUND)
 #else
 #define APR_STATUS_IS_ESYMNOTFOUND(s)   ((s) == APR_ESYMNOTFOUND)
 #endif
Index: include/arch/win32/apr_arch_misc.h
===================================================================
--- include/arch/win32/apr_arch_misc.h  (revision 584782)
+++ include/arch/win32/apr_arch_misc.h  (working copy)
@@ -85,9 +85,12 @@
        APR_WIN_UNICODE =  20, /* Prior versions support only narrow chars */
 
         APR_WIN_CE_3 =     23, /* CE is an odd beast, not supporting */
-                               /* some pre-NT features, such as the    */
-        APR_WIN_NT =       30, /* narrow charset APIs (fooA fns), while  */
-        APR_WIN_NT_3_5 =   35, /* not supporting some NT-family features.  */
+        APR_WIN_CE_4 =     24, /* some pre-NT features, such as the    */
+        APR_WIN_CE_5 =     25, /* narrow charset APIs (fooA fns), while  */
+        APR_WIN_CE_6 =     26, /* not supporting some NT-family features.  */
+
+        APR_WIN_NT =       30,
+        APR_WIN_NT_3_5 =   35,
         APR_WIN_NT_3_51 =  36,
 
         APR_WIN_NT_4 =     40,
@@ -191,8 +194,9 @@
     {   if (!apr_winapi_pfn_##fn) \
             apr_winapi_pfn_##fn = (apr_winapi_fpt_##fn) \
                                       apr_load_dll_func(lib, #fn, ord); \
-        return (*(apr_winapi_pfn_##fn)) names; }; \
+        return (*(apr_winapi_pfn_##fn)) names; };
 
+
 /* Provide late bound declarations of every API function missing from
  * one or more supported releases of the Win32 API
  *
Index: misc/win32/misc.c
===================================================================
--- misc/win32/misc.c   (revision 584782)
+++ misc/win32/misc.c   (working copy)
@@ -103,7 +103,7 @@
                 apr_os_level = APR_WIN_XP;
             }
         }
-#ifndef WINNT
+#if !defined(WINNT) && !defined(_WIN32_WCE)
         else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
             TCHAR *prevision;
             if (prevision = oslev.szCSDVersion) {
@@ -136,9 +136,18 @@
             if (oslev.dwMajorVersion < 3) {
                 apr_os_level = APR_WIN_UNSUP;
             }
-            else {
+            else if (oslev.dwMajorVersion < 4) {
                 apr_os_level = APR_WIN_CE_3;
             }
+            else if (oslev.dwMajorVersion < 5) {
+                apr_os_level = APR_WIN_CE_4;
+            }
+            else if (oslev.dwMajorVersion < 6) {
+                apr_os_level = APR_WIN_CE_5;
+            }
+            else {
+                apr_os_level = APR_WIN_CE_6;
+            }
         }
 #endif
         else {
@@ -160,15 +169,16 @@
  * missing from one or more releases of the Win32 API
  */
 
-static const char* const lateDllName[DLL_defined] = {
-    "kernel32", "advapi32", "mswsock",  "ws2_32", "shell32", "ntdll.dll"  };
+static const TCHAR* const lateDllName[DLL_defined] = {
+    _T("kernel32"), _T("advapi32"), _T("mswsock"),
+    _T("ws2_32"), _T("shell32"), _T("ntdll.dll")  };
 static HMODULE lateDllHandle[DLL_defined] = {
      NULL,       NULL,       NULL,       NULL,     NULL,       NULL       };
 
 FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char* fnName, int ordinal)
 {
     if (!lateDllHandle[fnLib]) { 
-        lateDllHandle[fnLib] = LoadLibraryA(lateDllName[fnLib]);
+        lateDllHandle[fnLib] = LoadLibrary(lateDllName[fnLib]);
         if (!lateDllHandle[fnLib])
             return NULL;
     }
@@ -210,11 +220,23 @@
         (TlsSetValue)(tlsid, sbuf);
         sbuf[1023] = '\0';
         if (!fh) {
-            (GetModuleFileNameA)(NULL, sbuf, 250);
+/* CE only has Unicode API. */
+#ifdef _WIN32_WCE
+            wchar_t *wsbuf = malloc(1024);
+            wsbuf[1023] = L'\0';
+            (GetModuleFileNameW)(NULL, wsbuf, 250);
+            swprintf(wcschr(wsbuf, L'\0'), L".%d",
+                    (GetCurrentProcessId)());
+            fh = (CreateFileW)(wsbuf, GENERIC_WRITE, 0, NULL, 
+                            CREATE_ALWAYS, 0, NULL);
+            free(wsbuf);
+#else
+            (GetModuleFileName)(NULL, sbuf, 250);
             sprintf(strchr(sbuf, '\0'), ".%d",
                     (GetCurrentProcessId)());
-            fh = (CreateFileA)(sbuf, GENERIC_WRITE, 0, NULL, 
+            fh = (CreateFile)(sbuf, GENERIC_WRITE, 0, NULL, 
                             CREATE_ALWAYS, 0, NULL);
+#endif
             (InitializeCriticalSection)(&cs);
         }
     }
Index: network_io/unix/multicast.c
===================================================================
--- network_io/unix/multicast.c (revision 584782)
+++ network_io/unix/multicast.c (working copy)
@@ -163,7 +163,11 @@
 
             if (setsockopt(sock->socketdes, IPPROTO_IP, type,
                            (const void *) &mip4, sizeof(mip4)) == -1) {
+#ifndef _WIN32_WCE
                 rv = errno;
+#else
+                rv = apr_get_netos_error();
+#endif
             }
         }
 #if APR_HAVE_IPV6 && defined(IPV6_JOIN_GROUP) && defined(IPV6_LEAVE_GROUP)
@@ -182,7 +186,11 @@
 
             if (setsockopt(sock->socketdes, IPPROTO_IPV6, type,
                            (const void *) &mip6, sizeof(mip6)) == -1) {
+#ifndef _WIN32_WCE
                 rv = errno;
+#else
+                rv = apr_get_netos_error();
+#endif
             }
         }
 #endif
@@ -201,7 +209,11 @@
     if (sock_is_ipv4(sock)) {
         if (setsockopt(sock->socketdes, IPPROTO_IP, type,
                        (const void *) &value, sizeof(value)) == -1) {
+#ifndef _WIN32_WCE
             rv = errno;
+#else
+            rv = apr_get_netos_error();
+#endif
         }
     }
 #if APR_HAVE_IPV6
@@ -210,7 +222,11 @@
         type = IPV6_MULTICAST_LOOP;
         if (setsockopt(sock->socketdes, IPPROTO_IPV6, type,
                        (const void *) &loopopt, sizeof(loopopt)) == -1) {
+#ifndef _WIN32_WCE
             rv = errno;
+#else
+            rv = apr_get_netos_error();
+#endif
         }
     }
     else if (sock_is_ipv6(sock)) {
@@ -223,7 +239,11 @@
 
         if (setsockopt(sock->socketdes, IPPROTO_IPV6, type,
                        &value, sizeof(value)) == -1) {
+#ifndef _WIN32_WCE
             rv = errno;
+#else
+            rv = apr_get_netos_error();
+#endif
         }
     }
 #endif
@@ -288,7 +308,11 @@
         if (setsockopt(sock->socketdes, IPPROTO_IP, IP_MULTICAST_IF,
                        (const void *) &iface->sa.sin.sin_addr,
                        sizeof(iface->sa.sin.sin_addr)) == -1) {
+#ifndef _WIN32_WCE
             rv = errno;
+#else
+            rv = apr_get_netos_error();
+#endif
         }
     }
 #if APR_HAVE_IPV6
@@ -296,7 +320,11 @@
         unsigned int idx = find_if_index(iface);
         if (setsockopt(sock->socketdes, IPPROTO_IPV6, IPV6_MULTICAST_IF,
                        (const void *) &idx, sizeof(idx)) == -1) {
+#ifndef _WIN32_WCE
             rv = errno;
+#else
+            rv = apr_get_netos_error();
+#endif
         }
     }
 #endif
Index: network_io/unix/sockaddr.c
===================================================================
--- network_io/unix/sockaddr.c  (revision 584782)
+++ network_io/unix/sockaddr.c  (working copy)
@@ -58,7 +58,7 @@
 #define GETHOSTBYNAME_BUFLEN 512
 #endif
 
-#ifdef _WIN32_WCE
+#if _WIN32_WCE < 0x500
 /* XXX: BS solution.  Need an HAVE_GETSERVBYNAME and actually
  * do something here, to provide the obvious proto mappings.
  */
@@ -716,7 +716,11 @@
         sockaddr->sa.sin.sin_port = se->s_port;
         return APR_SUCCESS;
     }
+#ifndef _WIN32_WCE
     return errno;
+#else
+    return apr_get_netos_error();
+#endif
 }
 
 #define V4MAPPED_EQUAL(a,b)                                   \
Index: network_io/win32/sockets.c
===================================================================
--- network_io/win32/sockets.c  (revision 584782)
+++ network_io/win32/sockets.c  (working copy)
@@ -42,6 +42,12 @@
         thesocket->overlapped = NULL;
     }
 #endif
+#if _WIN32_WCE >= 0x400
+    if (thesocket->wsaoverlapped) {
+        WSACloseEvent(thesocket->wsaoverlapped->hEvent);
+        thesocket->wsaoverlapped = NULL;
+    }
+#endif
     return APR_SUCCESS;
 }
 
@@ -92,11 +98,23 @@
     }
 
     alloc_socket(new, cont);
+#if _WIN32_WCE >= 0x400
+    (*new)->wsaoverlapped = (WSAOVERLAPPED *)apr_pcalloc((*new)->pool,
+                                                         
sizeof(WSAOVERLAPPED));
+    (*new)->wsaoverlapped->hEvent = WSACreateEvent();
+    if ((*new)->wsaoverlapped->hEvent == NULL) {
+        return apr_get_netos_error();
+    }
 
+    /* Need to use overlapped sockets to support blocking with timeout. */
+    (*new)->socketdes = WSASocket(family, type, protocol, NULL,
+                                  0, WSA_FLAG_OVERLAPPED);
+#else
     /* For right now, we are not using socket groups.  We may later.
      * No flags to use when creating a socket, so use 0 for that parameter as 
well.
      */
     (*new)->socketdes = socket(family, type, protocol);
+#endif
 #if APR_HAVE_IPV6
     if ((*new)->socketdes == INVALID_SOCKET && downgrade) {
         family = AF_INET;
@@ -234,12 +252,24 @@
 
     /* Don't allocate the memory until after we call accept. This allows
        us to work with nonblocking sockets. */
+#if _WIN32_WCE >= 0x400
+    s = WSAAccept(sock->socketdes, (struct sockaddr *)&sa, &salen, NULL, 0);
+#else
     s = accept(sock->socketdes, (struct sockaddr *)&sa, &salen);
+#endif
     if (s == INVALID_SOCKET) {
         return apr_get_netos_error();
     }
 
     alloc_socket(new, p);
+#if _WIN32_WCE >= 0x400
+    (*new)->wsaoverlapped = (WSAOVERLAPPED *)apr_pcalloc((*new)->pool,
+                                                         
sizeof(WSAOVERLAPPED));
+    (*new)->wsaoverlapped->hEvent = WSACreateEvent();
+    if ((*new)->wsaoverlapped->hEvent == NULL) {
+        return apr_get_netos_error();
+    }
+#endif
     set_socket_vars(*new, sock->local_addr->sa.sin.sin_family, SOCK_STREAM, 
                     sock->protocol);
 
@@ -310,9 +340,13 @@
     if ((sock->socketdes == INVALID_SOCKET) || (!sock->local_addr)) {
         return APR_ENOTSOCK;
     }
-
+#if _WIN32_WCE >= 0x400
+    if (WSAConnect(sock->socketdes, (const struct sockaddr *)&sa->sa.sin,
+                   sa->salen, NULL, NULL, NULL, NULL) == SOCKET_ERROR) {
+#else
     if (connect(sock->socketdes, (const struct sockaddr *)&sa->sa.sin,
                 sa->salen) == SOCKET_ERROR) {
+#endif
         int rc;
         struct timeval tv, *tvptr;
         fd_set wfdset, efdset;
Index: threadproc/win32/proc.c
===================================================================
--- threadproc/win32/proc.c     (revision 584782)
+++ threadproc/win32/proc.c     (working copy)
@@ -634,9 +634,12 @@
              * complete file path.  That is; "c:\bin\aprtest.exe"
              * would succeed, but "c:\bin\aprtest" or "aprtest.exe"
              * can fail.
+             * Apparently, CE 5 already passes the program name as the first
+             * argument.
              */
-            cmdline = apr_pstrcat(pool, argv0, cmdline, NULL);
-
+            if (apr_os_level < APR_WIN_CE_5) {
+                cmdline = apr_pstrcat(pool, argv0, cmdline, NULL);
+            }
             if (attr->cmdtype == APR_PROGRAM_PATH) {
                 progname = NULL;
             }
@@ -668,7 +671,8 @@
         {
             apr_wchar_t *pNext;
             pEnvBlock = (char *)apr_palloc(pool, iEnvBlockLen * 2);
-            dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT;
+            if (apr_os_level >= APR_WIN_NT)
+                dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT;
 
             i = 0;
             pNext = (apr_wchar_t*)pEnvBlock;

Reply via email to