The attached patch contains the changes I've made to get libapr-1 to compile
for Windows CE 5. I've had some problems sending the project files, so if
anyone wants those, let me know and I'll send them directly.
The changes aren't complete solutions in all cases. Some are probably
reasonable, but others simply comment out code to compile.
Ioan
Index: dso/win32/dso.c
===================================================================
--- dso/win32/dso.c (revision 550807)
+++ dso/win32/dso.c (working copy)
@@ -141,7 +141,7 @@
apr_wchar_t wsymname[256];
apr_status_t rv;
- rv = apr_conv_utf8_to_ucs2(wsymname, &wsymlen, symname, &symlen);
+ rv = apr_conv_utf8_to_ucs2(symname, &symlen, wsymname, &wsymlen);
if (rv != APR_SUCCESS) {
return rv;
}
Index: file_io/win32/filestat.c
===================================================================
--- file_io/win32/filestat.c (revision 550807)
+++ file_io/win32/filestat.c (working copy)
@@ -15,15 +15,19 @@
*/
#include "apr.h"
+#include "apr_private.h"
+#if HAVE_ACLAPI
#include <aclapi.h>
-#include "apr_private.h"
+#endif
#include "apr_arch_file_io.h"
#include "apr_file_io.h"
#include "apr_general.h"
#include "apr_strings.h"
#include "apr_errno.h"
#include "apr_time.h"
+#if APR_HAVE_SYS_TYPES_H
#include <sys/stat.h>
+#endif
#include "apr_arch_atime.h"
#include "apr_arch_misc.h"
@@ -57,6 +61,7 @@
static apr_gid_t worldid = NULL;
+#ifndef _WIN32_WCE
static void free_world(void)
{
if (worldid) {
@@ -64,6 +69,7 @@
worldid = NULL;
}
}
+#endif
/* Left bit shifts from World scope to given scope */
typedef enum prot_scope_e {
@@ -90,6 +96,7 @@
static void resolve_prot(apr_finfo_t *finfo, apr_int32_t wanted, PACL dacl)
{
+#if HAVE_ACLAPI
TRUSTEE_W ident = {NULL, NO_MULTIPLE_TRUSTEE, TRUSTEE_IS_SID};
ACCESS_MASK acc;
/*
@@ -137,6 +144,7 @@
finfo->valid |= APR_FINFO_WPROT;
}
}
+#endif
}
static apr_status_t resolve_ident(apr_finfo_t *finfo, const char *fname,
@@ -212,7 +220,7 @@
{
PSID user = NULL, grp = NULL;
PACL dacl = NULL;
- apr_status_t rv;
+ apr_status_t rv = ERROR_SUCCESS;
if (apr_os_level < APR_WIN_NT)
guess_protection_bits(finfo);
@@ -233,6 +241,7 @@
if (wanted & APR_FINFO_PROT)
sinf |= DACL_SECURITY_INFORMATION;
if (whatfile == MORE_OF_WFSPEC) {
+#ifndef _WIN32_WCE
apr_wchar_t *wfile = (apr_wchar_t*) ufile;
int fix = 0;
if (wcsncmp(wfile, L"\\\\?\\", 4) == 0) {
@@ -263,8 +272,10 @@
((wanted & (APR_FINFO_GROUP |
APR_FINFO_GPROT)) ? &grp : NULL),
((wanted & APR_FINFO_PROT) ? &dacl : NULL),
NULL, &pdesc);
- else
+ else {
+#endif
return APR_INCOMPLETE;
+ }
if (rv == ERROR_SUCCESS)
apr_pool_cleanup_register(finfo->pool, pdesc, free_localheap,
apr_pool_cleanup_null);
@@ -387,6 +398,7 @@
fillin_fileinfo(finfo, (WIN32_FILE_ATTRIBUTE_DATA *) &FileInfo, 1, wanted);
+#ifndef _WIN32_WCE
if (finfo->filetype == APR_REG)
{
/* Go the extra mile to be -certain- that we have a real, regular
@@ -406,6 +418,7 @@
*/
}
}
+#endif
finfo->pool = thefile->pool;
@@ -579,6 +592,7 @@
if (fillin_fileinfo(finfo, (WIN32_FILE_ATTRIBUTE_DATA *) &FileInfo,
0, wanted))
{
+#ifndef _WIN32_WCE
/* Go the extra mile to assure we have a file. WinNT/2000 seems
* to reliably translate char devices to the path '\\.\device'
* so go ask for the full path.
@@ -634,6 +648,7 @@
else {
finfo->valid &= ~APR_FINFO_TYPE;
}
+#endif
}
finfo->pool = pool;
}
Index: file_io/win32/filesys.c
===================================================================
--- file_io/win32/filesys.c (revision 550807)
+++ file_io/win32/filesys.c (working copy)
@@ -65,6 +65,7 @@
apr_status_t filepath_root_test(char *path, apr_pool_t *p)
{
+#ifndef _WIN32_WCE
apr_status_t rv;
#if APR_HAS_UNICODE_FS
if (apr_os_level >= APR_WIN_NT)
@@ -82,12 +83,16 @@
if (rv == DRIVE_UNKNOWN || rv == DRIVE_NO_ROOT_DIR)
return APR_EBADPATH;
return APR_SUCCESS;
+#else
+ return APR_ENOTIMPL;
+#endif
}
apr_status_t filepath_drive_get(char **rootpath, char drive,
apr_int32_t flags, apr_pool_t *p)
{
+#ifndef _WIN32_WCE
char path[APR_PATH_MAX];
#if APR_HAS_UNICODE_FS
IF_WIN_OS_IS_UNICODE
@@ -128,11 +133,15 @@
}
*rootpath = apr_pstrdup(p, path);
return APR_SUCCESS;
+#else
+ return APR_ENOTIMPL;
+#endif
}
apr_status_t filepath_root_case(char **rootpath, char *root, apr_pool_t *p)
{
+#ifndef _WIN32_WCE
#if APR_HAS_UNICODE_FS
IF_WIN_OS_IS_UNICODE
{
@@ -167,12 +176,16 @@
}
#endif
return APR_SUCCESS;
+#else
+ return APR_ENOTIMPL;
+#endif
}
APR_DECLARE(apr_status_t) apr_filepath_get(char **rootpath, apr_int32_t flags,
apr_pool_t *p)
{
+#ifndef _WIN32_WCE
char path[APR_PATH_MAX];
#if APR_HAS_UNICODE_FS
IF_WIN_OS_IS_UNICODE
@@ -200,12 +213,16 @@
}
*rootpath = apr_pstrdup(p, path);
return APR_SUCCESS;
+#else
+ return APR_ENOTIMPL;
+#endif
}
APR_DECLARE(apr_status_t) apr_filepath_set(const char *rootpath,
apr_pool_t *p)
{
+#ifndef _WIN32_WCE
#if APR_HAS_UNICODE_FS
IF_WIN_OS_IS_UNICODE
{
@@ -226,4 +243,7 @@
}
#endif
return APR_SUCCESS;
+#else
+ return APR_ENOTIMPL;
+#endif
}
Index: file_io/win32/open.c
===================================================================
--- file_io/win32/open.c (revision 550807)
+++ file_io/win32/open.c (working copy)
@@ -227,6 +227,7 @@
if (file->filehand != INVALID_HANDLE_VALUE) {
+#ifndef _WIN32_WCE
/* In order to avoid later segfaults with handle 'reuse',
* we must protect against the case that a dup2'ed handle
* is being closed, and invalidate the corresponding StdHandle
@@ -240,6 +241,7 @@
if (file->filehand == GetStdHandle(STD_INPUT_HANDLE)) {
SetStdHandle(STD_INPUT_HANDLE, INVALID_HANDLE_VALUE);
}
+#endif
if (file->buffered) {
/* XXX: flush here is not mutex protected */
Index: file_io/win32/readwrite.c
===================================================================
--- file_io/win32/readwrite.c (revision 550807)
+++ file_io/win32/readwrite.c (working copy)
@@ -41,6 +41,7 @@
*/
if (file->pipe) {
DWORD bytes;
+#ifndef _WIN32_WCE
if (!PeekNamedPipe(file->filehand, NULL, 0, NULL, &bytes, NULL)) {
rv = apr_get_os_error();
if (rv == APR_FROM_OS_ERROR(ERROR_BROKEN_PIPE)) {
@@ -58,6 +59,25 @@
len = bytes;
}
}
+#else
+ if (!ReadFile(file->filehand, NULL, 0, &bytes, NULL)) {
+ rv = apr_get_os_error();
+ if (rv == APR_FROM_OS_ERROR(ERROR_BROKEN_PIPE)) {
+ rv = APR_EOF;
+ }
+ *nbytes = 0;
+ return rv;
+ }
+ else {
+ if (bytes == 0) {
+ *nbytes = 0;
+ return APR_EAGAIN;
+ }
+ if (len > bytes) {
+ len = bytes;
+ }
+ }
+#endif
}
else {
/* ToDo: Handle zero timeout non-blocking file i/o
@@ -90,9 +110,11 @@
}
switch (rv) {
case WAIT_OBJECT_0:
+#ifndef _WIN32_WCE
GetOverlappedResult(file->filehand, file->pOverlapped,
&bytesread, TRUE);
*nbytes = bytesread;
+#endif
rv = APR_SUCCESS;
break;
@@ -108,11 +130,13 @@
break;
}
+#ifndef _WIN32_WCE
if (rv != APR_SUCCESS) {
if (apr_os_level >= APR_WIN_98) {
CancelIo(file->filehand);
}
}
+#endif
}
else if (rv == APR_FROM_OS_ERROR(ERROR_BROKEN_PIPE)) {
/* Assume ERROR_BROKEN_PIPE signals an EOF reading from a pipe */
@@ -339,9 +363,11 @@
rv = WaitForSingleObject(thefile->pOverlapped->hEvent,
timeout_ms);
switch (rv) {
case WAIT_OBJECT_0:
+#ifndef _WIN32_WCE
GetOverlappedResult(thefile->filehand,
thefile->pOverlapped,
&bwrote, TRUE);
*nbytes = bwrote;
+#endif
rv = APR_SUCCESS;
break;
case WAIT_TIMEOUT:
@@ -353,10 +379,12 @@
default:
break;
}
+#ifndef _WIN32_WCE
if (rv != APR_SUCCESS) {
if (apr_os_level >= APR_WIN_98)
CancelIo(thefile->filehand);
}
+#endif
}
}
if (rv == APR_SUCCESS && thefile->pOverlapped && !thefile->pipe) {
Index: file_io/win32/seek.c
===================================================================
--- file_io/win32/seek.c (revision 550807)
+++ file_io/win32/seek.c (working copy)
@@ -16,7 +16,9 @@
#include "win32/apr_arch_file_io.h"
#include "apr_file_io.h"
-#include <errno.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 )
Index: include/apr.hw
===================================================================
--- include/apr.hw (revision 550807)
+++ include/apr.hw (working copy)
@@ -296,13 +296,14 @@
#define APR_HAS_USER 1
#define APR_HAS_LARGE_FILES 1
#define APR_HAS_XTHREAD_FILES 1
+#define APR_HAS_OS_UUID 1
#else
#define APR_HAS_SENDFILE 0
#define APR_HAS_USER 0
#define APR_HAS_LARGE_FILES 0
#define APR_HAS_XTHREAD_FILES 0
+#define APR_HAS_OS_UUID 0
#endif
-#define APR_HAS_OS_UUID 1
/* Win32 cannot poll [just yet] on files/pipes.
*/
Index: include/arch/win32/apr_arch_file_io.h
===================================================================
--- include/arch/win32/apr_arch_file_io.h (revision 550807)
+++ include/arch/win32/apr_arch_file_io.h (working copy)
@@ -273,4 +273,8 @@
/** @see apr_create_nt_pipe */
#define APR_WRITE_BLOCK 4
+#ifdef _WIN32_WCE
+#define BUFSIZ 512
+#endif
+
#endif /* ! FILE_IO_H */
Index: include/arch/win32/apr_arch_misc.h
===================================================================
--- include/arch/win32/apr_arch_misc.h (revision 550807)
+++ include/arch/win32/apr_arch_misc.h (working copy)
@@ -85,9 +85,11 @@
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 */
+ /* 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,
Index: misc/win32/apr_app.c
===================================================================
--- misc/win32/apr_app.c (revision 550807)
+++ misc/win32/apr_app.c (working copy)
@@ -35,7 +35,9 @@
#include "apr_general.h"
#include "ShellAPI.h"
+#ifndef _WIN32_WCE
#include "crtdbg.h"
+#endif
#include "wchar.h"
#include "apr_arch_file_io.h"
#include "assert.h"
@@ -47,6 +49,7 @@
extern int main(int argc, const char **argv, const char **env);
+#ifndef _WIN32_WCE
int wmain(int argc, const wchar_t **wargv, const wchar_t **wenv)
{
char **argv;
@@ -78,3 +81,4 @@
return main(argc, argv, env);
}
+#endif
Index: misc/win32/internal.c
===================================================================
--- misc/win32/internal.c (revision 550807)
+++ misc/win32/internal.c (working copy)
@@ -18,7 +18,9 @@
#include "apr_arch_misc.h"
#include "apr_arch_file_io.h"
+#ifndef _WIN32_WCE
#include <crtdbg.h>
+#endif
#include <assert.h>
/* This module is the source of -static- helper functions that are
@@ -30,6 +32,7 @@
*/
+#ifndef _WIN32_WCE
/* Shared by apr_app.c and start.c
*
* An internal apr function to convert an array of strings (either
@@ -100,3 +103,4 @@
*retarr = newarr;
return args;
}
+#endif
Index: misc/win32/misc.c
===================================================================
--- misc/win32/misc.c (revision 550807)
+++ misc/win32/misc.c (working copy)
@@ -16,7 +16,9 @@
#include "apr_private.h"
#include "apr_arch_misc.h"
+#ifndef _WIN32_WCE
#include "crtdbg.h"
+#endif
#include "apr_arch_file_io.h"
#include "assert.h"
#include "apr_lib.h"
@@ -31,6 +33,7 @@
oslev.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&oslev);
+#ifndef _WIN32_WCE
if (oslev.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
static unsigned int servpack = 0;
@@ -98,7 +101,6 @@
}
#ifndef WINNT
else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
- char *prevision;
if (prevision = oslev.szCSDVersion) {
while (*prevision && !apr_isupper(*prevision)) {
prevision++;
@@ -123,15 +125,21 @@
}
}
#endif
-#ifdef _WIN32_WCE
- else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_CE)
+#else
+ if (oslev.dwPlatformId == VER_PLATFORM_WIN32_CE)
{
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 {
+ apr_os_level = APR_WIN_CE_5;
+ }
}
#endif
else {
@@ -160,7 +168,40 @@
FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char* fnName, int ordinal)
{
- if (!lateDllHandle[fnLib]) {
+#if APR_HAS_UNICODE_FS
+ apr_wchar_t wLateDllName[DLL_defined];
+ apr_size_t inbytes = sizeof(lateDllName[fnLib]), outwords = DLL_defined;
+
+ if (!lateDllHandle[fnLib]) {
+ if (apr_conv_utf8_to_ucs2(lateDllName[fnLib], &inbytes, wLateDllName,
+ &outwords) == APR_SUCCESS) {
+ lateDllHandle[fnLib] = LoadLibraryW(wLateDllName);
+ }
+ else {
+ return NULL;
+ }
+ if (!lateDllHandle[fnLib])
+ return NULL;
+ }
+ if (ordinal)
+ {
+ apr_wchar_t wOrdinal;
+ ((char *)&wOrdinal)[0] = *(char *)ordinal;
+ ((char *)&wOrdinal)[1] = 0;
+ return GetProcAddressW(lateDllHandle[fnLib], &wOrdinal);
+ }
+ else
+ {
+ inbytes = strlen(fnName);
+ outwords = DLL_defined;
+ if (apr_conv_utf8_to_ucs2(fnName, &inbytes, wLateDllName, &outwords)
+ != APR_SUCCESS) {
+ return NULL;
+ }
+ return GetProcAddressW(lateDllHandle[fnLib], wLateDllName);
+ }
+#elif APR_HAS_ANSI_FS
+ if (!lateDllHandle[fnLib]) {
lateDllHandle[fnLib] = LoadLibrary(lateDllName[fnLib]);
if (!lateDllHandle[fnLib])
return NULL;
@@ -169,6 +210,7 @@
return GetProcAddress(lateDllHandle[fnLib], (char *) ordinal);
else
return GetProcAddress(lateDllHandle[fnLib], fnName);
+#endif
}
/* Declared in include/arch/win32/apr_dbg_win32_handles.h
@@ -196,11 +238,23 @@
(TlsSetValue)(tlsid, sbuf);
sbuf[1023] = '\0';
if (!fh) {
+#if APR_HAS_UNICODE_FS
+ apr_status_t rv;
+ apr_wchar_t wsbuf[1024];
+ apr_size_t inbytes = 1024, outwords = 1024;
+ rv = apr_conv_utf8_to_ucs2(sbuf, &inbytes, wsbuf, &outwords);
+ (GetModuleFileNameW)(NULL, wsbuf, 250);
+ wsprintf(wcschr(wsbuf, L'\0'), L".%d",
+ (GetCurrentProcessId)());
+ fh = (CreateFileW)(wsbuf, GENERIC_WRITE, 0, NULL,
+ CREATE_ALWAYS, 0, NULL);
+#elif APR_HAS_ANSI_FS
(GetModuleFileName)(NULL, sbuf, 250);
sprintf(strchr(sbuf, '\0'), ".%d",
(GetCurrentProcessId)());
fh = (CreateFile)(sbuf, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, 0, NULL);
+#endif
(InitializeCriticalSection)(&cs);
}
}
Index: misc/win32/rand.c
===================================================================
--- misc/win32/rand.c (revision 550807)
+++ misc/win32/rand.c (working copy)
@@ -52,6 +52,7 @@
APR_DECLARE(apr_status_t) apr_os_uuid_get(unsigned char *uuid_data)
{
+#if APR_HAS_OS_UUID
/* Note: this call doesn't actually require CoInitialize() first
*
* XXX: we should scramble the bytes or some such to eliminate the
@@ -66,4 +67,7 @@
return APR_EGENERAL;
}
return APR_SUCCESS;
+#else
+ return APR_ENOTIMPL;
+#endif
}
Index: misc/win32/start.c
===================================================================
--- misc/win32/start.c (revision 550807)
+++ misc/win32/start.c (working copy)
@@ -23,7 +23,9 @@
#include "apr_arch_misc.h" /* for WSAHighByte / WSALowByte */
#include "wchar.h"
#include "apr_arch_file_io.h"
+#ifndef _WIN32_WCE
#include "crtdbg.h"
+#endif
#include "assert.h"
/* This symbol is _private_, although it must be exported.
Index: strings/apr_strings.c
===================================================================
--- strings/apr_strings.c (revision 550807)
+++ strings/apr_strings.c (working copy)
@@ -280,7 +280,9 @@
base = c == '0' ? 8 : 10;
acc = any = 0;
if (base < 2 || base > 36) {
+#if APR_HAVE_ERRNO_H
errno = EINVAL;
+#endif
if (endptr != NULL)
*endptr = (char *)(any ? s - 1 : nptr);
return acc;
@@ -341,9 +343,13 @@
if (any < 0) {
acc = neg ? INT64_MIN : INT64_MAX;
+#if APR_HAVE_ERRNO_H
errno = ERANGE;
+#endif
} else if (!any) {
+#if APR_HAVE_ERRNO_H
errno = EINVAL;
+#endif
}
if (endptr != NULL)
*endptr = (char *)(any ? s - 1 : nptr);