summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordougt%meer.net <devnull@localhost>2005-04-20 23:26:15 +0000
committerdougt%meer.net <devnull@localhost>2005-04-20 23:26:15 +0000
commit9172dbeb070acecbc59d6ffb3c232ac5185b6098 (patch)
tree024a0a11008da571dade62b7f0e279943be0a59e
parenta7fb7794709daa192783b28b9e410ec19d6ead32 (diff)
downloadnspr-hg-9172dbeb070acecbc59d6ffb3c232ac5185b6098.tar.gz
Creating branch tag and allowing WINCE code to live there.
-rw-r--r--pr/include/md/_win32_time.h178
-rw-r--r--pr/include/md/_win32_unicode.h73
-rw-r--r--pr/include/md/_wince.cfg209
-rw-r--r--pr/include/md/_wince.h513
-rw-r--r--pr/src/md/windows/w32netdb.c109
-rw-r--r--pr/src/md/windows/w32unicode.c161
6 files changed, 1243 insertions, 0 deletions
diff --git a/pr/include/md/_win32_time.h b/pr/include/md/_win32_time.h
new file mode 100644
index 00000000..9288f1d0
--- /dev/null
+++ b/pr/include/md/_win32_time.h
@@ -0,0 +1,178 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ *
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation. Portions created by Netscape are
+ * Copyright (C) 1998-2000 Netscape Communications Corporation. All
+ * Rights Reserved.
+ *
+ * Contributor(s):
+ * Garrett Arch Blythe 01/25/2002
+ *
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable
+ * instead of those above. If you wish to allow use of your
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL. If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+#ifndef nspr_win32_time_h___
+#define nspr_win32_time_h___
+
+#include <windows.h>
+
+/*
+ * _win23_time.h
+ *
+ * This file mainly exists because when porting NSPR to WinCE there was
+ * a lack of LIBC support. Conversion between window's FILETIME and
+ * time_t was going to be a common operation; thus this file.
+ *
+ * I assume compiler support for int64.
+ */
+
+#if !defined(__GNUC__)
+#define _PR_I64_CONST(number) number ## i64
+#else
+#define _PR_I64_COSNT(number) number ## LL
+#endif
+
+/*
+ * FILETIME has an epoch of 1601.
+ * Precomputed the 1970 epoch so we do not have to below.
+ */
+#define _MD_FILETIME_1970 _PR_I64_CONST(116444736000000000)
+
+/*
+ * Marco to support add/sub/mul/div on a FILETIME level.
+ */
+#define _MD_FILETIME_ARITH(outFileTime, inFileTime, inOperation, inValue) \
+ PR_BEGIN_MACRO \
+ ULARGE_INTEGER _buffer1; \
+ \
+ _buffer1.LowPart = inFileTime.dwLowDateTime; \
+ _buffer1.HighPart = inFileTime.dwHighDateTime; \
+ _buffer1.QuadPart = _buffer1.QuadPart inOperation inValue; \
+ outFileTime.dwLowDateTime = _buffer1.LowPart; \
+ outFileTime.dwHighDateTime = _buffer1.HighPart; \
+ PR_END_MACRO
+
+/*
+ * FILETIME is in 100 nanosecond units.
+ * Provide macros for conversion to other second units.
+ */
+#define _MD_FILETIME_2_MICROSECONDS(outTime, inFileTime) \
+ PR_BEGIN_MACRO \
+ ULARGE_INTEGER _buffer2; \
+ \
+ _buffer2.LowPart = inFileTime.dwLowDateTime; \
+ _buffer2.HighPart = inFileTime.dwHighDateTime; \
+ outTime = _buffer2.QuadPart / _PR_I64_CONST(10); \
+ PR_END_MACRO
+#define _MD_FILETIME_2_MILLISECONDS(outTime, inFileTime) \
+ PR_BEGIN_MACRO \
+ ULARGE_INTEGER _buffer3; \
+ \
+ _buffer3.LowPart = inFileTime.dwLowDateTime; \
+ _buffer3.HighPart = inFileTime.dwHighDateTime; \
+ outTime = _buffer3.QuadPart / _PR_I64_CONST(10000); \
+ PR_END_MACRO
+#define _MD_FILETIME_2_SECONDS(outTime, inFileTime) \
+ PR_BEGIN_MACRO \
+ ULARGE_INTEGER _buffer4; \
+ \
+ _buffer4.LowPart = inFileTime.dwLowDateTime; \
+ _buffer4.HighPart = inFileTime.dwHighDateTime; \
+ outTime = _buffer4.QuadPart / _PR_I64_CONST(10000000); \
+ PR_END_MACRO
+#define _MD_SECONDS_2_FILETIME(outFileTime, inTime) \
+ PR_BEGIN_MACRO \
+ ULARGE_INTEGER _buffer5; \
+ \
+ _buffer5.QuadPart = (ULONGLONG)inTime * _PR_I64_CONST(10000000); \
+ outFileTime.dwLowDateTime = _buffer5.LowPart; \
+ outFileTime.dwHighDateTime = _buffer5.HighPart; \
+ PR_END_MACRO
+
+/*
+ * Conversions from FILETIME 1601 epoch time to LIBC/NSPR 1970 time.epoch.
+ */
+#define _MD_FILETIME_2_PRTime(outPRTime, inFileTime) \
+ PR_BEGIN_MACRO \
+ FILETIME _result1; \
+ ULONGLONG _conversion1; \
+ \
+ _MD_FILETIME_ARITH(_result1, inFileTime, -, _MD_FILETIME_1970); \
+ _MD_FILETIME_2_MICROSECONDS(_conversion1, _result1); \
+ outPRTime = (PRTime)_conversion1; \
+ PR_END_MACRO
+#define _MD_FILETIME_2_time_t(outTimeT, inFileTime) \
+ PR_BEGIN_MACRO \
+ FILETIME _result2; \
+ ULONGLONG _conversion2; \
+ \
+ _MD_FILETIME_ARITH(_result2, inFileTime, -, _MD_FILETIME_1970); \
+ _MD_FILETIME_2_SECONDS(_conversion2, _result2); \
+ outTimeT = (time_t)_conversion2; \
+ PR_END_MACRO
+#define _MD_time_t_2_FILETIME(outFileTime, inTimeT) \
+ PR_BEGIN_MACRO \
+ FILETIME _conversion3; \
+ \
+ _MD_SECONDS_2_FILETIME(_conversion3, inTimeT); \
+ _MD_FILETIME_ARITH(outFileTime, _conversion3, +, _MD_FILETIME_1970); \
+ PR_END_MACRO
+
+
+/*
+ * Sometimes SYSTEMTIME needs to be handled as well.
+ */
+#define _MD_SYSTEMTIME_2_PRTime(outPRTime, inSystemTime) \
+ PR_BEGIN_MACRO \
+ FILETIME _result3; \
+ \
+ SystemTimeToFileTime(&inSystemTime, &_result3); \
+ _MD_FILETIME_2_PRTime(outPRTime, _result3); \
+ PR_END_MACRO
+#define _MD_SYSTEMTIME_2_time_t(outTimeT, inSystemTime) \
+ PR_BEGIN_MACRO \
+ FILETIME _result4; \
+ \
+ SystemTimeToFileTime(&inSystemTime, &_result4); \
+ _MD_FILETIME_2_time_t(outTimeT, _result4); \
+ PR_END_MACRO
+#define _MD_time_t_2_SYSTEMTIME(outSystemTime, inTimeT) \
+ PR_BEGIN_MACRO \
+ FILETIME _conversion4; \
+ \
+ _MD_time_t_2_FILETIME(_conversion4, inTimeT); \
+ FileTimeToSystemTime(&_conversion4, &outSystemTime); \
+ PR_END_MACRO
+#define _MD_time_t_2_LOCALSYSTEMTIME(outSystemTime, inTimeT) \
+ PR_BEGIN_MACRO \
+ FILETIME _conversion5; \
+ FILETIME localConversion; \
+ \
+ _MD_time_t_2_FILETIME(_conversion5, inTimeT); \
+ FileTimeToLocalFileTime(&_conversion5, &localConversion); \
+ FileTimeToSystemTime(&localConversion, &outSystemTime); \
+ PR_END_MACRO
+
+#endif /* nspr_win32_time_h___ */
diff --git a/pr/include/md/_win32_unicode.h b/pr/include/md/_win32_unicode.h
new file mode 100644
index 00000000..6a0aca9a
--- /dev/null
+++ b/pr/include/md/_win32_unicode.h
@@ -0,0 +1,73 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ *
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation. Portions created by Netscape are
+ * Copyright (C) 1998-2000 Netscape Communications Corporation. All
+ * Rights Reserved.
+ *
+ * Contributor(s):
+ * Garrett Arch Blythe 02/05/2002
+ *
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable
+ * instead of those above. If you wish to allow use of your
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL. If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+#ifndef nspr_win32_unicode_h___
+#define nspr_win32_unicode_h___
+
+#include <windows.h>
+
+/*
+ * _PR_MD_MALLOC_A2W
+ *
+ * Automatically PR_Malloc a wide char string and return it based on the
+ * ANSI (multi byte, ansi code page) string passed in.
+ *
+ * Caller must PR_Free the return value if non-NULL.
+ */
+LPWSTR _PR_MD_MALLOC_A2W(LPCSTR inString);
+
+/*
+ * _PR_MD_A2W
+ *
+ * Non-mallocing/faster version to return a wide char string based on the
+ * ANSI (multi byte, ansi code page) string passed in.
+ *
+ * NOTE: inWideStringChars is number of wide characters in outWideString,
+ * NOT the number of bytes....
+ */
+LPWSTR _PR_MD_A2W(LPCSTR inString, LPWSTR outWideString, int inWideStringChars);
+
+/*
+ * _PR_MD_W2A
+ *
+ * Non-mallocing fucntion to return a ANSI (multi byte, ansi code page)
+ * string based on the wide char string passed in.
+ *
+ * NOTE: inWideStringChars is number of wide characters in outWideString,
+ * NOT the number of bytes....
+ */
+LPSTR _PR_MD_W2A(LPCWSTR inWideString, LPSTR outString, int inStringChars);
+
+#endif /* nspr_win32_unicode_h___ */
diff --git a/pr/include/md/_wince.cfg b/pr/include/md/_wince.cfg
new file mode 100644
index 00000000..5249ad84
--- /dev/null
+++ b/pr/include/md/_wince.cfg
@@ -0,0 +1,209 @@
+ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+ /*
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ *
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation. Portions created by Netscape are
+ * Copyright (C) 1998-2000 Netscape Communications Corporation. All
+ * Rights Reserved.
+ *
+ * Contributor(s):
+ * Garrett Arch Blythe 01/15/2002
+ *
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable
+ * instead of those above. If you wish to allow use of your
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL. If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+ #ifndef nspr_cpucfg___
+ #define nspr_cpucfg___
+
+ #ifndef XP_PC
+ #define XP_PC
+ #endif
+
+ #ifndef WIN32
+ #define WIN32
+ #endif
+
+ #ifndef WINCE
+ #define WINCE
+ #endif
+
+ /*
+ * Some needed types herein.
+ */
+ #include <windows.h>
+ #include <winnt.h>
+ #include <stdlib.h>
+
+ #define PR_AF_INET6 (100) /* IPv6 not supported yet, use standard value. */
+
+ #if defined(_M_IX86) || defined(_X86_)
+
+ #define IS_LITTLE_ENDIAN 1
+ #undef IS_BIG_ENDIAN
+
+ #define PR_BYTES_PER_BYTE 1
+ #define PR_BYTES_PER_SHORT 2
+ #define PR_BYTES_PER_INT 4
+ #define PR_BYTES_PER_INT64 8
+ #define PR_BYTES_PER_LONG 4
+ #define PR_BYTES_PER_FLOAT 4
+ #define PR_BYTES_PER_WORD 4
+ #define PR_BYTES_PER_DWORD 8
+ #define PR_BYTES_PER_DOUBLE 8
+
+ #define PR_BITS_PER_BYTE 8
+ #define PR_BITS_PER_SHORT 16
+ #define PR_BITS_PER_INT 32
+ #define PR_BITS_PER_INT64 64
+ #define PR_BITS_PER_LONG 32
+ #define PR_BITS_PER_FLOAT 32
+ #define PR_BITS_PER_WORD 32
+ #define PR_BITS_PER_DWORD 64
+ #define PR_BITS_PER_DOUBLE 64
+
+ #define PR_BITS_PER_BYTE_LOG2 3
+ #define PR_BITS_PER_SHORT_LOG2 4
+ #define PR_BITS_PER_INT_LOG2 5
+ #define PR_BITS_PER_INT64_LOG2 6
+ #define PR_BITS_PER_LONG_LOG2 5
+ #define PR_BITS_PER_FLOAT_LOG2 5
+ #define PR_BITS_PER_WORD_LOG2 5
+ #define PR_BITS_PER_DWORD_LOG2 6
+ #define PR_BITS_PER_DOUBLE_LOG2 6
+
+ #define PR_ALIGN_OF_SHORT 2
+ #define PR_ALIGN_OF_INT 4
+ #define PR_ALIGN_OF_LONG 4
+ #define PR_ALIGN_OF_INT64 8
+ #define PR_ALIGN_OF_FLOAT 4
+ #define PR_ALIGN_OF_WORD 4
+ #define PR_ALIGN_OF_DWORD 8
+ #define PR_ALIGN_OF_DOUBLE 4
+ #define PR_ALIGN_OF_POINTER 4
+
+ #define PR_BYTES_PER_WORD_LOG2 2
+ #define PR_BYTES_PER_DWORD_LOG2 2
+
+ #elif defined(_ARM_)
+
+ #define IS_LITTLE_ENDIAN 1
+ #undef IS_BIG_ENDIAN
+
+ #define PR_BYTES_PER_BYTE 1
+ #define PR_BYTES_PER_SHORT 2
+ #define PR_BYTES_PER_INT 4
+ #define PR_BYTES_PER_INT64 8
+ #define PR_BYTES_PER_LONG 4
+ #define PR_BYTES_PER_FLOAT 4
+ #define PR_BYTES_PER_WORD 4
+ #define PR_BYTES_PER_DWORD 8
+ #define PR_BYTES_PER_DOUBLE 8
+
+ #define PR_BITS_PER_BYTE 8
+ #define PR_BITS_PER_SHORT 16
+ #define PR_BITS_PER_INT 32
+ #define PR_BITS_PER_INT64 64
+ #define PR_BITS_PER_LONG 32
+ #define PR_BITS_PER_FLOAT 32
+ #define PR_BITS_PER_WORD 32
+ #define PR_BITS_PER_DWORD 64
+ #define PR_BITS_PER_DOUBLE 64
+
+ #define PR_BITS_PER_BYTE_LOG2 3
+ #define PR_BITS_PER_SHORT_LOG2 4
+ #define PR_BITS_PER_INT_LOG2 5
+ #define PR_BITS_PER_INT64_LOG2 6
+ #define PR_BITS_PER_LONG_LOG2 5
+ #define PR_BITS_PER_FLOAT_LOG2 5
+ #define PR_BITS_PER_WORD_LOG2 5
+ #define PR_BITS_PER_DWORD_LOG2 6
+ #define PR_BITS_PER_DOUBLE_LOG2 6
+
+ #define PR_ALIGN_OF_SHORT 2
+ #define PR_ALIGN_OF_INT 4
+ #define PR_ALIGN_OF_LONG 4
+ #define PR_ALIGN_OF_INT64 8
+ #define PR_ALIGN_OF_FLOAT 4
+ #define PR_ALIGN_OF_WORD 4
+ #define PR_ALIGN_OF_DWORD 8
+ #define PR_ALIGN_OF_DOUBLE 4
+ #define PR_ALIGN_OF_POINTER 4
+
+ #define PR_BYTES_PER_WORD_LOG2 2
+ #define PR_BYTES_PER_DWORD_LOG2 2
+
+ #else /* defined(_M_IX86) || defined(_X86_) */
+
+ #error unknown processor architecture
+
+ #endif /* defined(_M_IX86) || defined(_X86_) */
+
+ #define HAVE_LONG_LONG
+
+ #ifndef NO_NSPR_10_SUPPORT
+
+ #define BYTES_PER_BYTE PR_BYTES_PER_BYTE
+ #define BYTES_PER_SHORT PR_BYTES_PER_SHORT
+ #define BYTES_PER_INT PR_BYTES_PER_INT
+ #define BYTES_PER_INT64 PR_BYTES_PER_INT64
+ #define BYTES_PER_LONG PR_BYTES_PER_LONG
+ #define BYTES_PER_FLOAT PR_BYTES_PER_FLOAT
+ #define BYTES_PER_DOUBLE PR_BYTES_PER_DOUBLE
+ #define BYTES_PER_WORD PR_BYTES_PER_WORD
+ #define BYTES_PER_DWORD PR_BYTES_PER_DWORD
+
+ #define BITS_PER_BYTE PR_BITS_PER_BYTE
+ #define BITS_PER_SHORT PR_BITS_PER_SHORT
+ #define BITS_PER_INT PR_BITS_PER_INT
+ #define BITS_PER_INT64 PR_BITS_PER_INT64
+ #define BITS_PER_LONG PR_BITS_PER_LONG
+ #define BITS_PER_FLOAT PR_BITS_PER_FLOAT
+ #define BITS_PER_DOUBLE PR_BITS_PER_DOUBLE
+ #define BITS_PER_WORD PR_BITS_PER_WORD
+
+ #define BITS_PER_BYTE_LOG2 PR_BITS_PER_BYTE_LOG2
+ #define BITS_PER_SHORT_LOG2 PR_BITS_PER_SHORT_LOG2
+ #define BITS_PER_INT_LOG2 PR_BITS_PER_INT_LOG2
+ #define BITS_PER_INT64_LOG2 PR_BITS_PER_INT64_LOG2
+ #define BITS_PER_LONG_LOG2 PR_BITS_PER_LONG_LOG2
+ #define BITS_PER_FLOAT_LOG2 PR_BITS_PER_FLOAT_LOG2
+ #define BITS_PER_DOUBLE_LOG2 PR_BITS_PER_DOUBLE_LOG2
+ #define BITS_PER_WORD_LOG2 PR_BITS_PER_WORD_LOG2
+
+ #define ALIGN_OF_SHORT PR_ALIGN_OF_SHORT
+ #define ALIGN_OF_INT PR_ALIGN_OF_INT
+ #define ALIGN_OF_LONG PR_ALIGN_OF_LONG
+ #define ALIGN_OF_INT64 PR_ALIGN_OF_INT64
+ #define ALIGN_OF_FLOAT PR_ALIGN_OF_FLOAT
+ #define ALIGN_OF_DOUBLE PR_ALIGN_OF_DOUBLE
+ #define ALIGN_OF_POINTER PR_ALIGN_OF_POINTER
+ #define ALIGN_OF_WORD PR_ALIGN_OF_WORD
+
+ #define BYTES_PER_WORD_LOG2 PR_BYTES_PER_WORD_LOG2
+ #define BYTES_PER_DWORD_LOG2 PR_BYTES_PER_DWORD_LOG2
+ #define WORDS_PER_DWORD_LOG2 PR_WORDS_PER_DWORD_LOG2
+
+ #endif /* NO_NSPR_10_SUPPORT */
+
+ #endif /* nspr_cpucfg___ */
diff --git a/pr/include/md/_wince.h b/pr/include/md/_wince.h
new file mode 100644
index 00000000..63cba7be
--- /dev/null
+++ b/pr/include/md/_wince.h
@@ -0,0 +1,513 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ *
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation. Portions created by Netscape are
+ * Copyright (C) 1998-2000 Netscape Communications Corporation. All
+ * Rights Reserved.
+ *
+ * Contributor(s):
+ * Garrett Arch Blythe 01/15/2002
+ *
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable
+ * instead of those above. If you wish to allow use of your
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL. If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+#ifndef nspr_wince_defs_h___
+#define nspr_wince_defs_h___
+
+#include <windows.h>
+#include <winsock.h>
+#include <winnt.h>
+#include <stdlib.h>
+
+#include "_win32_time.h"
+#include "_win32_unicode.h"
+
+#include "prio.h"
+
+/*
+ * Internal configuration macros
+ */
+
+#define PR_LINKER_ARCH "win32"
+#define _PR_SI_SYSNAME "WINCE"
+
+/*
+ * Hardcoded for now.
+ */
+#if defined(_X86_)
+#define _PR_SI_ARCHITECTURE "x86"
+#elif defined(_ARM_)
+#define _PR_SI_ARCHITECTURE "ARM"
+#else
+#define _PR_SI_ARCHITECTURE "XX"
+#endif
+
+#define HAVE_DLL
+#undef HAVE_THREAD_AFFINITY
+#define _PR_HAVE_ATOMIC_OPS
+#define PR_HAVE_WIN32_NAMED_SHARED_MEMORY
+
+/* --- Common User-Thread/Native-Thread Definitions --------------------- */
+
+/* --- Globals --- */
+extern struct PRLock *_pr_schedLock;
+
+/* --- Typedefs --- */
+typedef void (*FiberFunc)(void *);
+
+#define PR_NUM_GCREGS 8
+typedef PRInt32 PR_CONTEXT_TYPE[PR_NUM_GCREGS];
+#define GC_VMBASE 0x40000000
+#define GC_VMLIMIT 0x00FFFFFF
+
+#define _MD_MAGIC_THREAD 0x22222222
+#define _MD_MAGIC_THREADSTACK 0x33333333
+#define _MD_MAGIC_SEGMENT 0x44444444
+#define _MD_MAGIC_DIR 0x55555555
+#define _MD_MAGIC_CV 0x66666666
+
+struct _MDCPU {
+ int unused;
+};
+
+struct _MDThread {
+ HANDLE blocked_sema; /* Threads block on this when waiting
+ * for IO or CondVar.
+ */
+ PRBool inCVWaitQueue; /* PR_TRUE if the thread is in the
+ * wait queue of some cond var.
+ * PR_FALSE otherwise. */
+ HANDLE handle; /* Win32 thread handle */
+ PRBool noCloseHandle; /* Whether or not to CloseHandle */
+ PRUint32 id;
+ void *sp; /* only valid when suspended */
+ PRUint32 magic; /* for debugging */
+ PR_CONTEXT_TYPE gcContext; /* Thread context for GC */
+ struct PRThread *prev, *next; /* used by the cvar wait queue to
+ * chain the PRThread structures
+ * together */
+ void (*start)(void *); /* used by _PR_MD_CREATE_THREAD to
+ * pass its 'start' argument to
+ * pr_root. */
+};
+
+struct _MDThreadStack {
+ PRUint32 magic; /* for debugging */
+};
+
+struct _MDSegment {
+ PRUint32 magic; /* for debugging */
+};
+
+#undef PROFILE_LOCKS
+
+struct _MDDir {
+ HANDLE d_hdl;
+ WIN32_FIND_DATAW d_entry;
+ CHAR cFileNameA[ MAX_PATH ];
+ PRBool firstEntry; /* Is this the entry returned
+ * by FindFirstFile()? */
+ PRUint32 magic; /* for debugging */
+};
+
+struct _MDCVar {
+ PRUint32 magic;
+ struct PRThread *waitHead, *waitTail; /* the wait queue: a doubly-
+ * linked list of threads
+ * waiting on this condition
+ * variable */
+ PRIntn nwait; /* number of threads in the
+ * wait queue */
+};
+
+#define _MD_CV_NOTIFIED_LENGTH 6
+typedef struct _MDNotified _MDNotified;
+struct _MDNotified {
+ PRIntn length; /* # of used entries in this
+ * structure */
+ struct {
+ struct _MDCVar *cv; /* the condition variable notified */
+ PRIntn times; /* and the number of times notified */
+ struct PRThread *notifyHead; /* list of threads to wake up */
+ } cv[_MD_CV_NOTIFIED_LENGTH];
+ _MDNotified *link; /* link to another of these, or NULL */
+};
+
+struct _MDLock {
+ CRITICAL_SECTION mutex; /* this is recursive on NT */
+
+ /*
+ * When notifying cvars, there is no point in actually
+ * waking up the threads waiting on the cvars until we've
+ * released the lock. So, we temporarily record the cvars.
+ * When doing an unlock, we'll then wake up the waiting threads.
+ */
+ struct _MDNotified notified; /* array of conditions notified */
+#ifdef PROFILE_LOCKS
+ PRInt32 hitcount;
+ PRInt32 misscount;
+#endif
+};
+
+struct _MDSemaphore {
+ HANDLE sem;
+};
+
+struct _MDFileDesc {
+ PRInt32 osfd; /* The osfd can come from one of three spaces:
+ * - For stdin, stdout, and stderr, we are using
+ * the libc file handle (0, 1, 2), which is an int.
+ * - For files and pipes, we are using Win32 HANDLE,
+ * which is a void*.
+ * - For sockets, we are using Winsock SOCKET, which
+ * is a u_int.
+ */
+};
+
+struct _MDProcess {
+ HANDLE handle;
+ DWORD id;
+};
+
+/* --- Misc stuff --- */
+#define _MD_GET_SP(thread) (thread)->md.gcContext[6]
+
+/* --- NT security stuff --- */
+
+extern void _PR_NT_InitSids(void);
+extern void _PR_NT_FreeSids(void);
+extern PRStatus _PR_NT_MakeSecurityDescriptorACL(
+ PRIntn mode,
+ DWORD accessTable[],
+ PSECURITY_DESCRIPTOR *resultSD,
+ PACL *resultACL
+ );
+extern void _PR_NT_FreeSecurityDescriptorACL(
+ PSECURITY_DESCRIPTOR pSD, PACL pACL);
+
+/* --- IO stuff --- */
+
+#define _MD_OPEN _PR_MD_OPEN
+#define _MD_OPEN_FILE _PR_MD_OPEN_FILE
+#define _MD_READ _PR_MD_READ
+#define _MD_WRITE _PR_MD_WRITE
+#define _MD_WRITEV _PR_MD_WRITEV
+#define _MD_LSEEK _PR_MD_LSEEK
+#define _MD_LSEEK64 _PR_MD_LSEEK64
+extern PRInt32 _MD_CloseFile(PRInt32 osfd);
+#define _MD_CLOSE_FILE _MD_CloseFile
+#define _MD_GETFILEINFO _PR_MD_GETFILEINFO
+#define _MD_GETFILEINFO64 _PR_MD_GETFILEINFO64
+#define _MD_GETOPENFILEINFO _PR_MD_GETOPENFILEINFO
+#define _MD_GETOPENFILEINFO64 _PR_MD_GETOPENFILEINFO64
+#define _MD_STAT _PR_MD_STAT
+#define _MD_RENAME _PR_MD_RENAME
+#define _MD_ACCESS _PR_MD_ACCESS
+#define _MD_DELETE _PR_MD_DELETE
+#define _MD_MKDIR _PR_MD_MKDIR
+#define _MD_MAKE_DIR _PR_MD_MAKE_DIR
+#define _MD_RMDIR _PR_MD_RMDIR
+#define _MD_LOCKFILE _PR_MD_LOCKFILE
+#define _MD_TLOCKFILE _PR_MD_TLOCKFILE
+#define _MD_UNLOCKFILE _PR_MD_UNLOCKFILE
+
+/* --- Socket IO stuff --- */
+#define _MD_EACCES WSAEACCES
+#define _MD_EADDRINUSE WSAEADDRINUSE
+#define _MD_EADDRNOTAVAIL WSAEADDRNOTAVAIL
+#define _MD_EAFNOSUPPORT WSAEAFNOSUPPORT
+#define _MD_EAGAIN WSAEWOULDBLOCK
+#define _MD_EALREADY WSAEALREADY
+#define _MD_EBADF WSAEBADF
+#define _MD_ECONNREFUSED WSAECONNREFUSED
+#define _MD_ECONNRESET WSAECONNRESET
+#define _MD_EFAULT WSAEFAULT
+#define _MD_EINPROGRESS WSAEINPROGRESS
+#define _MD_EINTR WSAEINTR
+#define _MD_EINVAL EINVAL
+#define _MD_EISCONN WSAEISCONN
+#define _MD_ENETUNREACH WSAENETUNREACH
+#define _MD_ENOENT ENOENT
+#define _MD_ENOTCONN WSAENOTCONN
+#define _MD_ENOTSOCK WSAENOTSOCK
+#define _MD_EOPNOTSUPP WSAEOPNOTSUPP
+#define _MD_EWOULDBLOCK WSAEWOULDBLOCK
+#define _MD_GET_SOCKET_ERROR() WSAGetLastError()
+#define _MD_SET_SOCKET_ERROR(_err) WSASetLastError(_err)
+
+#define _MD_INIT_FILEDESC(fd)
+extern void _MD_MakeNonblock(PRFileDesc *f);
+#define _MD_MAKE_NONBLOCK _MD_MakeNonblock
+#define _MD_INIT_FD_INHERITABLE _PR_MD_INIT_FD_INHERITABLE
+#define _MD_QUERY_FD_INHERITABLE _PR_MD_QUERY_FD_INHERITABLE
+#define _MD_SHUTDOWN _PR_MD_SHUTDOWN
+#define _MD_LISTEN _PR_MD_LISTEN
+extern PRInt32 _MD_CloseSocket(PRInt32 osfd);
+#define _MD_CLOSE_SOCKET _MD_CloseSocket
+#define _MD_SENDTO _PR_MD_SENDTO
+#define _MD_RECVFROM _PR_MD_RECVFROM
+#define _MD_SOCKETPAIR(s, type, proto, sv) -1
+#define _MD_GETSOCKNAME _PR_MD_GETSOCKNAME
+#define _MD_GETPEERNAME _PR_MD_GETPEERNAME
+#define _MD_GETSOCKOPT _PR_MD_GETSOCKOPT
+#define _MD_SETSOCKOPT _PR_MD_SETSOCKOPT
+#define _MD_SET_FD_INHERITABLE _PR_MD_SET_FD_INHERITABLE
+#define _MD_SELECT select
+#define _MD_FSYNC _PR_MD_FSYNC
+#define READ_FD 1
+#define WRITE_FD 2
+
+#define _MD_INIT_ATOMIC()
+#if defined(_M_IX86) || defined(_X86_)
+#define _MD_ATOMIC_INCREMENT _PR_MD_ATOMIC_INCREMENT
+#define _MD_ATOMIC_ADD _PR_MD_ATOMIC_ADD
+#define _MD_ATOMIC_DECREMENT _PR_MD_ATOMIC_DECREMENT
+#else /* non-x86 processors */
+#define _MD_ATOMIC_INCREMENT(x) InterlockedIncrement((PLONG)x)
+#if defined(WINCE)
+#define _MD_ATOMIC_ADD(ptr,val) (InterlockedExchange((PLONG)ptr, (*(PLONG)ptr) + (LONG)val) + val)
+#else
+#define _MD_ATOMIC_ADD(ptr,val) (InterlockedExchangeAdd((PLONG)ptr, (LONG)val) + val)
+#endif
+#define _MD_ATOMIC_DECREMENT(x) InterlockedDecrement((PLONG)x)
+#endif /* x86 */
+#define _MD_ATOMIC_SET(x,y) InterlockedExchange((PLONG)x, (LONG)y)
+
+#define _MD_INIT_IO _PR_MD_INIT_IO
+
+
+/* wince doesn't have async IO */
+#define _MD_SOCKET _PR_MD_SOCKET
+extern PRInt32 _MD_SocketAvailable(PRFileDesc *fd);
+#define _MD_SOCKETAVAILABLE _MD_SocketAvailable
+#define _MD_PIPEAVAILABLE _PR_MD_PIPEAVAILABLE
+#define _MD_CONNECT _PR_MD_CONNECT
+extern PRInt32 _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
+ PRIntervalTime timeout);
+#define _MD_ACCEPT _MD_Accept
+#define _MD_BIND _PR_MD_BIND
+#define _MD_RECV _PR_MD_RECV
+#define _MD_SEND _PR_MD_SEND
+#define _MD_PR_POLL _PR_MD_PR_POLL
+
+/* --- Scheduler stuff --- */
+// #define _MD_PAUSE_CPU _PR_MD_PAUSE_CPU
+#define _MD_PAUSE_CPU
+
+/* --- DIR stuff --- */
+#define PR_DIRECTORY_SEPARATOR '\\'
+#define PR_DIRECTORY_SEPARATOR_STR "\\"
+#define PR_PATH_SEPARATOR ';'
+#define PR_PATH_SEPARATOR_STR ";"
+#define _MD_ERRNO() GetLastError()
+#define _MD_OPEN_DIR _PR_MD_OPEN_DIR
+#define _MD_CLOSE_DIR _PR_MD_CLOSE_DIR
+#define _MD_READ_DIR _PR_MD_READ_DIR
+
+/* --- Segment stuff --- */
+#define _MD_INIT_SEGS()
+#define _MD_ALLOC_SEGMENT(seg, size, vaddr) 0
+#define _MD_FREE_SEGMENT(seg)
+
+/* --- Environment Stuff --- */
+#define _MD_GET_ENV _PR_MD_GET_ENV
+#define _MD_PUT_ENV _PR_MD_PUT_ENV
+
+/* --- Threading Stuff --- */
+#define _MD_DEFAULT_STACK_SIZE 0
+#define _MD_INIT_THREAD _PR_MD_INIT_THREAD
+#define _MD_INIT_ATTACHED_THREAD _PR_MD_INIT_THREAD
+#define _MD_CREATE_THREAD _PR_MD_CREATE_THREAD
+#define _MD_YIELD _PR_MD_YIELD
+#define _MD_SET_PRIORITY _PR_MD_SET_PRIORITY
+#define _MD_CLEAN_THREAD _PR_MD_CLEAN_THREAD
+#define _MD_SETTHREADAFFINITYMASK _PR_MD_SETTHREADAFFINITYMASK
+#define _MD_GETTHREADAFFINITYMASK _PR_MD_GETTHREADAFFINITYMASK
+#define _MD_EXIT_THREAD _PR_MD_EXIT_THREAD
+#define _MD_EXIT _PR_MD_EXIT
+#define _MD_SUSPEND_THREAD _PR_MD_SUSPEND_THREAD
+#define _MD_RESUME_THREAD _PR_MD_RESUME_THREAD
+#define _MD_SUSPEND_CPU _PR_MD_SUSPEND_CPU
+#define _MD_RESUME_CPU _PR_MD_RESUME_CPU
+#define _MD_BEGIN_SUSPEND_ALL()
+#define _MD_BEGIN_RESUME_ALL()
+#define _MD_END_SUSPEND_ALL()
+#define _MD_END_RESUME_ALL()
+
+/* --- Lock stuff --- */
+#define _PR_LOCK _MD_LOCK
+#define _PR_UNLOCK _MD_UNLOCK
+
+#define _MD_NEW_LOCK(lock) (InitializeCriticalSection(&((lock)->mutex)),(lock)->notified.length=0,(lock)->notified.link=NULL,PR_SUCCESS)
+#define _MD_FREE_LOCK(lock) DeleteCriticalSection(&((lock)->mutex))
+#define _MD_LOCK(lock) EnterCriticalSection(&((lock)->mutex))
+#define _MD_TEST_AND_LOCK(lock) (EnterCriticalSection(&((lock)->mutex)),0)
+#define _MD_UNLOCK _PR_MD_UNLOCK
+
+/* --- lock and cv waiting --- */
+#define _MD_WAIT _PR_MD_WAIT
+#define _MD_WAKEUP_WAITER _PR_MD_WAKEUP_WAITER
+
+/* --- CVar ------------------- */
+#define _MD_WAIT_CV _PR_MD_WAIT_CV
+#define _MD_NEW_CV _PR_MD_NEW_CV
+#define _MD_FREE_CV _PR_MD_FREE_CV
+#define _MD_NOTIFY_CV _PR_MD_NOTIFY_CV
+#define _MD_NOTIFYALL_CV _PR_MD_NOTIFYALL_CV
+
+/* XXXMB- the IOQ stuff is certainly not working correctly yet. */
+// extern struct _MDLock _pr_ioq_lock;
+#define _MD_IOQ_LOCK()
+#define _MD_IOQ_UNLOCK()
+
+
+/* --- Initialization stuff --- */
+#define _MD_START_INTERRUPTS()
+#define _MD_STOP_INTERRUPTS()
+#define _MD_DISABLE_CLOCK_INTERRUPTS()
+#define _MD_ENABLE_CLOCK_INTERRUPTS()
+#define _MD_BLOCK_CLOCK_INTERRUPTS()
+#define _MD_UNBLOCK_CLOCK_INTERRUPTS()
+#define _MD_EARLY_INIT _PR_MD_EARLY_INIT
+#define _MD_FINAL_INIT()
+#define _MD_INIT_CPUS()
+#define _MD_INIT_RUNNING_CPU(cpu)
+
+struct PRProcess;
+struct PRProcessAttr;
+
+#define _MD_CREATE_PROCESS _PR_CreateWindowsProcess
+extern struct PRProcess * _PR_CreateWindowsProcess(
+ const char *path,
+ char *const *argv,
+ char *const *envp,
+ const struct PRProcessAttr *attr
+ );
+
+#define _MD_DETACH_PROCESS _PR_DetachWindowsProcess
+extern PRStatus _PR_DetachWindowsProcess(struct PRProcess *process);
+
+/* --- Wait for a child process to terminate --- */
+#define _MD_WAIT_PROCESS _PR_WaitWindowsProcess
+extern PRStatus _PR_WaitWindowsProcess(struct PRProcess *process,
+ PRInt32 *exitCode);
+
+#define _MD_KILL_PROCESS _PR_KillWindowsProcess
+extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process);
+
+#define _MD_CLEANUP_BEFORE_EXIT _PR_MD_CLEANUP_BEFORE_EXIT
+#define _MD_INIT_CONTEXT
+#define _MD_SWITCH_CONTEXT
+#define _MD_RESTORE_CONTEXT
+
+/* --- Intervals --- */
+#define _MD_INTERVAL_INIT _PR_MD_INTERVAL_INIT
+#define _MD_GET_INTERVAL _PR_MD_GET_INTERVAL
+#define _MD_INTERVAL_PER_SEC _PR_MD_INTERVAL_PER_SEC
+#define _MD_INTERVAL_PER_MILLISEC() (_PR_MD_INTERVAL_PER_SEC() / 1000)
+#define _MD_INTERVAL_PER_MICROSEC() (_PR_MD_INTERVAL_PER_SEC() / 1000000)
+
+/* --- Native-Thread Specific Definitions ------------------------------- */
+
+extern struct PRThread * _MD_CURRENT_THREAD(void);
+
+#ifdef _PR_USE_STATIC_TLS
+extern __declspec(thread) struct PRThread *_pr_currentThread;
+#define _MD_GET_ATTACHED_THREAD() _pr_currentThread
+#define _MD_SET_CURRENT_THREAD(_thread) (_pr_currentThread = (_thread))
+
+extern __declspec(thread) struct PRThread *_pr_thread_last_run;
+#define _MD_LAST_THREAD() _pr_thread_last_run
+#define _MD_SET_LAST_THREAD(_thread) (_pr_thread_last_run = 0)
+
+extern __declspec(thread) struct _PRCPU *_pr_currentCPU;
+#define _MD_CURRENT_CPU() _pr_currentCPU
+#define _MD_SET_CURRENT_CPU(_cpu) (_pr_currentCPU = 0)
+#else /* _PR_USE_STATIC_TLS */
+extern DWORD _pr_currentThreadIndex;
+#define _MD_GET_ATTACHED_THREAD() ((PRThread *) TlsGetValue(_pr_currentThreadIndex))
+#define _MD_SET_CURRENT_THREAD(_thread) TlsSetValue(_pr_currentThreadIndex, (_thread))
+
+extern DWORD _pr_lastThreadIndex;
+#define _MD_LAST_THREAD() ((PRThread *) TlsGetValue(_pr_lastThreadIndex))
+#define _MD_SET_LAST_THREAD(_thread) TlsSetValue(_pr_lastThreadIndex, 0)
+
+extern DWORD _pr_currentCPUIndex;
+#define _MD_CURRENT_CPU() ((struct _PRCPU *) TlsGetValue(_pr_currentCPUIndex))
+#define _MD_SET_CURRENT_CPU(_cpu) TlsSetValue(_pr_currentCPUIndex, 0)
+#endif /* _PR_USE_STATIC_TLS */
+
+/* --- Scheduler stuff --- */
+#define LOCK_SCHEDULER() 0
+#define UNLOCK_SCHEDULER() 0
+#define _PR_LockSched() 0
+#define _PR_UnlockSched() 0
+
+/* --- Initialization stuff --- */
+#define _MD_INIT_LOCKS()
+
+/* --- Stack stuff --- */
+#define _MD_INIT_STACK(stack, redzone)
+#define _MD_CLEAR_STACK(stack)
+
+/* --- Memory-mapped files stuff --- */
+
+struct _MDFileMap {
+ HANDLE hFileMap;
+ DWORD dwAccess;
+};
+
+extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
+#define _MD_CREATE_FILE_MAP _MD_CreateFileMap
+
+extern PRInt32 _MD_GetMemMapAlignment(void);
+#define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
+
+extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
+ PRUint32 len);
+#define _MD_MEM_MAP _MD_MemMap
+
+extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
+#define _MD_MEM_UNMAP _MD_MemUnmap
+
+extern PRStatus _MD_CloseFileMap(struct PRFileMap *fmap);
+#define _MD_CLOSE_FILE_MAP _MD_CloseFileMap
+
+/* --- Named semaphores stuff --- */
+#define _PR_HAVE_NAMED_SEMAPHORES
+#define _MD_OPEN_SEMAPHORE _PR_MD_OPEN_SEMAPHORE
+#define _MD_WAIT_SEMAPHORE _PR_MD_WAIT_SEMAPHORE
+#define _MD_POST_SEMAPHORE _PR_MD_POST_SEMAPHORE
+#define _MD_CLOSE_SEMAPHORE _PR_MD_CLOSE_SEMAPHORE
+#define _MD_DELETE_SEMAPHORE(name) PR_SUCCESS /* no op */
+
+
+/*
+ * Couple of missing functions for wince.
+ */
+extern struct protoent* Wingetprotobyname(const char* inName);
+extern struct protoent* Wingetprotobynumber(int inNumber);
+
+#endif /* nspr_wince_defs_h___ */
diff --git a/pr/src/md/windows/w32netdb.c b/pr/src/md/windows/w32netdb.c
new file mode 100644
index 00000000..9118bbda
--- /dev/null
+++ b/pr/src/md/windows/w32netdb.c
@@ -0,0 +1,109 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ *
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation. Portions created by Netscape are
+ * Copyright (C) 1998-2000 Netscape Communications Corporation. All
+ * Rights Reserved.
+ *
+ * Contributor(s):
+ * Garrett Arch Blythe, 02/07/2002
+ *
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable
+ * instead of those above. If you wish to allow use of your
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL. If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+/*
+ * w32netdb.c
+ *
+ * This file exists mainly to provide an implementation of the socket
+ * functions that are missing from certain toolsets; namely
+ * MS eMbedded Visual Tools (Windows CE).
+ */
+
+#include "primpl.h"
+
+/*
+ * Our static protocols entries.
+ */
+static struct protoent sProtos[] = {
+ { "tcp", NULL, IPPROTO_TCP },
+ { "udp", NULL, IPPROTO_UDP },
+ { "ip", NULL, IPPROTO_IP },
+ { "icmp", NULL, IPPROTO_ICMP },
+ { "ggp", NULL, IPPROTO_GGP },
+ { "pup", NULL, IPPROTO_PUP },
+ { "idp", NULL, IPPROTO_IDP },
+ { "nd", NULL, IPPROTO_ND },
+ { "raw", NULL, IPPROTO_RAW }
+};
+
+#define MAX_PROTOS (sizeof(sProtos) / sizeof(struct protoent))
+
+/*
+ * Wingetprotobyname
+ *
+ * As getprotobyname
+ */
+struct protoent* Wingetprotobyname(const char* inName)
+{
+ struct protoent* retval = NULL;
+
+ if(NULL != inName)
+ {
+ unsigned uLoop;
+
+ for(uLoop = 0; uLoop < MAX_PROTOS; uLoop++)
+ {
+ if(0 == stricmp(inName, sProtos[uLoop].p_name))
+ {
+ retval = &sProtos[uLoop];
+ break;
+ }
+ }
+ }
+
+ return retval;
+}
+
+/*
+ * Wingetprotobynumber
+ *
+ * As getprotobynumber
+ */
+struct protoent* Wingetprotobynumber(int inNumber)
+{
+ struct protoent* retval = NULL;
+ unsigned uLoop;
+
+ for(uLoop = 0; uLoop < MAX_PROTOS; uLoop++)
+ {
+ if(inNumber == sProtos[uLoop].p_proto)
+ {
+ retval = &sProtos[uLoop];
+ break;
+ }
+ }
+
+ return retval;
+}
diff --git a/pr/src/md/windows/w32unicode.c b/pr/src/md/windows/w32unicode.c
new file mode 100644
index 00000000..fc14c825
--- /dev/null
+++ b/pr/src/md/windows/w32unicode.c
@@ -0,0 +1,161 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * The Original Code is the Netscape Portable Runtime (NSPR).
+ *
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation. Portions created by Netscape are
+ * Copyright (C) 1998-2000 Netscape Communications Corporation. All
+ * Rights Reserved.
+ *
+ * Contributor(s):
+ * Garrett Arch Blythe, 02/05/2002
+ *
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License Version 2 or later (the
+ * "GPL"), in which case the provisions of the GPL are applicable
+ * instead of those above. If you wish to allow use of your
+ * version of this file only under the terms of the GPL and not to
+ * allow others to use your version of this file under the MPL,
+ * indicate your decision by deleting the provisions above and
+ * replace them with the notice and other provisions required by
+ * the GPL. If you do not delete the provisions above, a recipient
+ * may use your version of this file under either the MPL or the
+ * GPL.
+ */
+
+/*
+ * w32unicode.c
+ *
+ * This file exists mainly to provide easy ways to convert internal
+ * multibyte string representations into their wide character
+ * counterparts.
+ *
+ * FYI:
+ *
+ * WinNT functions as a UNICODE Win32 API with automatic conversions
+ * functioning in the funcA (using funcW would be faster for NT).
+ * Win95 functions as a multibyte Win32 API with automatic conversions
+ * functioning in the funcW (using funcA would be faster for win9x).
+ */
+
+#include "primpl.h"
+
+/*
+ * _PR_MD_MALLOC_A2W
+ *
+ * Automatically PR_Malloc a wide char string and return it based on the
+ * ANSI (multi byte, ansi code page) string passed in.
+ *
+ * Caller must PR_Free the return value if non-NULL.
+ */
+LPWSTR _PR_MD_MALLOC_A2W(LPCSTR inString)
+{
+ LPWSTR retval = NULL;
+
+ if(NULL != inString)
+ {
+ int neededWChars = 0;
+
+ neededWChars = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, inString, -1, NULL, 0);
+ if(0 < neededWChars)
+ {
+ LPWSTR wstr = NULL;
+
+ wstr = (LPWSTR)PR_Malloc(sizeof(WCHAR) * neededWChars);
+ if(NULL != wstr)
+ {
+ int convertRes = 0;
+
+ convertRes = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, inString, -1, wstr, neededWChars);
+ if(0 == convertRes)
+ {
+ PR_Free(wstr);
+ }
+ else
+ {
+ retval = wstr;
+ }
+ }
+ }
+ }
+
+ return retval;
+}
+
+/*
+ * _PR_MD_A2W
+ *
+ * Non-mallocing version to return a wide char string based on the
+ * ANSI (multi byte, ansi code page) string passed in.
+ *
+ * NOTE: inWideStringChars is number of wide characters in outWideString,
+ * NOT the number of bytes....
+ */
+LPWSTR _PR_MD_A2W(LPCSTR inString, LPWSTR outWideString, int inWideStringChars)
+{
+ LPWSTR retval = outWideString;
+
+ if(NULL != outWideString)
+ {
+ int convertRes = 0;
+
+ convertRes = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, inString, -1, outWideString, inWideStringChars);
+ if(0 == convertRes)
+ {
+ retval = NULL;
+ }
+ }
+
+ return retval;
+}
+
+/*
+ * _PR_MD_W2A
+ *
+ * Non-mallocing fucntion to return a ANSI (multi byte, ansi code page)
+ * string based on the wide char string passed in.
+ *
+ * NOTE: inWideStringChars is number of wide characters in outWideString,
+ * NOT the number of bytes....
+ */
+LPSTR _PR_MD_W2A(LPCWSTR inWideString, LPSTR outString, int inStringChars)
+{
+ LPSTR retval = outString;
+
+ if(NULL != outString)
+ {
+ int convertRes = 0;
+
+ convertRes = WideCharToMultiByte(
+ CP_ACP,
+ WC_COMPOSITECHECK,
+ inWideString,
+ -1,
+ outString,
+ inStringChars,
+ NULL,
+ NULL
+ );
+ if(0 == convertRes)
+ {
+ retval = NULL;
+ }
+ }
+
+ return retval;
+}
+
+#if defined(WINCE)
+
+
+#endif /* WINCE */