More work to support unimplemented library functions for Wince. WINCE_NSPRPUB_RELEASE_4_2_BETA1
authorblythe%netscape.com
Fri, 08 Feb 2002 00:00:28 +0000
branchWINCE_NSPRPUB_RELEASE_4_2_BETA1
changeset 2226 90e6fb0388ae1319837b3fcad4d400eedd05109c
parent 2225 5fba6f0782e3948237f627cb63ddb11b04abafe0
child 2227 45e92b49703b360baf751848ecddd0919d91e592
push idunknown
push userunknown
push dateunknown
More work to support unimplemented library functions for Wince.
pr/include/md/_win32_time.h
pr/include/md/_wince.h
pr/src/md/windows/Makefile.in
pr/src/md/windows/objs.mk
pr/src/md/windows/w32netdb.c
pr/src/md/windows/w32time.c
pr/src/misc/prnetdb.c
pr/src/misc/prtime.c
--- a/pr/include/md/_win32_time.h
+++ b/pr/include/md/_win32_time.h
@@ -156,25 +156,9 @@
         FILETIME conversion; \
         FILETIME localConversion; \
         \
         _MD_time_t_2_FILETIME(conversion, inTimeT); \
         FileTimeToLocalFileTime(&conversion, &localConversion); \
         FileTimeToSystemTime(&localConversion, &outSystemTime); \
     PR_END_MACRO
 
-/*
- * tm is needed.
- * Used by Winlocaltime.
- */
-struct tm {
-    int tm_sec;
-    int tm_min;
-    int tm_hour;
-    int tm_mday;
-    int tm_mon;
-    int tm_year;
-    int tm_wday;
-    int tm_yday;
-    int tm_isdst;
-};
-
 #endif /* nspr_win32_time_h___ */
--- a/pr/include/md/_wince.h
+++ b/pr/include/md/_wince.h
@@ -501,17 +501,19 @@ extern PRStatus _MD_CloseFileMap(struct 
 
 
 /*
  * Missing types.
  */
 typedef long _off_t; /* file offset value */
 
 /*
- * Missing structs that are assumed by nspr.
+ * struct stat
+ *
+ * Assumed by NSPR in a place or two.
  */
 struct stat {
     unsigned short st_mode;
     _off_t st_size;
     time_t st_atime;
     time_t st_mtime;
     time_t st_ctime;
 };
@@ -528,9 +530,44 @@ struct stat {
  */
 #define HINSTANCE_ERROR 1 /* LoadLibrary, NULL on failure for WinCE */
 #define _S_IFDIR    0040000 /* stat, is a directory */
 #define _S_IFREG    0100000 /* stat, is a normal file */
 #define _S_IREAD    0000400 /* stat, can read */
 #define _S_IWRITE   0000200 /* stat, can write */
 #define ENOMEM 12 /* errno, out of memory */
 
+/*
+ * struct tm
+ *
+ * And related windows specific functions to mimic LIBC's tm funcs.
+ */
+struct tm {
+    int tm_sec;
+    int tm_min;
+    int tm_hour;
+    int tm_mday;
+    int tm_mon;
+    int tm_year;
+    int tm_wday;
+    int tm_yday;
+    int tm_isdst;
+};
+extern struct tm* Winlocaltime(const time_t* inTimeT);
+extern time_t Winmktime(struct tm* inTM);
+extern size_t Winstrftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr);
+
+/*
+ * struct protoent is actually defined, but the functions that use it are not.
+ *
+ * And related windows specific functions to mimic these absent sockets funcs.
+ */
+#if 0
+struct protoent {
+    char* p_name;
+    char** p_aliases;
+    short p_proto;
+};
+#endif
+extern struct protoent* Wingetprotobyname(const char* inName);
+extern struct protoent* Wingetprotobynumber(int inNumber);
+
 #endif /* nspr_wince_defs_h___ */
--- a/pr/src/md/windows/Makefile.in
+++ b/pr/src/md/windows/Makefile.in
@@ -72,16 +72,17 @@ CSRCS = \
     w95sock.c \
     win32_errors.c \
     w32ipcsem.c \
     w32poll.c \
     w32shm.c \
     w95dllmain.c \
     w32time.c \
     w32unicode.c \
+    w32netdb.c \
     $(NULL)
 else
 ifeq ($(OS_TARGET), WIN95)
 CSRCS =          \
     ntmisc.c \
     ntsec.c   \
     ntsem.c   \
     ntinrval.c \
--- a/pr/src/md/windows/objs.mk
+++ b/pr/src/md/windows/objs.mk
@@ -59,17 +59,18 @@ CSRCS =	ntmisc.c \
 	w95sock.c \
 	win32_errors.c \
 	w32ipcsem.c \
 	w32poll.c \
 	w32rng.c \
 	w32shm.c \
 	w95dllmain.c \
 	w32time.c \
-	w32unicode.c
+	w32unicode.c \
+	w32netdb.c
 else
 ifeq ($(OS_TARGET),WIN95)
 CSRCS =	ntmisc.c \
 	ntsec.c \
 	ntsem.c \
 	ntinrval.c \
 	ntgc.c \
 	w95thred.c \
new file mode 100644
--- /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;
+}
--- a/pr/src/md/windows/w32time.c
+++ b/pr/src/md/windows/w32time.c
@@ -106,9 +106,47 @@ struct tm* Winlocaltime(const time_t* in
             tmStorage.tm_isdst = -1;
             break;
         }
 
         retval = &tmStorage;
     }
 
     return retval;
-}
\ No newline at end of file
+}
+
+/*
+ *  Winmktime
+ *
+ *  As LIBCs mktime
+ */
+time_t Winmktime(struct tm* inTM)
+{
+    time_t retval = (time_t)-1;
+
+    /*
+    ** FIXME TODO
+    **
+    ** More here
+    */
+
+    return retval;
+}
+
+/*
+ *  Winstrftime
+ *
+ *  As LIBCs strftime
+ */
+size_t Winstrftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr)
+{
+    size_t retval = 0;
+
+    /*
+    ** FIXME TODO
+    **
+    ** More here.
+    **
+    ** Use GetTimeFormat and GetDateFormat
+    */
+
+    return retval;
+}
--- a/pr/src/misc/prnetdb.c
+++ b/pr/src/misc/prnetdb.c
@@ -838,28 +838,28 @@ PR_IMPLEMENT(PRStatus) PR_GetHostByAddr(
  * any usable implementation.
  */
 
 static struct protoent *getprotobyname_r(const char* name)
 {
 #ifdef XP_OS2_VACPP
 	return getprotobyname((char *)name);
 #elif defined(WINCE)
-    return NULL;
+    return Wingetprotobyname(name);
 #else
 	return getprotobyname(name);
 #endif
 } /* getprotobyname_r */
 
 static struct protoent *getprotobynumber_r(PRInt32 number)
 {
 #if !defined(WINCE)
 	return getprotobynumber(number);
 #else
-    return NULL;
+    return Wingetprotobynumber(number);
 #endif
 } /* getprotobynumber_r */
 
 #endif /* !defined(_PR_HAVE_GETPROTO_R) */
 
 PR_IMPLEMENT(PRStatus) PR_GetProtoByName(
     const char* name, char* buffer, PRInt32 buflen, PRProtoEnt* result)
 {
--- a/pr/src/misc/prtime.c
+++ b/pr/src/misc/prtime.c
@@ -566,17 +566,16 @@ PR_NormalizeTime(PRExplodedTime *time, P
 #define MT_safe_localtime localtime_r
 
 #else
 
 #if defined(XP_MAC)
 extern struct tm *Maclocaltime(const time_t * t);
 #endif
 #if defined(WINCE)
-extern struct tm* Winlocaltime(const time_t* inTimeT);
 #endif
 
 static PRLock *monitor = NULL;
 
 static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result)
 {
     struct tm *tmPtr;
     int needLock = PR_Initialized();  /* We need to use a lock to protect
@@ -1585,17 +1584,21 @@ PR_ParseTimeString(
                   localTime.tm_mday = tm.tm_mday;
                   localTime.tm_mon = tm.tm_month;
                   localTime.tm_year = tm.tm_year - 1900;
                   /* Set this to -1 to tell mktime "I don't care".  If you set
                      it to 0 or 1, you are making assertions about whether the
                      date you are handing it is in daylight savings mode or not;
                      and if you're wrong, it will "fix" it for you. */
                   localTime.tm_isdst = -1;
+#if !defined(WINCE)
                   secs = mktime(&localTime);
+#else
+                  secs = Winmktime(&localTime);
+#endif
                   if (secs != (time_t) -1)
                     {
 #if defined(XP_MAC) && (__MSL__ < 0x6000)
                       /*
                        * The mktime() routine in MetroWerks MSL C
                        * Runtime library returns seconds since midnight,
                        * 1 Jan. 1900, not 1970 - in versions of MSL (Metrowerks Standard
                        * Library) prior to version 6.  Only for older versions of
@@ -1678,17 +1681,21 @@ PR_FormatTime(char *buf, int buflen, con
 
 #if defined(SUNOS4) || (__GLIBC__ >= 2) || defined(XP_BEOS)
     if (mktime(&a) == -1) {
         PR_snprintf(buf, buflen, "can't get timezone");
         return 0;
     }
 #endif
 
+#if !defined(WINCE)
     return strftime(buf, buflen, fmt, &a);
+#else
+    return Winstrftime(buf, buflen, fmt, &a);
+#endif
 }
 
 
 /*
  * The following string arrays and macros are used by PR_FormatTimeUSEnglish().
  */
 
 static const char* abbrevDays[] =