harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r350181 [190/198] - in /incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/ depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/ depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/ depends/oss/win....
Date Thu, 01 Dec 2005 06:04:00 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hysock.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hysock.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hysock.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hysock.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,222 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#if !defined(hysock_h)
+#define hysock_h
+
+/******************************************************\
+       Portable socket library implementation.
+\******************************************************/
+/* windows.h defined UDATA.  Ignore its definition */
+#define UDATA UDATA_win32_
+#include <windows.h>
+#undef UDATA			/* this is safe because our UDATA is a typedef, not a macro */
+
+/* Undefine the winsockapi because winsock2 defines it.  Removes warnings. */
+#if defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)
+#undef _WINSOCKAPI_
+#endif
+#include <winsock2.h>
+#include <ws2tcpip.h>
+
+#include "hysocket.h"
+#include "hycomp.h"
+#include "hyport.h"
+#include "hyportpg.h"
+
+#if defined(DEBUG)
+#define HYSOCKDEBUG(x, error) printf(x, error)
+#define HYSOCKDEBUGPRINT(x) printf(x)
+#else
+#define HYSOCKDEBUG(x, error)
+#define HYSOCKDEBUGPRINT(x)
+#endif
+
+extern HY_CFUNC char *VMCALL os_error_message
+PROTOTYPE ((struct HyPortLibrary * portLibrary, I_32 errorNum));
+
+/* os types */
+typedef SOCKET OSSOCKET;	/* as returned by socket() */
+typedef SOCKADDR OSADDR;
+typedef SOCKADDR_IN OSSOCKADDR;	/* as used by bind() and friends */
+typedef struct hostent OSHOSTENT;
+typedef fd_set OSFDSET;
+typedef struct timeval OSTIMEVAL;
+typedef struct linger OSLINGER;
+typedef struct ip_mreq OSIPMREQ;
+
+#define OSSOMAXCONN SOMAXCONN
+#define OS_BADSOCKET INVALID_SOCKET
+
+typedef SOCKADDR_IN6 OSSOCKADDR_IN6;	/* IPv6 */
+typedef struct ipv6_mreq OSIPMREQ6;
+typedef struct addrinfo OSADDRINFO;	/* IPv6 */
+typedef struct sockaddr_storage OSSOCKADDR_STORAGE;	/* IPv6 */
+/* constant for identifying the pseudo looback interface */
+#define pseudoLoopbackGUID  "{6BD113CC-5EC2-7638-B953-0B889DA72014}"
+
+/* defines for socket levels */
+#define OS_SOL_SOCKET SOL_SOCKET
+#define OS_IPPROTO_TCP IPPROTO_TCP
+#define OS_IPPROTO_IP IPPROTO_IP
+#define OS_IPPROTO_IPV6 IPPROTO_IPV6
+
+/* defines for socket options */
+#define OS_SO_LINGER SO_LINGER
+#define OS_SO_KEEPALIVE SO_KEEPALIVE
+#define OS_TCP_NODELAY TCP_NODELAY
+#define OS_SO_REUSEADDR SO_REUSEADDR
+#define OS_SO_SNDBUF SO_SNDBUF
+#define OS_SO_RCVBUF SO_RCVBUF
+#define OS_SO_BROADCAST SO_BROADCAST
+#define OS_SO_OOBINLINE SO_OOBINLINE
+#define OS_IP_TOS IP_TOS
+
+/* defines added for IPv6 */
+#define OS_AF_INET4 AF_INET
+#define OS_AF_UNSPEC AF_UNSPEC
+#define OS_PF_UNSPEC PF_UNSPEC
+#define OS_PF_INET4 PF_INET
+#define OS_AF_INET6 AF_INET6
+#define OS_PF_INET6 PF_INET6
+#define OS_INET4_ADDRESS_LENGTH INET_ADDRSTRLEN
+#define OS_INET6_ADDRESS_LENGTH INET6_ADDRSTRLEN
+#define OSNIMAXHOST NI_MAXHOST
+#define OSNIMAXSERV NI_MAXSERV
+
+/* defines for socket options, multicast */
+#define OS_MCAST_TTL IP_MULTICAST_TTL
+#define OS_MCAST_ADD_MEMBERSHIP IP_ADD_MEMBERSHIP
+#define OS_MCAST_DROP_MEMBERSHIP IP_DROP_MEMBERSHIP
+#define OS_MCAST_INTERFACE IP_MULTICAST_IF
+#define OS_MCAST_INTERFACE_2 IPV6_MULTICAST_IF
+#define OS_IPV6_ADD_MEMBERSHIP IPV6_ADD_MEMBERSHIP
+#define OS_IPV6_DROP_MEMBERSHIP IPV6_DROP_MEMBERSHIP
+#define OS_MCAST_LOOP IP_MULTICAST_LOOP
+
+/* platform constants */
+#define HYSOCK_MAXCONN OSSOMAXCONN
+#define HYSOCK_BADSOCKET OS_BADSOCKET
+
+/*
+ * Socket Types
+ */
+#define OSSOCK_ANY        0	/* for getaddrinfo hints */
+#define OSSOCK_STREAM     SOCK_STREAM	/* stream socket */
+#define OSSOCK_DGRAM      SOCK_DGRAM	/* datagram socket */
+#define OSSOCK_RAW        SOCK_RAW	/* raw-protocol interface */
+#define OSSOCK_RDM        SOCK_RDM	/* reliably-delivered message */
+#define OSSOCK_SEQPACKET  SOCK_SEQPACKET	/* sequenced packet stream */
+
+/* socket structure flags */
+#define SOCKET_IPV4_OPEN_MASK '\x1'	/* 00000001 */
+#define SOCKET_IPV6_OPEN_MASK '\x2'	/* 00000010 */
+#define SOCKET_BOTH_OPEN_MASK '\x3'	/* 00000011 */
+#define SOCKET_USE_IPV4_MASK '\x4'	/* 00000100 - this tells which one to pick when doing an operation */
+
+/* The sockets returned as a hysocket_t (hysocket_struct*) are not actual structs, we just
+ * pretend that the pointer is a struct and never dereference it.
+ */
+#if defined(NO_LVALUE_CASTING)
+#define SOCKET_CAST(x) (*((OSSOCKET *) &(x)))
+#else
+#define SOCKET_CAST(x) ((OSSOCKET)x)
+#endif
+typedef struct hysockaddr_struct
+{
+  OSSOCKADDR_STORAGE addr;
+} hysockaddr_struct;
+
+/*
+* Socket structure on windows requires 2 sockets due to the fact that microsoft does not
+* handle ipv6-mapped ipv6 addresses.  Therefore we need to listen to sockets on both
+* the ipv6 and ipv4 stacks, when in a mode where we support ipv6.
+*/
+typedef struct hysocket_struct
+{
+  OSSOCKET ipv4;
+  OSSOCKET ipv6;
+  U_8 flags;
+} hysocket_struct;
+
+typedef struct hyhostent_struct
+{
+  OSHOSTENT *entity;
+} hyhostent_struct;
+
+typedef struct hyfdset_struct
+{
+  OSFDSET handle;
+} hyfdset_struct;
+
+typedef struct hytimeval_struct
+{
+  OSTIMEVAL time;
+} hytimeval_struct;
+
+typedef struct hylinger_struct
+{
+  OSLINGER linger;
+} hylinger_struct;
+
+typedef struct hyipmreq_struct
+{
+  OSIPMREQ addrpair;
+} hyipmreq_struct;
+
+typedef struct hyipv6_mreq_struct
+{
+  OSIPMREQ6 mreq;
+} hyipv6_mreq_struct;
+
+/** structure for IPv6 addrinfo will either point to a hostent or 
+	an addr info depending on the IPv6 support for this OS */
+typedef struct hyaddrinfo_struct
+{
+  void *addr_info;
+  int length;
+} hyaddrinfo_struct;
+
+/* structure for returning either and IPV4 or IPV6 ip address */
+typedef struct hyipAddress_struct
+{
+  union
+  {
+    U_8 bytes[sizeof (struct in6_addr)];
+    struct in_addr inAddr;
+    struct in6_addr in6Addr;
+  } addr;
+  U_32 length;
+  U_32 scope;
+} hyipAddress_struct;
+
+/* structure for returning network interface information */
+typedef struct hyNetworkInterface_struct
+{
+  char *name;
+  char *displayName;
+  U_32 numberAddresses;
+  U_32 index;
+  struct hyipAddress_struct *addresses;
+} hyNetworkInterface_struct;
+
+/* array of network interface structures */
+typedef struct hyNetworkInterfaceArray_struct
+{
+  U_32 length;
+  struct hyNetworkInterface_struct *elements;
+} hyNetworkInterfaceArray_struct;
+
+#endif /* hysock_h */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hystr.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hystr.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hystr.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hystr.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,1127 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * @ingroup Port
+ * @brief String utilities.
+ */
+#include <stdarg.h>
+#include <string.h>
+
+/* for sprintf, which is used for printing floats */
+#include <stdio.h>
+
+#include "hycomp.h"
+#include "hyport.h"
+
+#define HYFTYPE_U64 1
+#define HYFTYPE_U32 2
+#define HYFTYPE_DBL 3
+#define HYFTYPE_PTR 4
+#define HYFTYPE_IMMEDIATE 5
+
+#define HYFFLAG_DASH 0x01
+#define HYFFLAG_HASH 0x02
+#define HYFFLAG_ZERO 0x04
+#define HYFFLAG_SPACE 0x08
+#define HYFFLAG_PLUS 0x10
+
+#define HYFSPEC_LL 0x20
+#define HYFSPEC_L 0x40
+
+#define HYF_NO_VALUE ((U_64)-1)
+
+typedef union
+{
+  U_64 u64;
+  double dbl;
+  void *ptr;
+} HyFormatValue;
+
+typedef struct
+{
+  U_8 tag;
+  U_8 index;
+  U_8 widthIndex;
+  U_8 precisionIndex;
+  const char *type;
+} HyFormatSpecifier;
+
+#define HYF_MAX_SPECS 16
+#define HYF_MAX_ARGS (HYF_MAX_SPECS * 3)
+
+typedef struct
+{
+  const char *formatString;
+  HyFormatValue value[HYF_MAX_ARGS];
+  U_8 valueType[HYF_MAX_ARGS];
+  HyFormatSpecifier spec[HYF_MAX_SPECS];
+  U_8 valueCount;
+  U_8 immediateCount;
+  U_8 specCount;
+} HyFormatData;
+
+static const char digits_dec[] = "0123456789";
+static const char digits_hex_lower[] = "0123456789abcdef";
+static const char digits_hex_upper[] = "0123456789ABCDEF";
+
+extern U_32 encodeUTF8Char (UDATA unicode, U_8 * result);
+
+static const char *parseTagChar (const char *format, HyFormatData * result);
+static void readValues (struct HyPortLibrary *portLibrary,
+			HyFormatData * result, va_list args);
+static int parseFormatString (struct HyPortLibrary *portLibrary,
+			      HyFormatData * result);
+static I_32 writeDoubleToBuffer (char *buf, U_32 bufLen, U_64 width,
+				 U_64 precision, double value, U_8 type,
+				 U_8 tag);
+static const char *parseModifier (const char *format, HyFormatData * result);
+static const char *parseType (const char *format, HyFormatData * result);
+static const char *parseWidth (const char *format, HyFormatData * result);
+static U_32 writeFormattedString (struct HyPortLibrary *portLibrary,
+				  HyFormatData * data, char *result,
+				  U_32 length);
+static I_32 writeSpec (HyFormatData * data, HyFormatSpecifier * spec,
+		       char *result, U_32 length);
+static const char *parseIndex (const char *format, U_8 * result);
+static I_32 writeStringToBuffer (char *buf, U_32 bufLen, U_64 width,
+				 U_64 precision, const char *value, U_8 tag);
+static const char *parsePrecision (const char *format, HyFormatData * result);
+static I_32 writeIntToBuffer (char *buf, U_32 bufLen, U_64 width,
+			      U_64 precision, U_64 value, U_8 tag,
+			      int isSigned, const char *digits);
+static I_32 writeUnicodeStringToBuffer (char *buf, U_32 bufLen, U_64 width,
+					U_64 precision, const U_16 * value,
+					U_8 tag);
+
+/**
+ * Write characaters to a string as specified by format.
+ *
+ * @param[in] portLibrary The port library.
+ * @param[in, out] buf The string buffer to be written.
+ * @param[in] bufLen The size of the string buffer to be written.
+ * @param[in] format The format of the string.
+ * @param[in] ... Arguments for the format string.
+ *
+ * @return The number of characters printed not including the NUL terminator.
+ *
+ * @note When buf is NULL, the size of the buffer required to print to the string, including
+ * the NUL terminator is returned.
+ */
+U_32 VMCALL
+hystr_printf (struct HyPortLibrary *portLibrary, char *buf, U_32 bufLen,
+	      const char *format, ...)
+{
+  U_32 rc;
+  va_list args;
+  va_start (args, format);
+  rc = portLibrary->str_vprintf (portLibrary, buf, bufLen, format, args);
+  va_end (args);
+  return rc;
+}
+
+/**
+ * Write characaters to a string as specified by format.
+ *
+ * @param[in] portLibrary The port library.
+ * @param[in, out] buf The string buffer to be written.
+ * @param[in] bufLen The size of the string buffer to be written.
+ * @param[in] format The format of the string.
+ * @param[in] args Arguments for the format string.
+ *
+ * @return The number of characters printed not including the NUL terminator.
+ *
+ * @note When buf is NULL, the size of the buffer required to print to the string, including
+ * the NUL terminator is returned.
+ */
+U_32 VMCALL
+hystr_vprintf (struct HyPortLibrary * portLibrary, char *buf, U_32 bufLen,
+	       const char *format, va_list args)
+{
+  HyFormatData formatData;
+  memset (&formatData, 0, sizeof (formatData));
+
+  formatData.formatString = format;
+  parseFormatString (portLibrary, &formatData);
+  readValues (portLibrary, &formatData, args);
+  return writeFormattedString (portLibrary, &formatData, buf, bufLen);
+}
+
+static int
+parseFormatString (struct HyPortLibrary *portLibrary, HyFormatData * result)
+{
+  const char *format = result->formatString;
+
+  while (*format)
+    {
+      switch (*format)
+	{
+	case '%':
+	  format++;
+	  switch (*format)
+	    {
+	    case '%':
+	      /* literal '%' */
+	      format++;
+	      break;
+	    default:
+	      format =
+		parseIndex (format, &result->spec[result->specCount].index);
+	      format = parseTagChar (format, result);
+	      format = parseWidth (format, result);
+	      format = parsePrecision (format, result);
+	      format = parseModifier (format, result);
+	      format = parseType (format, result);
+	      if (format == NULL)
+		{
+		  return -1;
+		}
+	      result->specCount++;
+	    }
+	  break;
+	default:
+	  format++;
+	}
+    }
+
+  return 0;
+}
+
+static const char *
+parseTagChar (const char *format, HyFormatData * result)
+{
+  switch (*format)
+    {
+    case '0':
+      result->spec[result->specCount].tag |= HYFFLAG_ZERO;
+      format++;
+      break;
+    case ' ':
+      result->spec[result->specCount].tag |= HYFFLAG_SPACE;
+      format++;
+      break;
+    case '-':
+      result->spec[result->specCount].tag |= HYFFLAG_DASH;
+      format++;
+      break;
+    case '+':
+      result->spec[result->specCount].tag |= HYFFLAG_PLUS;
+      format++;
+      break;
+    case '#':
+      result->spec[result->specCount].tag |= HYFFLAG_HASH;
+      format++;
+      break;
+    }
+
+  return format;
+}
+
+static const char *
+parseWidth (const char *format, HyFormatData * result)
+{
+  U_8 index;
+
+  if (*format == '*')
+    {
+      format =
+	parseIndex (format + 1, &result->spec[result->specCount].widthIndex);
+      index = result->spec[result->specCount].widthIndex;
+      if (index == 0xFF)
+	{
+	  index = result->valueCount;
+	  result->spec[result->specCount].widthIndex = index;
+	}
+      result->valueCount++;
+      result->valueType[index] = HYFTYPE_U32;
+      result->value[index].u64 = HYF_NO_VALUE;
+
+      return format;
+    }
+  else
+    {
+      U_32 width = 0;
+      int anyDigits = 0;
+      for (;;)
+	{
+	  switch (*format)
+	    {
+	    case '0':
+	    case '1':
+	    case '2':
+	    case '3':
+	    case '4':
+	    case '5':
+	    case '6':
+	    case '7':
+	    case '8':
+	    case '9':
+	      anyDigits = 1;
+	      width = width * 10 + (*format - '0');
+	      format += 1;
+	      break;
+	    default:
+	      index = HYF_MAX_ARGS - ++result->immediateCount;
+	      result->spec[result->specCount].widthIndex = index;
+	      result->valueType[index] = HYFTYPE_IMMEDIATE;
+	      if (anyDigits)
+		{
+		  result->value[index].u64 = width;
+		}
+	      else
+		{
+		  result->value[index].u64 = HYF_NO_VALUE;
+		}
+	      return format;
+	    }
+	}
+    }
+}
+
+static const char *
+parsePrecision (const char *format, HyFormatData * result)
+{
+  U_8 index;
+
+  if (*format == '.')
+    {
+      format += 1;
+    }
+  else
+    {
+      index = HYF_MAX_ARGS - ++result->immediateCount;
+      result->spec[result->specCount].precisionIndex = index;
+      result->valueType[index] = HYFTYPE_IMMEDIATE;
+      result->value[index].u64 = HYF_NO_VALUE;
+
+      return format;
+    }
+
+  if (*format == '*')
+    {
+      format =
+	parseIndex (format + 1,
+		    &result->spec[result->specCount].precisionIndex);
+      index = result->spec[result->specCount].precisionIndex;
+      if (index == 0xFF)
+	{
+	  index = result->valueCount;
+	  result->spec[result->specCount].precisionIndex = index;
+	}
+      result->valueCount++;
+      result->valueType[index] = HYFTYPE_U32;
+      result->value[index].u64 = HYF_NO_VALUE;
+
+      return format;
+    }
+  else
+    {
+      U_32 precision = 0;
+      int anyDigits = 0;
+      for (;;)
+	{
+	  switch (*format)
+	    {
+	    case '0':
+	    case '1':
+	    case '2':
+	    case '3':
+	    case '4':
+	    case '5':
+	    case '6':
+	    case '7':
+	    case '8':
+	    case '9':
+	      anyDigits = 1;
+	      precision = precision * 10 + (*format - '0');
+	      format += 1;
+	      break;
+	    default:
+	      index = HYF_MAX_ARGS - ++result->immediateCount;
+	      result->spec[result->specCount].precisionIndex = index;
+	      result->valueType[index] = HYFTYPE_IMMEDIATE;
+	      if (anyDigits)
+		{
+		  result->value[index].u64 = precision;
+		}
+	      else
+		{
+		  result->value[index].u64 = HYF_NO_VALUE;
+		}
+	      return format;
+	    }
+	}
+    }
+}
+
+static const char *
+parseModifier (const char *format, HyFormatData * result)
+{
+  switch (*format)
+    {
+    case 'z':
+      format++;
+
+      break;
+    case 'l':
+      format++;
+      if (*format == 'l')
+	{
+	  format++;
+	  result->spec[result->specCount].tag |= HYFSPEC_LL;
+	}
+      else
+	{
+	  result->spec[result->specCount].tag |= HYFSPEC_L;
+	}
+      break;
+    }
+
+  return format;
+}
+
+static const char *
+parseType (const char *format, HyFormatData * result)
+{
+  const char *type = format++;
+  U_8 tag = result->spec[result->specCount].tag;
+  U_8 index = result->spec[result->specCount].index;
+
+  if (index == 0xFF)
+    {
+      index = result->valueCount;
+      result->spec[result->specCount].index = index;
+    }
+  result->valueCount++;
+
+  result->spec[result->specCount].type = type;
+
+  switch (*type)
+    {
+      /* integers */
+    case 'c':
+      result->valueType[index] = HYFTYPE_U32;
+      break;
+    case 'i':
+    case 'd':
+    case 'u':
+    case 'x':
+    case 'X':
+      result->valueType[index] = tag & HYFSPEC_LL ? HYFTYPE_U64 : HYFTYPE_U32;
+      break;
+
+      /* pointers */
+    case 'p':
+    case 's':
+      result->valueType[index] = HYFTYPE_PTR;
+      break;
+
+      /* floats */
+    case 'f':
+    case 'e':
+    case 'E':
+    case 'F':
+    case 'g':
+    case 'G':
+      result->valueType[index] = HYFTYPE_DBL;
+      break;
+
+    default:
+      return NULL;
+    }
+
+  return format;
+}
+
+static void
+readValues (struct HyPortLibrary *portLibrary, HyFormatData * result,
+	    va_list args)
+{
+  U_8 index;
+
+  for (index = 0; index < result->valueCount; index++)
+    {
+      switch (result->valueType[index])
+	{
+	case HYFTYPE_U64:
+	  result->value[index].u64 = va_arg (args, U_64);
+	  break;
+	case HYFTYPE_U32:
+	  result->value[index].u64 = va_arg (args, U_32);
+	  break;
+	case HYFTYPE_DBL:
+	  result->value[index].dbl = va_arg (args, double);
+	  break;
+	case HYFTYPE_PTR:
+	  result->value[index].ptr = va_arg (args, void *);
+	  break;
+	case HYFTYPE_IMMEDIATE:
+	  /* shouldn't be encountered -- these should all be at the end of the value array */
+	  break;
+	}
+    }
+}
+
+static I_32
+writeSpec (HyFormatData * data, HyFormatSpecifier * spec, char *result,
+	   U_32 length)
+{
+  HyFormatValue *value = &data->value[spec->index];
+  U_64 width = data->value[spec->widthIndex].u64;
+  U_64 precision = data->value[spec->precisionIndex].u64;
+  I_32 index = 0;
+
+  switch (*spec->type)
+    {
+    case 'i':
+    case 'd':
+      index =
+	writeIntToBuffer (result, length, width, precision, value->u64,
+			  spec->tag, 1, digits_dec);
+      break;
+    case 'u':
+      index =
+	writeIntToBuffer (result, length, width, precision, value->u64,
+			  spec->tag, 0, digits_dec);
+      break;
+    case 'x':
+      index =
+	writeIntToBuffer (result, length, width, precision, value->u64,
+			  spec->tag, 0, digits_hex_lower);
+      break;
+    case 'X':
+      index =
+	writeIntToBuffer (result, length, width, precision, value->u64,
+			  spec->tag, 0, digits_hex_upper);
+      break;
+
+    case 'p':
+      index =
+	writeIntToBuffer (result, length, sizeof (UDATA) * 2,
+			  sizeof (UDATA) * 2, (UDATA) value->ptr, 0, 0,
+			  digits_hex_upper);
+      break;
+
+    case 'c':
+      if (spec->tag & HYFSPEC_L)
+	{
+	  char asUTF8[4];
+	  U_32 numberWritten =
+	    encodeUTF8Char ((UDATA) value->u64, (U_8 *) asUTF8);
+
+	  /* what if width/precision is less than size of asUTF8? [truncate?] */
+	  asUTF8[numberWritten] = '\0';
+	  index =
+	    writeStringToBuffer (result, length, width, precision, asUTF8,
+				 spec->tag);
+	}
+      else
+	{
+	  index =
+	    writeStringToBuffer (result, length, width, precision, " ",
+				 spec->tag);
+	  if (index <= (I_32)length)
+	    {
+	      if (result)
+		{
+		  result[index - 1] = (char) value->u64;
+		}
+	    }
+	}
+      break;
+
+    case 's':
+      if (value->ptr)
+	{
+	  if (spec->tag & HYFSPEC_L)
+	    {
+	      index =
+		writeUnicodeStringToBuffer (result, length, width, precision,
+					    (const U_16 *) value->ptr,
+					    spec->tag);
+	    }
+	  else
+	    {
+	      index =
+		writeStringToBuffer (result, length, width, precision,
+				     (const char *) value->ptr, spec->tag);
+	    }
+	}
+      else
+	{
+	  index =
+	    writeStringToBuffer (result, length, width, precision, "<NULL>",
+				 spec->tag);
+	}
+      break;
+
+      /* floats */
+    case 'f':
+    case 'e':
+    case 'E':
+    case 'F':
+    case 'g':
+    case 'G':
+      index =
+	writeDoubleToBuffer (result, length, width, precision, value->dbl,
+			     *spec->type, spec->tag);
+      break;
+    }
+
+  return index;
+}
+
+static I_32
+writeIntToBuffer (char *buf, U_32 bufLen, U_64 width, U_64 precision,
+		  U_64 value, U_8 tag, int isSigned, const char *digits)
+{
+  U_32 index = 0;
+  U_32 length = 0;
+  I_32 rightSpace = 0;
+  U_64 temp;
+  int base = strlen (digits);
+  U_32 actualPrecision = 0;
+  char signChar = 0;
+
+  if (isSigned)
+    {
+      I_64 signedValue;
+      if (tag & HYFSPEC_LL)
+	{
+	  signedValue = (I_64) value;
+	}
+      else
+	{
+	  signedValue = (I_32) value;
+	}
+
+      if (signedValue < 0)
+	{
+	  signChar = '-';
+	  value = (U_64) (signedValue * -1);
+	}
+      else if (signedValue >= 0 && (tag & HYFFLAG_PLUS))
+	{
+	  signChar = '+';
+	}
+    }
+
+  /* find the end of the number */
+  temp = value;
+  do
+    {
+      length++;
+      temp /= base;
+    }
+  while (temp);
+
+  if (precision != HYF_NO_VALUE)
+    {
+      actualPrecision = (I_32) precision;
+      if (actualPrecision > length)
+	{
+	  length = actualPrecision;
+	}
+    }
+
+  /* Account for "-" Must be after setting actualPrecision, before calculation of rightSpace */
+  if (signChar)
+    {
+      length++;
+    }
+
+  if (width != HYF_NO_VALUE && (I_32) width > length)
+    {
+      if (tag & HYFFLAG_DASH)
+	{
+	  rightSpace = (I_32) width - length;
+	}
+      length = (I_32) width;
+    }
+
+  if (tag & HYFFLAG_ZERO)
+    {
+      actualPrecision = length - (signChar ? 1 : 0);
+    }
+
+  /* now write the number out backwards */
+  for (; rightSpace > 0; rightSpace--)
+    {
+      length -= 1;
+      if (bufLen > length)
+	{
+	  if (buf)
+	    {
+	      buf[length] = ' ';
+	    }
+	  index += 1;
+	}
+    }
+
+  /* write out the digits */
+  temp = value;
+  do
+    {
+      length -= 1;
+      actualPrecision -= 1;
+      if (bufLen > length)
+	{
+	  if (buf)
+	    {
+	      buf[length] = digits[(int) (temp % base)];
+	    }
+	  index += 1;
+	}
+      temp /= base;
+    }
+  while (temp);
+
+  /* zero extend to the left according the the requested precision */
+  while (length > 0)
+    {
+      length -= 1;
+      actualPrecision -= 1;
+      if (bufLen > length)
+	{
+	  if (buf)
+	    {
+	      if (actualPrecision >= 0)
+		{
+		  buf[length] = '0';
+		}
+	      else
+		{
+		  if (signChar)
+		    {
+		      buf[length] = signChar;
+		      /* only print the sign char once */
+		      signChar = 0;
+		    }
+		  else
+		    {
+		      buf[length] = ' ';
+		    }
+		}
+	    }
+	  index += 1;
+	}
+    }
+
+  return index;
+}
+
+static I_32
+writeStringToBuffer (char *buf, U_32 bufLen, U_64 width, U_64 precision,
+		     const char *value, U_8 tag)
+{
+  size_t leftPadding = 0;
+  size_t rightPadding = 0;
+
+  if (precision == HYF_NO_VALUE)
+    {
+      precision = strlen (value);
+    }
+  else
+    {
+      I_32 n;
+      /* detect if the string is shorter than precision */
+      for (n = 0; n < precision; n++)
+	{
+	  if (value[n] == 0)
+	    {
+	      precision = n;
+	      break;
+	    }
+	}
+    }
+
+  if (width == HYF_NO_VALUE)
+    {
+      width = precision;
+    }
+
+  if (width > precision)
+    {
+      if (tag & HYFFLAG_DASH)
+	{
+	  rightPadding = (size_t) (width - precision);
+	}
+      else
+	{
+	  leftPadding = (size_t) (width - precision);
+	}
+    }
+
+  if (leftPadding > bufLen)
+    {
+      leftPadding = bufLen;
+    }
+  if (buf)
+    {
+      memset (buf, ' ', leftPadding);
+      buf += leftPadding;
+    }
+  bufLen -= leftPadding;
+
+  if (precision > bufLen)
+    {
+      precision = bufLen;
+    }
+  if (buf)
+    {
+      memcpy (buf, value, (size_t) precision);
+      buf += (size_t) precision;
+    }
+  bufLen -= (size_t) precision;
+
+  if (rightPadding > bufLen)
+    {
+      rightPadding = bufLen;
+    }
+  if (buf)
+    {
+      memset (buf, ' ', rightPadding);
+      buf += rightPadding;
+    }
+
+  return (I_32) (leftPadding + (size_t) precision + rightPadding);
+}
+
+/*
+ * To determine size of buffer required for format string pass in a NULL buffer and the maximum
+ * size willing to create.  For example for no restrictions result=NULL, length=(U_32)(-1), to restrict
+ * the buffer to 2k, result=NULL, length=2048
+ *
+ * Value returned does not include space required for the null terminator
+ */
+static U_32
+writeFormattedString (struct HyPortLibrary *portLibrary, HyFormatData * data,
+		      char *result, U_32 length)
+{
+  const char *format = data->formatString;
+  U_8 specIndex = 0;
+  U_32 index = 0;
+
+  if (NULL == result)
+    {
+      length = (U_32) - 1;
+    }
+  else if (0 == length)
+    {
+      /* empty buffer */
+      return 0;
+    }
+
+  while (*format && index < length - 1)
+    {
+      switch (*format)
+	{
+	case '%':
+	  format++;
+	  switch (*format)
+	    {
+	    case '%':
+	      /* literal '%' */
+	      if (result)
+		{
+		  result[index] = '%';
+		}
+	      index++;
+	      format++;
+	      break;
+	    default:
+	      if (result)
+		{
+		  index +=
+		    writeSpec (data, &data->spec[specIndex], result + index,
+			       length - index);
+		}
+	      else
+		{
+		  index +=
+		    writeSpec (data, &data->spec[specIndex], result, length);
+		}
+
+	      format = data->spec[specIndex].type + 1;
+	      specIndex += 1;
+	      break;
+	    }
+	  break;
+	default:
+	  if (result)
+	    {
+	      result[index] = *format;
+	    }
+	  *format++;
+	  index++;
+	}
+    }
+
+  /* writeSpec can return value > 1, so index does not increment sequentially */
+  if (index > length - 1)
+    {
+      index = length - 1;
+    }
+
+  if (result)
+    {
+      result[index] = 0;
+    }
+
+  if (NULL == result)
+    {
+      return index + 1;		/* For the NUL terminator */
+    }
+
+  return index;
+}
+
+static I_32
+writeDoubleToBuffer (char *buf, U_32 bufLen, U_64 width, U_64 precision,
+		     double value, U_8 type, U_8 tag)
+{
+  char format[sizeof ("%+4294967295.4294967295f")];
+  char *formatCursor = format;
+  char *lastFormat = format + sizeof (format);
+  char tempBuf[510];		/* 509 is maximum size of a converted double */
+
+  *formatCursor++ = '%';
+
+  if (tag & HYFFLAG_DASH)
+    {
+      *formatCursor++ = '-';
+    }
+  else if (tag & HYFFLAG_PLUS)
+    {
+      *formatCursor++ = '+';
+    }
+  else if (tag & HYFFLAG_SPACE)
+    {
+      *formatCursor++ = ' ';
+    }
+  else if (tag & HYFFLAG_ZERO)
+    {
+      *formatCursor++ = '0';
+    }
+  else if (tag & HYFFLAG_HASH)
+    {
+      *formatCursor++ = '#';
+    }
+
+  if (width != HYF_NO_VALUE)
+    {
+      formatCursor +=
+	writeIntToBuffer (formatCursor, lastFormat - formatCursor,
+			  HYF_NO_VALUE, HYF_NO_VALUE, width, 'u', 0,
+			  digits_dec);
+    }
+  if (precision != HYF_NO_VALUE)
+    {
+      *formatCursor++ = '.';
+      formatCursor +=
+	writeIntToBuffer (formatCursor, lastFormat - formatCursor,
+			  HYF_NO_VALUE, HYF_NO_VALUE, precision, 'u', 0,
+			  digits_dec);
+    }
+
+  *formatCursor++ = type;
+  *formatCursor++ = '\0';
+
+  sprintf (tempBuf, format, value);
+
+  if (buf)
+    {
+      strncpy (buf, tempBuf, bufLen);
+      buf[bufLen - 1] = '\0';
+      return strlen (buf);
+    }
+
+  return strlen (tempBuf);
+}
+
+/**
+ * PortLibrary shutdown.
+ *
+ * This function is called during shutdown of the portLibrary.  Any resources that were created by @ref hystr_startup
+ * should be destroyed here.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @note Most implementations will be empty.
+ */
+void VMCALL
+hystr_shutdown (struct HyPortLibrary *portLibrary)
+{
+  /* empty */
+}
+
+/**
+ * PortLibrary startup.
+ *
+ * This function is called during startup of the portLibrary.  Any resources that are required for
+ * the string operations may be created here.  All resources created here should be destroyed
+ * in @ref hystr_shutdown.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return 0 on success, negative error code on failure.  Error code values returned are
+ * \arg HYPORT_ERROR_STARTUP_STR
+ *
+ * @note Most implementations will simply return success.
+ */
+I_32 VMCALL
+hystr_startup (struct HyPortLibrary *portLibrary)
+{
+  return 0;
+}
+
+static I_32
+writeUnicodeStringToBuffer (char *buf, U_32 bufLen, U_64 width,
+			    U_64 precision, const U_16 * value, U_8 tag)
+{
+  U_32 numberOfUnicodeChar = 0;
+  U_32 numberOfUTF8Char = 0;
+  U_32 encodingLength;
+  size_t leftPadding = 0;
+  size_t rightPadding = 0;
+  const U_16 *currentU16;
+
+  if (precision == HYF_NO_VALUE)
+    {
+      currentU16 = value;
+      precision = 0;
+      while (*currentU16++ != 0)
+	{
+	  precision++;
+	}
+    }
+  else
+    {
+      I_32 n;
+      /* detect if the string is shorter than precision */
+      for (n = 0; n < precision; n++)
+	{
+	  if (value[n] == 0)
+	    {
+	      precision = n;
+	      break;
+	    }
+	}
+    }
+
+  currentU16 = value;
+  while (numberOfUnicodeChar < precision)
+    {
+
+      encodingLength = encodeUTF8Char ((UDATA) * currentU16++, NULL);
+      if (numberOfUTF8Char + encodingLength > bufLen)
+	{
+	  break;
+	}
+
+      /* If the character fits then increment counts */
+      numberOfUnicodeChar++;
+      numberOfUTF8Char += encodingLength;
+    }
+
+  if (width == HYF_NO_VALUE)
+    {
+      width = numberOfUTF8Char;
+    }
+
+  if (width > numberOfUTF8Char)
+    {
+      if (tag & HYFFLAG_DASH)
+	{
+	  rightPadding = (size_t) (width - numberOfUTF8Char);
+	}
+      else
+	{
+	  leftPadding = (size_t) (width - numberOfUTF8Char);
+	}
+    }
+
+  if (leftPadding > bufLen)
+    {
+      leftPadding = bufLen;
+    }
+  if (buf)
+    {
+      memset (buf, ' ', leftPadding);
+      buf += leftPadding;
+    }
+  bufLen -= leftPadding;
+
+  /* The space required for the UTF8 chars is guaranteed to be there */
+  if (buf)
+    {
+      currentU16 = value;
+      while (numberOfUnicodeChar-- > 0)
+	{
+	  buf += encodeUTF8Char ((UDATA) * currentU16++, buf);
+	}
+    }
+  bufLen -= numberOfUTF8Char;
+
+  if (rightPadding > bufLen)
+    {
+      rightPadding = bufLen;
+    }
+  if (buf)
+    {
+      memset (buf, ' ', rightPadding);
+      buf += rightPadding;
+    }
+
+  return (I_32) (leftPadding + numberOfUTF8Char + rightPadding);
+}
+
+static const char *
+parseIndex (const char *format, U_8 * result)
+{
+  const char *start = format;
+  U_8 index = 0;
+
+  for (;;)
+    {
+      switch (*format)
+	{
+	case '0':
+	case '1':
+	case '2':
+	case '3':
+	case '4':
+	case '5':
+	case '6':
+	case '7':
+	case '8':
+	case '9':
+	  index = index * 10 + (*format - '0');
+	  format += 1;
+	  break;
+	case '$':
+	  if (index > 0)
+	    {
+	      *result = index - 1;
+	      return format + 1;
+	    }
+	  /* fall through */
+	default:
+	  *result = 0xFF;
+	  return start;
+	}
+    }
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hystrftime.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hystrftime.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hystrftime.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hystrftime.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,363 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * @ingroup Port
+ * @brief Time formatting utilities.
+ */
+
+#include <string.h>
+#include "hycomp.h"
+#include "hyport.h"
+
+typedef struct HyTimeInfo
+{
+  U_32 second;
+  U_32 minute;
+  U_32 hour;
+  U_32 day;
+  U_32 month;
+  U_32 year;
+} HyTimeInfo;
+
+static void gettimestruct (I_64 millis, struct HyTimeInfo *tm);
+
+/**
+ * Returns the current time in as a formatted string.  Formatted according to the 'format' parameter.
+ *
+ * @param[in] portLibrary  The port library.
+ * @param[in,out] buf A pointer to a character buffer where the resulting time string will be stored.
+ * @param[in] bufLen The length of the 'buf' character buffer.
+ * @param[in] format The format string, ordinary characters placed in the format string are copied.
+ * to buf without conversion.  Conversion specifiers are introduced by a '%' character, and are replaced in buf as follows:.
+ * <ul>
+ * <li>%b The abbreviated month name in english
+ * <li>%d The  day  of the month as a decimal number (range 0 to 31).
+ * <li>%H The hour as a decimal number using a 24-hour  clock (range 00 to 23).
+ * <li>%m The month as a decimal number (range 01 to 12).
+ * <li>%M The minute as a decimal number.
+ * <li>%S The second as a decimal number.
+ * <li>%Y The year as a decimal number including the century.
+ * <li>%% A literal '%' character.
+ * <li>all other '%' specifiers will be ignored
+ * </ul>
+ *
+ * @return The number of characters placed in the array buf, not including NULL terminator.
+ * If the value equals 'bufLen', it means that the array was too small.
+ */
+U_32 VMCALL
+hystrftime (struct HyPortLibrary *portLibrary, char *buf, U_32 bufLen,
+	    const char *format)
+{
+  I_64 millis;
+  U_32 index = 0;
+  HyTimeInfo tm;
+  static const char abbMonthName[12][4] =
+    { "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT",
+"NOV", "DEC" };
+
+  if (buf == NULL || bufLen < 1)
+    {
+      return 0;
+    }
+
+  millis = portLibrary->time_current_time_millis (portLibrary);
+
+  gettimestruct (millis, &tm);
+
+  /* format the date/time information according to the format string */
+  while (*format && index < bufLen - 1)
+    {
+      switch (*format)
+	{
+	case '%':
+	  format++;
+	  switch (*format)
+	    {
+	    case '\0':
+	      /* end of the format string */
+	      break;
+	    case '%':
+	      /* literal '%' */
+	      buf[index] = '%';
+	      index++;
+	      format++;
+	      break;
+	    case 'Y':
+	      if (index + 4 >= bufLen - 1)
+		{
+		  return bufLen;
+		}
+	      index +=
+		portLibrary->str_printf (portLibrary, buf + index,
+					 bufLen - index, "%04u", tm.year);
+	      format++;
+	      break;
+	    case 'm':
+	      if (index + 2 >= bufLen - 1)
+		{
+		  return bufLen;
+		}
+	      index +=
+		portLibrary->str_printf (portLibrary, buf + index,
+					 bufLen - index, "%02u", tm.month);
+	      format++;
+	      break;
+	    case 'b':
+	      if (index + strlen (abbMonthName[tm.month - 1]) >= bufLen - 1)
+		{
+		  return bufLen;
+		}
+	      index +=
+		portLibrary->str_printf (portLibrary, buf + index,
+					 bufLen - index, "%s",
+					 abbMonthName[tm.month - 1]);
+	      format++;
+	      break;
+	    case 'd':
+	      if (index + 2 >= bufLen - 1)
+		{
+		  return bufLen;
+		}
+	      index +=
+		portLibrary->str_printf (portLibrary, buf + index,
+					 bufLen - index, "%02u", tm.day);
+	      format++;
+	      break;
+	    case 'H':
+	      if (index + 2 >= bufLen - 1)
+		{
+		  return bufLen;
+		}
+	      index +=
+		portLibrary->str_printf (portLibrary, buf + index,
+					 bufLen - index, "%02u", tm.hour);
+	      format++;
+	      break;
+	    case 'M':
+	      if (index + 2 >= bufLen - 1)
+		{
+		  return bufLen;
+		}
+	      index +=
+		portLibrary->str_printf (portLibrary, buf + index,
+					 bufLen - index, "%02u", tm.minute);
+	      format++;
+	      break;
+	    case 'S':
+	      if (index + 2 >= bufLen - 1)
+		{
+		  return bufLen;
+		}
+	      index +=
+		portLibrary->str_printf (portLibrary, buf + index,
+					 bufLen - index, "%02u", tm.second);
+	      format++;
+	      break;
+	    default:
+	      /* ignore unsupported format specifiers */
+	      format++;
+	      break;
+	    }
+	  break;
+	default:
+	  buf[index] = *format++;
+	  index++;
+	  break;
+	}
+    }
+
+  buf[index] = 0;
+
+  return index;
+}
+
+static void
+gettimestruct (I_64 millis, struct HyTimeInfo *tm)
+{
+#define HYSFT_NUM_MONTHS         (12)
+#define HYSFT_NUM_SECS_IN_MINUTE (60)
+#define HYSFT_NUM_SECS_IN_HOUR   (60*HYSFT_NUM_SECS_IN_MINUTE)
+#define HYSFT_NUM_SECS_IN_DAY    (24*(I_32)HYSFT_NUM_SECS_IN_HOUR)
+#define HYSFT_NUM_SECS_IN_YEAR   (365*HYSFT_NUM_SECS_IN_DAY)
+#define HYSFT_NUM_SECS_IN_LEAP_YEAR (366*HYSFT_NUM_SECS_IN_DAY)
+#define HYSFT_NUM_SECS_IN_JAN (31*HYSFT_NUM_SECS_IN_DAY)
+#define HYSFT_NUM_SECS_IN_FEB (28*HYSFT_NUM_SECS_IN_DAY)
+#define HYSFT_NUM_SECS_IN_MAR (31*HYSFT_NUM_SECS_IN_DAY)
+#define HYSFT_NUM_SECS_IN_APR (30*HYSFT_NUM_SECS_IN_DAY)
+#define HYSFT_NUM_SECS_IN_MAY (31*HYSFT_NUM_SECS_IN_DAY)
+#define HYSFT_NUM_SECS_IN_JUN (30*HYSFT_NUM_SECS_IN_DAY)
+#define HYSFT_NUM_SECS_IN_JUL (31*HYSFT_NUM_SECS_IN_DAY)
+#define HYSFT_NUM_SECS_IN_AUG (31*HYSFT_NUM_SECS_IN_DAY)
+#define HYSFT_NUM_SECS_IN_SEP (30*HYSFT_NUM_SECS_IN_DAY)
+#define HYSFT_NUM_SECS_IN_OCT (31*HYSFT_NUM_SECS_IN_DAY)
+#define HYSFT_NUM_SECS_IN_NOV (30*HYSFT_NUM_SECS_IN_DAY)
+#define HYSFT_NUM_SECS_IN_DEC (31*HYSFT_NUM_SECS_IN_DAY)
+#define HYSFT_NUM_SECS_IN_LEAP_FEB (29*HYSFT_NUM_SECS_IN_DAY)
+
+  I_64 timeLeft;
+  I_32 i;
+  I_32 *secondsInMonth;
+  I_32 normalSecondsInMonth[12] = {
+    HYSFT_NUM_SECS_IN_JAN,
+    HYSFT_NUM_SECS_IN_FEB,
+    HYSFT_NUM_SECS_IN_MAR,
+    HYSFT_NUM_SECS_IN_APR,
+    HYSFT_NUM_SECS_IN_MAY,
+    HYSFT_NUM_SECS_IN_JUN,
+    HYSFT_NUM_SECS_IN_JUL,
+    HYSFT_NUM_SECS_IN_AUG,
+    HYSFT_NUM_SECS_IN_SEP,
+    HYSFT_NUM_SECS_IN_OCT,
+    HYSFT_NUM_SECS_IN_NOV,
+    HYSFT_NUM_SECS_IN_DEC
+  };
+  I_32 leapYearSecondsInMonth[12] = {
+    HYSFT_NUM_SECS_IN_JAN,
+    HYSFT_NUM_SECS_IN_LEAP_FEB,
+    HYSFT_NUM_SECS_IN_MAR,
+    HYSFT_NUM_SECS_IN_APR,
+    HYSFT_NUM_SECS_IN_MAY,
+    HYSFT_NUM_SECS_IN_JUN,
+    HYSFT_NUM_SECS_IN_JUL,
+    HYSFT_NUM_SECS_IN_AUG,
+    HYSFT_NUM_SECS_IN_SEP,
+    HYSFT_NUM_SECS_IN_OCT,
+    HYSFT_NUM_SECS_IN_NOV,
+    HYSFT_NUM_SECS_IN_DEC
+  };
+  BOOLEAN leapYear = FALSE;
+
+  if (!tm)
+    return;
+
+  memset (tm, 0, sizeof (struct HyTimeInfo));
+
+  tm->year = 1970;
+
+  /* -- obtain the current time in seconds */
+  timeLeft = millis / 1000;
+  /* -- determine the year */
+  while (timeLeft)
+    {
+      I_64 numSecondsInAYear = HYSFT_NUM_SECS_IN_YEAR;
+      leapYear = FALSE;
+      if (tm->year % 4 == 0)
+	{
+	  /* potential leap year */
+	  if ((tm->year % 100 != 0) || (tm->year % 400 == 0))
+	    {
+	      /* we have leap year! */
+	      leapYear = TRUE;
+	      numSecondsInAYear = HYSFT_NUM_SECS_IN_LEAP_YEAR;
+	    }
+	}
+      if (timeLeft < numSecondsInAYear)
+	{
+	  /* under a year's time left */
+	  break;
+	}
+      /* increment the year and take the appropriate number 
+         of seconds off the timeLeft */
+      tm->year++;
+      timeLeft -= numSecondsInAYear;
+    }
+  /* -- determine the month */
+  if (leapYear)
+    {
+      secondsInMonth = leapYearSecondsInMonth;
+    }
+  else
+    {
+      secondsInMonth = normalSecondsInMonth;
+    }
+  for (i = 0; i < HYSFT_NUM_MONTHS; i++)
+    {
+      if (timeLeft >= secondsInMonth[i])
+	{
+	  timeLeft -= secondsInMonth[i];
+	}
+      else
+	{
+	  break;
+	}
+    }
+  tm->month = i + 1;
+  /* -- determine the day of the month */
+  tm->day = 1;
+  while (timeLeft)
+    {
+      if (timeLeft >= HYSFT_NUM_SECS_IN_DAY)
+	{
+	  timeLeft -= HYSFT_NUM_SECS_IN_DAY;
+	}
+      else
+	{
+	  break;
+	}
+      tm->day++;
+    }
+  /* -- determine the hour of the day */
+  tm->hour = 0;
+  while (timeLeft)
+    {
+      if (timeLeft >= HYSFT_NUM_SECS_IN_HOUR)
+	{
+	  timeLeft -= HYSFT_NUM_SECS_IN_HOUR;
+	}
+      else
+	{
+	  break;
+	}
+      tm->hour++;
+    }
+  /* -- determine the minute of the hour */
+  tm->minute = 0;
+  while (timeLeft)
+    {
+      if (timeLeft >= HYSFT_NUM_SECS_IN_MINUTE)
+	{
+	  timeLeft -= HYSFT_NUM_SECS_IN_MINUTE;
+	}
+      else
+	{
+	  break;
+	}
+      tm->minute++;
+    }
+  /* -- and the rest is seconds */
+  tm->second = (U_32) timeLeft;
+
+#undef HYSFT_NUM_MONTHS
+#undef HYSFT_NUM_SECS_IN_MINUTE
+#undef HYSFT_NUM_SECS_IN_HOUR
+#undef HYSFT_NUM_SECS_IN_DAY
+#undef HYSFT_NUM_SECS_IN_YEAR
+#undef HYSFT_NUM_SECS_IN_LEAP_YEAR
+#undef HYSFT_NUM_SECS_IN_JAN
+#undef HYSFT_NUM_SECS_IN_FEB
+#undef HYSFT_NUM_SECS_IN_MAR
+#undef HYSFT_NUM_SECS_IN_APR
+#undef HYSFT_NUM_SECS_IN_MAY
+#undef HYSFT_NUM_SECS_IN_JUN
+#undef HYSFT_NUM_SECS_IN_JUL
+#undef HYSFT_NUM_SECS_IN_AUG
+#undef HYSFT_NUM_SECS_IN_SEP
+#undef HYSFT_NUM_SECS_IN_OCT
+#undef HYSFT_NUM_SECS_IN_NOV
+#undef HYSFT_NUM_SECS_IN_DEC
+#undef HYSFT_NUM_SECS_IN_LEAP_FEB
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hystsl.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hystsl.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hystsl.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hystsl.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,238 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * @ingroup Port
+ * @brief Static shared library
+ */
+#include <string.h>
+#include <stdlib.h>
+#include "hyport.h"
+
+#if defined(HYVM_STATIC_LINKAGE)
+#include "hystatic.h"
+extern HyPrimitiveTable HyLinkedNatives;
+void *
+upLookupName (char *name, HyPrimitiveTableSlot * table)
+{
+  void *result;
+  while (!((table->name == (char *) 0) && (table->funcOrTable == (void *) 0)))
+    {
+      if (table->name == (char *) 0)
+	{
+	  result =
+	    upLookupName (name,
+			  (HyPrimitiveTableSlot *) (table->funcOrTable));
+	  if (result != (void *) 0 /*HyDefaultFailPrimitive */ )
+	    return result;
+	}
+      else
+	{
+	  if (strcmp (name, table->name) == 0)
+	    return table->funcOrTable;
+	}
+      table++;
+    }
+  return (void *) 0 /*HyDefaultFailPrimitive */ ;
+}
+
+/**
+ * Close a static library.
+ *
+ * @param[in] portLibrary The port library.
+ * @param[in] descriptor Static library handle to close.
+ *
+ * @return 0 on success, any other value on failure.
+ */
+UDATA VMCALL
+hysl_up_close_shared_library (struct HyPortLibrary *portLibrary,
+			      UDATA descriptor)
+{
+  return 0;
+}
+
+/** 
+ * Opens a static library .
+ *
+ * @param[in] portLibrary The port library.
+ * @param[in] name path Null-terminated string containing the static library.
+ * @param[out] descriptor Pointer to memory which is filled in with static-library handle on success.
+ * @param[in] decorate Boolean value indicates whether name should be decorated if it contains path information and cannot be found.
+ *
+ * @return 0 on success, any other value on failure.
+ *
+ * @note contents of descriptor are undefined on failure.
+ */
+UDATA VMCALL
+hysl_up_open_shared_library (struct HyPortLibrary * portLibrary, char *name,
+			     UDATA * descriptor, BOOLEAN decorate)
+{
+  void *result;
+  if (result = upLookupName (name, &HyLinkedNatives[0]))
+    {
+      *descriptor = (UDATA) result;
+      return 0;
+    }
+  else
+    {
+      return portLibrary->error_set_last_error_with_message (portLibrary,
+							     HYPORT_SL_NOT_FOUND,
+							     "Not statically linked");
+    }
+}
+
+/**
+ * Search for a function named 'name' taking argCount in the static library 'descriptor'.
+ *
+ * @param[in] portLibrary The port library.
+ * @param[in] descriptor Static library to search.
+ * @param[in] name Function to look up.
+ * @param[out] func Pointer to the function.
+ * @param[in] argSignature Argument signature.
+ *
+ * @return 0 on success, any other value on failure.
+ *
+ * @note contents of func are undefined on failure.
+ */
+UDATA VMCALL
+hysl_up_lookup_name (struct HyPortLibrary * portLibrary, UDATA descriptor,
+		     char *name, UDATA * func, const char *argSignature)
+{
+  void *result;
+  if (result = upLookupName (name, (HyPrimitiveTableSlot *) descriptor))
+    {
+      *func = (UDATA) result;
+      return 0;
+    }
+  else
+    {
+      return 1;
+    }
+}
+typedef struct
+{
+  UDATA descriptor;
+  UDATA tag;
+} hysplit_sl_handle;
+#define HYFLAG_SL_LINKED 0
+#define HYFLAG_SL_LOADED 1
+/* support BOTH types of libraries */
+/** 
+ * Opens a static/shared library .
+ *
+ * @param[in] portLibrary The port library.
+ * @param[in] name path Null-terminated string containing the library.
+ * @param[out] descriptor Pointer to memory which is filled in with library handle on success.
+ * @param[in] decorate Boolean value indicates whether name should be decorated if it contains path information and cannot be found.
+ *
+ * @return 0 on success, any other value on failure.
+ *
+ * @note contents of descriptor are undefined on failure.
+ */
+UDATA VMCALL
+hysl_split_open_shared_library (struct HyPortLibrary *portLibrary, char *name,
+				UDATA * descriptor, BOOLEAN decorate)
+{
+  UDATA result;
+  UDATA tag;
+  tag = HYFLAG_SL_LINKED;
+  result =
+    hysl_up_open_shared_library (portLibrary, name, descriptor, decorate);
+  if (result == HYPORT_SL_NOT_FOUND)
+    {
+      result =
+	hysl_open_shared_library (portLibrary, name, descriptor, decorate);
+      tag = HYFLAG_SL_LOADED;
+    }
+  if (result == 0)
+    {
+      hysplit_sl_handle *handle;
+      handle =
+	portLibrary->mem_allocate_memory (portLibrary,
+					  sizeof (hysplit_sl_handle));
+      if (handle == NULL)
+	{
+	  if (tag == HYFLAG_SL_LOADED)
+	    {
+	      hysl_close_shared_library (portLibrary, *descriptor);
+	    }
+	  return portLibrary->error_set_last_error_with_message (portLibrary,
+								 HYPORT_SL_INVALID,
+								 "Out of memory");
+	}
+      handle->descriptor = *descriptor;
+      handle->tag = tag;
+      *descriptor = (UDATA) handle;
+    }
+  return result;
+}
+
+/**
+ * Close a static or shared library.
+ *
+ * @param[in] portLibrary The port library.
+ * @param[in] descriptor Library handle to close.
+ *
+ * @return 0 on success, any other value on failure.
+ */
+UDATA VMCALL
+hysl_split_close_shared_library (struct HyPortLibrary * portLibrary,
+				 UDATA descriptor)
+{
+  hysplit_sl_handle *handle = (hysplit_sl_handle *) descriptor;
+  UDATA result;
+  if (handle->tag == HYFLAG_SL_LOADED)
+    {
+      result = hysl_close_shared_library (portLibrary, handle->descriptor);
+    }
+  else
+    {
+      result = hysl_up_close_shared_library (portLibrary, handle->descriptor);
+    }
+  portLibrary->mem_free_memory (portLibrary, handle);
+  return result;
+}
+
+/**
+ * Search for a function named 'name' taking argCount in the static/shared library 'descriptor'.
+ *
+ * @param[in] portLibrary The port library.
+ * @param[in] descriptor Library to search.
+ * @param[in] name Function to look up.
+ * @param[out] func Pointer to the function.
+ * @param[in] argSignature Argument signature.
+ *
+ * @return 0 on success, any other value on failure.
+ *
+ * @note contents of func are undefined on failure.
+ */
+UDATA VMCALL
+hysl_split_lookup_name (struct HyPortLibrary * portLibrary, UDATA descriptor,
+			char *name, UDATA * func, const char *argSignature)
+{
+  hysplit_sl_handle *handle = (hysplit_sl_handle *) descriptor;
+  if (handle->tag == HYFLAG_SL_LOADED)
+    {
+      return hysl_lookup_name (portLibrary, handle->descriptor, name, func,
+			       argSignature);
+    }
+  else
+    {
+      return hysl_up_lookup_name (portLibrary, handle->descriptor, name, func,
+				  argSignature);
+    }
+}
+#endif

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hysysinfo.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hysysinfo.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hysysinfo.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hysysinfo.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,601 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define CDEV_CURRENT_FUNCTION _comment_
+/**
+ * @file
+ * @ingroup Port
+ * @brief System information
+ */
+#undef CDEV_CURRENT_FUNCTION
+
+#include <stdio.h>
+#include <windows.h>
+#include "portpriv.h"
+#include "hyportpg.h"
+
+/* Missing from the ALPHA include files */
+#if !defined(VER_PLATFORM_WIN32_WINDOWS)
+#define VER_PLATFORM_WIN32_WINDOWS 1
+#endif
+
+#define CDEV_CURRENT_FUNCTION _prototypes_private
+/* none */
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION _prototypes_public
+IDATA VMCALL hysysinfo_get_executable_name (struct HyPortLibrary *
+					    portLibrary, char *argv0,
+					    char **result);
+const char *VMCALL hysysinfo_get_OS_type (struct HyPortLibrary *portLibrary);
+U_64 VMCALL hysysinfo_get_physical_memory (struct HyPortLibrary *portLibrary);
+UDATA VMCALL hysysinfo_DLPAR_max_CPUs (struct HyPortLibrary *portLibrary);
+UDATA VMCALL hysysinfo_get_number_CPUs (struct HyPortLibrary *portLibrary);
+const char *VMCALL hysysinfo_get_CPU_architecture (struct HyPortLibrary
+						   *portLibrary);
+UDATA VMCALL hysysinfo_get_processing_capacity (struct HyPortLibrary
+						*portLibrary);
+const char *VMCALL hysysinfo_get_OS_version (struct HyPortLibrary
+					     *portLibrary);
+I_32 VMCALL hysysinfo_startup (struct HyPortLibrary *portLibrary);
+UDATA VMCALL hysysinfo_DLPAR_enabled (struct HyPortLibrary *portLibrary);
+void VMCALL hysysinfo_shutdown (struct HyPortLibrary *portLibrary);
+UDATA VMCALL hysysinfo_get_pid (struct HyPortLibrary *portLibrary);
+U_16 VMCALL hysysinfo_get_classpathSeparator (struct HyPortLibrary
+					      *portLibrary);
+IDATA VMCALL hysysinfo_get_username (struct HyPortLibrary *portLibrary,
+				     char *buffer, UDATA length);
+UDATA VMCALL hysysinfo_weak_memory_consistency (struct HyPortLibrary
+						*portLibrary);
+IDATA VMCALL hysysinfo_get_env (struct HyPortLibrary *portLibrary,
+				char *envVar, char *infoString,
+				UDATA bufSize);
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_get_CPU_architecture
+/**
+ * Determine the CPU architecture.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return A null-terminated string describing the CPU architecture of the hardware, NULL on error.
+ * 
+ * @note portLibrary is responsible for allocation/deallocation of returned buffer.
+ * @note See http://www.tolstoy.com/samizdat/sysprops.html for good values to return.
+ */
+const char *VMCALL
+hysysinfo_get_CPU_architecture (struct HyPortLibrary *portLibrary)
+{
+#if defined(_ALPHA_)
+  return HYPORT_ARCH_ALPHA;
+#elif defined(_ARM_)
+  return HYPORT_ARCH_ARM;
+#elif defined( _MIPS_)
+  return HYPORT_ARCH_MIPS;
+#elif defined(_PPC_)
+  return HYPORT_ARCH_PPC;
+#elif defined( _SH4_)
+  return HYPORT_ARCH_SH4;
+#elif defined( _SH3_)
+  return HYPORT_ARCH_SH3;
+#elif defined(_X86_)
+  return HYPORT_ARCH_X86;
+#elif defined( _AMD64_)
+  return HYPORT_ARCH_HAMMER;
+#else
+  return "unknown";
+#endif
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_get_env
+/**
+ * Query the operating system for environment variables.
+ *
+ * Obtain the value of the environment variable specified by envVar from the operating system 
+ * and write out to supplied buffer.
+ *
+ * @param[in] portLibrary The port library.
+ * @param[in] envVar Environment variable to query.
+ * @param[out] infoString Buffer for value string describing envVar.
+ * @param[in] bufSize Size of buffer to hold returned string.
+ *
+ * @return 0 on success, number of bytes required to hold the 
+ *	information if the output buffer was too small, -1 on failure.
+ *
+ * @note infoString is undefined on error or when supplied buffer was too small.
+ */
+IDATA VMCALL
+hysysinfo_get_env (struct HyPortLibrary * portLibrary, char *envVar,
+		   char *infoString, UDATA bufSize)
+{
+  DWORD rc;
+
+  rc = GetEnvironmentVariable (envVar, infoString, bufSize);
+
+  /* If the function succeeds, the return value is the number of characters stored into 
+     the buffer, not including the terminating null character. If the specified environment 
+     variable name was not found in the environment block for the current process, the 
+     return value is zero. 
+
+     If the buffer pointed to by lpBuffer is not large enough, the return value is the buffer 
+     size, in characters, required to hold the value string and its terminating null character. 
+   */
+
+  if (rc > bufSize)
+    {
+      return rc;
+    }
+  else if (rc == 0)
+    {
+      return -1;
+    }
+  else
+    {
+      return 0;			/* success */
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_get_OS_type
+/**
+ * Determine the OS type.
+ * 
+ * @param[in] portLibrary The port library.
+ *
+ * @return OS type string (NULL terminated) on success, NULL on error.
+ *
+ * @note portLibrary is responsible for allocation/deallocation of returned buffer.
+ */
+const char *VMCALL
+hysysinfo_get_OS_type (struct HyPortLibrary *portLibrary)
+{
+  if (NULL == PPG_si_osType)
+    {
+      OSVERSIONINFOEX versionInfo;
+
+      versionInfo.dwOSVersionInfoSize = sizeof (versionInfo);
+      if (!GetVersionEx ((OSVERSIONINFO *) & versionInfo))
+	{
+	  return NULL;
+	}
+
+      switch (versionInfo.dwPlatformId)
+	{
+	case VER_PLATFORM_WIN32s:
+	  PPG_si_osType = "Windows 3.1";
+	  break;
+
+	case VER_PLATFORM_WIN32_WINDOWS:
+	  switch (versionInfo.dwMinorVersion)
+	    {
+	    case 0:
+	      PPG_si_osType = "Windows 95";
+	      break;
+	    case 90:
+	      PPG_si_osType = "Windows Me";
+	      break;
+	    default:
+	      PPG_si_osType = "Windows 98";
+	      break;
+	    }
+	  break;
+
+	case VER_PLATFORM_WIN32_NT:
+	  if (versionInfo.dwMajorVersion < 5)
+	    {
+	      PPG_si_osType = "Windows NT";
+	    }
+	  else
+	    {
+	      switch (versionInfo.dwMinorVersion)
+		{
+		case 0:
+		  PPG_si_osType = "Windows 2000";
+		  break;
+
+		  /* case 1: WinNT 5.1 => Windows XP. Handled by the default. */
+
+		case 2:
+		  /* WinNT 5.2 can be either Win2003 Server or Workstation (e.g. XP64). 
+		     Report workstation products as "Windows XP". */
+		  if (versionInfo.wProductType == VER_NT_WORKSTATION)
+		    {
+		      PPG_si_osType = "Windows XP";
+		    }
+		  else
+		    {
+		      PPG_si_osType = "Windows Server 2003";
+		    }
+		  break;
+
+		default:
+		  PPG_si_osType = "Windows XP";
+		  break;
+		}
+	    }
+	  break;
+
+	default:
+	  PPG_si_osType = "unknown";
+	  break;
+	}
+    }
+  return PPG_si_osType;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_get_OS_version
+/**
+ * Determine version information from the operating system.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return OS version string (NULL terminated) on success, NULL on error.
+ *
+ * @note portLibrary is responsible for allocation/deallocation of returned buffer.
+ */
+const char *VMCALL
+hysysinfo_get_OS_version (struct HyPortLibrary *portLibrary)
+{
+  if (NULL == PPG_si_osVersion)
+    {
+      OSVERSIONINFO versionInfo;
+      int len = sizeof ("0123456789.0123456789 build 0123456789") + 1;
+      char *buffer;
+#if defined(UNICODE)
+      int convSize;
+      int position;
+#endif /* UNICODE */
+
+      versionInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
+      if (!GetVersionEx (&versionInfo))
+	{
+	  return NULL;
+	}
+
+#if defined(UNICODE)
+      convSize =
+	WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK,
+			     versionInfo.szCSDVersion, -1, NULL, 0, NULL,
+			     NULL);
+      convSize = (convSize + 1) * 2;
+      len = len + convSize + 2;
+      buffer = portLibrary->mem_allocate_memory (portLibrary, len);
+      if (NULL == buffer)
+	{
+	  return NULL;
+	}
+      position = sprintf (buffer, "%d.%d build %d%s",
+			  versionInfo.dwMajorVersion,
+			  versionInfo.dwMinorVersion,
+			  versionInfo.dwBuildNumber & 0x0000FFFF,
+			  versionInfo.szCSDVersion ? " " : "");
+      WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK,
+			   versionInfo.szCSDVersion, -1,
+			   (WCHAR *) & buffer[position], convSize, NULL,
+			   NULL);
+      PPG_si_osVersion = buffer;
+#else
+      len = len + strlen (versionInfo.szCSDVersion) + 2;
+      buffer = portLibrary->mem_allocate_memory (portLibrary, len);
+      if (NULL == buffer)
+	{
+	  return NULL;
+	}
+      sprintf (buffer, "%d.%d build %d%s%s",
+	       versionInfo.dwMajorVersion,
+	       versionInfo.dwMinorVersion,
+	       versionInfo.dwBuildNumber & 0x0000FFFF,
+	       versionInfo.szCSDVersion ? " " : "",
+	       versionInfo.szCSDVersion ? versionInfo.szCSDVersion : "");
+      PPG_si_osVersion = buffer;
+#endif
+
+    }
+  return PPG_si_osVersion;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_get_pid
+/**
+ * Determine the process ID of the calling process.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return the PID.
+ */
+UDATA VMCALL
+hysysinfo_get_pid (struct HyPortLibrary * portLibrary)
+{
+  return GetCurrentProcessId ();
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_get_classpathSeparator
+/**
+ * Determine the character used to separate entries on the classpath.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return the classpathSeparator character.
+ */
+U_16 VMCALL
+hysysinfo_get_classpathSeparator (struct HyPortLibrary * portLibrary)
+{
+  return ';';
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_get_executable_name
+/**
+ * Determines an absolute pathname for the executable.
+ * 
+ * @param[in] portLibrary The port library.
+ * @param[in] argv0 argv[0] value
+ * @param[out] result Null terminated pathname string
+ * 
+ * @return 0 on success, -1 on error (or information is not available).
+ *
+ * @note Caller is responsible for de-allocating memory for result buffer with @ref hymem_free_memory.
+ */
+IDATA VMCALL
+hysysinfo_get_executable_name (struct HyPortLibrary * portLibrary,
+			       char *argv0, char **result)
+{
+  char *temp;
+  TCHAR osTemp[_MAX_PATH + 2];
+  DWORD length;
+
+  (void) argv0;			/* unused */
+
+  length = GetModuleFileName (NULL, osTemp, _MAX_PATH + 1);
+  if (!length || (length >= _MAX_PATH))
+    {
+      return -1;
+    }
+  osTemp[length] = (TCHAR) '\0';	/* jic */
+
+#if defined(UNICODE)
+  length =
+    WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK, osTemp, -1, NULL, 0, NULL,
+			 NULL);
+  temp = portLibrary->mem_allocate_memory (portLibrary, length + 1);
+  if (!temp)
+    {
+      return -1;
+    }
+  length =
+    WideCharToMultiByte (CP_ACP, WC_COMPOSITECHECK, osTemp, -1, temp, length,
+			 NULL, NULL);
+#else
+  temp = portLibrary->mem_allocate_memory (portLibrary, length + 1);
+  if (!temp)
+    {
+      return -1;
+    }
+  strcpy (temp, osTemp);
+#endif
+
+  *result = temp;
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_get_number_CPUs
+/**
+ * Determine the number of CPUs on this platform.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return The number of supported CPUs.
+ */
+UDATA VMCALL
+hysysinfo_get_number_CPUs (struct HyPortLibrary * portLibrary)
+{
+  SYSTEM_INFO aSysInfo;
+
+  GetSystemInfo (&aSysInfo);
+  return aSysInfo.dwNumberOfProcessors;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_get_physical_memory
+/**
+ * Determine the size of the total physical memory in the system, in bytes.
+ * 
+ * @param[in] portLibrary The port library.
+ *
+ * @return 0 if the information was unavailable, otherwise total physical memory in bytes.
+ */
+U_64 VMCALL
+hysysinfo_get_physical_memory (struct HyPortLibrary * portLibrary)
+{
+  MEMORYSTATUS aMemStatus;
+
+  /* Function does not work properly on systems with more than 4 GB, when not running Win2K */
+  SetLastError (ERROR_SUCCESS);
+  GlobalMemoryStatus (&aMemStatus);
+  if (GetLastError () != ERROR_SUCCESS)
+    {
+      return HYCONST64 (0);
+    }
+
+  return (U_64) aMemStatus.dwTotalPhys;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_DLPAR_enabled
+/**
+ * Determine if DLPAR (i.e. the ability to change number of CPUs and amount of memory dynamically)
+ * is enabled on this platform.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return 1 if DLPAR is supported, otherwise 0.
+ */
+UDATA VMCALL
+hysysinfo_DLPAR_enabled (struct HyPortLibrary * portLibrary)
+{
+  return FALSE;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_weak_memory_consistency
+/**
+ * Determine if the platform has weak memory consistency behaviour.
+ * 
+ * @param[in] portLibrary The port library.
+ *
+ * @return 1 if weak memory consistency, 0 otherwise.
+ */
+UDATA VMCALL
+hysysinfo_weak_memory_consistency (struct HyPortLibrary * portLibrary)
+{
+  return FALSE;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_shutdown
+/**
+ * PortLibrary shutdown.
+ *
+ * This function is called during shutdown of the portLibrary.  Any resources that were created by @ref hysysinfo_startup
+ * should be destroyed here.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @note Most implementations will be empty.
+ */
+void VMCALL
+hysysinfo_shutdown (struct HyPortLibrary *portLibrary)
+{
+  if (PPG_si_osVersion)
+    {
+      portLibrary->mem_free_memory (portLibrary, PPG_si_osVersion);
+      PPG_si_osVersion = NULL;
+    }
+
+  /* PPG_si_osType is not dynamically allocated, so no need to free */
+  PPG_si_osType = NULL;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_startup
+/**
+ * PortLibrary startup.
+ *
+ * This function is called during startup of the portLibrary.  Any resources that are required for
+ * the system information operations may be created here.  All resources created here should be destroyed
+ * in @ref hysysinfo_shutdown.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return 0 on success, negative error code on failure.  Error code values returned are
+ * \arg HYPORT_ERROR_STARTUP_SYSINFO
+ *
+ * @note Most implementations will simply return success.
+ */
+I_32 VMCALL
+hysysinfo_startup (struct HyPortLibrary *portLibrary)
+{
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_DLPAR_max_CPUs
+/**
+ * Determine the maximum number of CPUs on this platform
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return The maximum number of supported CPUs..
+ */
+UDATA VMCALL
+hysysinfo_DLPAR_max_CPUs (struct HyPortLibrary * portLibrary)
+{
+  return portLibrary->sysinfo_get_number_CPUs (portLibrary);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_get_username
+/**
+ * Query the operating system for the name of the user associate with the current thread
+ * 
+ * Obtain the value of the name of the user associated with the current thread, and then
+ * write it out into the buffer supplied by the user
+ *
+ * @param[in] portLibrary The port Library
+ * @param[out] buffer Buffer for the name of the user
+ * @param[in,out] length The length of the buffer
+ *
+ * @return 0 on success, number of bytes required to hold the 
+ * information if the output buffer was too small, -1 on failure.
+ *
+ * @note buffer is undefined on error or when supplied buffer was too small.
+ */
+IDATA VMCALL
+hysysinfo_get_username (struct HyPortLibrary * portLibrary, char *buffer,
+			UDATA length)
+{
+  int resultLength = length;
+
+  if (GetUserName (buffer, &resultLength))
+    {
+      return 0;
+    }
+
+  if (GetLastError () == ERROR_INSUFFICIENT_BUFFER)
+    {
+      return resultLength;
+    }
+
+  return -1;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hysysinfo_get_processing_capacity
+/**
+ * Determine the collective processing capacity available to the VM
+ * in units of 1% of a physical processor. In environments without
+ * some kind of virtual partitioning, this will simply be the number
+ * of CPUs * 100.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return The processing capacity available to the VM.
+ */
+UDATA VMCALL
+hysysinfo_get_processing_capacity (struct HyPortLibrary * portLibrary)
+{
+  return portLibrary->sysinfo_get_number_CPUs (portLibrary) * 100;
+}
+
+#undef CDEV_CURRENT_FUNCTION

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hytime.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hytime.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hytime.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hytime.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,300 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define CDEV_CURRENT_FUNCTION _comment_
+/** 
+ * @file
+ * @ingroup Port
+ * @brief Timer utilities
+ */
+#undef CDEV_CURRENT_FUNCTION
+
+#include <windows.h>
+
+#include "hyport.h"
+#include "portpriv.h"
+#include "hyportpg.h"
+
+#define CDEV_CURRENT_FUNCTION _prototypes_private
+void VMCALL shutdown_timer (void);
+I_32 VMCALL init_timer (void);
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hytime_msec_clock
+/**
+ * Query OS for timestamp.
+ * Retrieve the current value of system clock and convert to milliseconds.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return 0 on failure, time value in milliseconds on success.
+ * @deprecated Use @ref hytime_hires_clock and @ref hytime_hires_delta
+ */
+UDATA VMCALL
+hytime_msec_clock (struct HyPortLibrary *portLibrary)
+{
+  LARGE_INTEGER freq, i, multiplier;
+  UDATA result;
+
+  if (!QueryPerformanceFrequency (&freq))
+    {
+      return (UDATA) GetTickCount ();
+    }
+
+  multiplier.QuadPart = freq.QuadPart / 1000;
+
+  QueryPerformanceCounter (&i);
+  result = (UDATA) (i.QuadPart / multiplier.QuadPart);
+
+  return result;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hytime_usec_clock
+/**
+ * Query OS for timestamp.
+ * Retrieve the current value of system clock and convert to microseconds.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return 0 on failure, time value in microseconds on success.
+ * @deprecated Use @ref hytime_hires_clock and @ref hytime_hires_delta
+ */
+UDATA VMCALL
+hytime_usec_clock (struct HyPortLibrary * portLibrary)
+{
+  LARGE_INTEGER freq, i, multiplier;
+  UDATA result;
+
+  if (!QueryPerformanceFrequency (&freq))
+    {
+      return (UDATA) GetTickCount ();
+    }
+
+  multiplier.QuadPart = freq.QuadPart / 1000000;
+
+  QueryPerformanceCounter (&i);
+  result = (UDATA) (i.QuadPart / multiplier.QuadPart);
+
+  return result;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hytime_current_time_millis
+/**
+ * Query OS for timestamp.
+ * Retrieve the current value of system clock and convert to milliseconds since
+ * January 1st 1970.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return 0 on failure, time value in milliseconds on success.
+ */
+I_64 VMCALL
+hytime_current_time_millis (struct HyPortLibrary * portLibrary)
+{
+  /* returns in time the number of 100ns elapsed since January 1, 1601 */
+  /* subtract 116444736000000000 = number of 100ns from jan 1, 1601 to jan 1, 1970 */
+  /* multiply by 10000 to get number of milliseconds since Jan 1, 1970 */
+
+  LONGLONG time;
+  GetSystemTimeAsFileTime ((FILETIME *) & time);
+  return (I_64) ((time - 116444736000000000) / 10000);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION init_timer
+I_32 VMCALL
+init_timer (void)
+{
+  /* on Win98 this forced the process to run with a higher
+   * resolution clock. It made things like Thread.sleep() more
+   * accurate. But the functions it calls are defined in WINMM.DLL,
+   * which forces USER32.DLL, GDI.DLL and other modules to
+   * be loaded, polluting the address space. By not loading WINMM.DLL
+   * we increase the chances of having a large contiguous region
+   * of virtual memory to use as the Java heap.
+   */
+#if 0
+  TIMECAPS timecaps;
+  timeGetDevCaps (&timecaps, sizeof (TIMECAPS));
+  timeBeginPeriod (timecaps.wPeriodMin);
+#endif
+
+  return 0;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION shutdown_timer
+void VMCALL
+shutdown_timer (void)
+{
+  /* see init_timer */
+#if 0
+  TIMECAPS timecaps;
+  timeGetDevCaps (&timecaps, sizeof (TIMECAPS));
+  timeEndPeriod (timecaps.wPeriodMin);
+#endif
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hytime_hires_clock
+/**
+ * Query OS for timestamp.
+ * Retrieve the current value of the high-resolution performance counter.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return 0 on failure, time value on success.
+ */
+U_64 VMCALL
+hytime_hires_clock (struct HyPortLibrary *portLibrary)
+{
+  LARGE_INTEGER i;
+
+  if (QueryPerformanceCounter (&i))
+    {
+      return (U_64) i.QuadPart;
+    }
+  else
+    {
+      return (U_64) GetTickCount ();
+    }
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hytime_hires_frequency
+/**
+ * Query OS for clock frequency
+ * Retrieves the frequency of the high-resolution performance counter.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return 0 on failure, number of ticks per second on success.
+ */
+U_64 VMCALL
+hytime_hires_frequency (struct HyPortLibrary * portLibrary)
+{
+  return PPG_time_hiresClockFrequency;
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hytime_hires_delta
+/**
+ * Calculate time difference between two hires clock timer values @ref hytime_hires_clock.
+ *
+ * Given a start and end time determine how much time elapsed.  Return the value as
+ * requested by the required resolution
+ *
+ * @param[in] portLibrary The port library.
+ * @param[in] startTime Timer value at start of timing interval
+ * @param[in] endTime Timer value at end of timing interval
+ * @param[in] requiredResolution Returned timer resolution as a fraction of a second.  For example: 
+ *  \arg 1 to report elapsed time in seconds
+ *  \arg 1,000 to report elapsed time in milliseconds
+ *  \arg 1,000,000 to report elapsed time in microseconds
+ *
+ * @return 0 on failure, time difference on success.
+ *
+ * @note helper macros are available for commonly requested resolution
+ *  \arg HYPORT_TIME_DELTA_IN_SECONDS return timer value in seconds.
+ *  \arg HYPORT_TIME_DELTA_IN_MILLISECONDS return timer value in milliseconds.
+ *  \arg HYPORT_TIME_DELTA_IN_MICROSECONDS return timer value in micoseconds.
+ *  \arg HYPORT_TIME_DELTA_IN_NANOSECONDS return timer value in nanoseconds.
+ */
+U_64 VMCALL
+hytime_hires_delta (struct HyPortLibrary * portLibrary, U_64 startTime,
+		    U_64 endTime, UDATA requiredResolution)
+{
+  U_64 ticks;
+  U_64 frequency = PPG_time_hiresClockFrequency;
+
+  /* modular arithmetic saves us, answer is always ... */
+  ticks = endTime - startTime;
+
+  if (frequency == requiredResolution)
+    {
+      return ticks;
+    }
+
+  if (frequency < requiredResolution)
+    {
+      return (ticks * requiredResolution) / frequency;
+    }
+
+  return ticks / (frequency / requiredResolution);
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hytime_shutdown
+/**
+ * PortLibrary shutdown.
+ *
+ * This function is called during shutdown of the portLibrary.  Any resources that were created by @ref hytime_startup
+ * should be destroyed here.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @note Most implementations will be empty.
+ */
+void VMCALL
+hytime_shutdown (struct HyPortLibrary *portLibrary)
+{
+  shutdown_timer ();
+}
+
+#undef CDEV_CURRENT_FUNCTION
+
+#define CDEV_CURRENT_FUNCTION hytime_startup
+/**
+ * PortLibrary startup.
+ *
+ * This function is called during startup of the portLibrary.  Any resources that are required for
+ * the time operations may be created here.  All resources created here should be destroyed
+ * in @ref hytime_shutdown.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return 0 on success, negative error code on failure.  Error code values returned are
+ * \arg HYPORT_ERROR_STARTUP_TIME
+ *
+ * @note Most implementations will simply return success.
+ */
+I_32 VMCALL
+hytime_startup (struct HyPortLibrary *portLibrary)
+{
+  LARGE_INTEGER freq;
+
+  if (QueryPerformanceFrequency (&freq))
+    {
+      PPG_time_hiresClockFrequency = freq.QuadPart;
+    }
+  else
+    {
+      PPG_time_hiresClockFrequency = 1000;	/* GetTickCount() returns millis */
+    }
+
+  return init_timer ();
+}
+
+#undef CDEV_CURRENT_FUNCTION

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hytlshelpers.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hytlshelpers.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hytlshelpers.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/port/hytlshelpers.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,210 @@
+/* Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file
+ * @ingroup Port
+ * @brief Per Thread Buffer Support
+ *
+ * Per thread buffers are used to store information that is not sharable among the threads.  
+ * For example when an OS system call fails the error code associated with that error is
+ * relevant to the thread that called the OS function; it has no meaning to any other thread.
+ *
+ * This file contains the functions supported by the port library for creating, accessing and
+ * destroying per thread buffers.@see hyportptb.h for details on the per thread buffer structure.
+ *
+ * Only the function @hyport_tls_free is available via the port library function table.  The rest of
+ * the functions are helpers for the port library only.
+ */
+#include <string.h>
+#include "hyport.h"
+#include "portpriv.h"
+#include "hythread.h"
+#include "hyportptb.h"
+
+/**
+ * @internal
+ * @brief Per Thread Buffer Support
+ *
+ * Get a per thread buffer.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return The per thread buffer on success, NULL on failure.
+ */
+void *VMCALL
+hyport_tls_get (struct HyPortLibrary *portLibrary)
+{
+  PortlibPTBuffers_t ptBuffers;
+
+  ptBuffers =
+    hythread_tls_get (hythread_self (), portLibrary->portGlobals->tls_key);
+  if (NULL == ptBuffers)
+    {
+      MUTEX_ENTER (portLibrary->portGlobals->tls_mutex);
+
+      ptBuffers =
+	portLibrary->mem_allocate_memory (portLibrary,
+					  sizeof (PortlibPTBuffers_struct));
+      if (NULL != ptBuffers)
+	{
+	  if (0 ==
+	      hythread_tls_set (hythread_self (),
+				portLibrary->portGlobals->tls_key, ptBuffers))
+	    {
+	      memset (ptBuffers, 0, sizeof (PortlibPTBuffers_struct));
+	      ptBuffers->next = portLibrary->portGlobals->buffer_list;
+	      if (portLibrary->portGlobals->buffer_list)
+		{
+		  ((PortlibPTBuffers_t) portLibrary->portGlobals->
+		   buffer_list)->previous = ptBuffers;
+		}
+	      portLibrary->portGlobals->buffer_list = ptBuffers;
+	    }
+	  else
+	    {
+	      portLibrary->mem_free_memory (portLibrary, ptBuffers);
+	      ptBuffers = NULL;
+	    }
+	}
+
+      MUTEX_EXIT (portLibrary->portGlobals->tls_mutex);
+    }
+  return ptBuffers;
+}
+
+/**
+ * @brief Per Thread Buffer Support
+ * 
+ * Free the per thread buffers.
+ *
+ * @param[in] portLibrary The port library.
+ */
+void VMCALL
+hyport_tls_free (struct HyPortLibrary *portLibrary)
+{
+  PortlibPTBuffers_t ptBuffers;
+
+  MUTEX_ENTER (portLibrary->portGlobals->tls_mutex);
+  ptBuffers =
+    hythread_tls_get (hythread_self (), portLibrary->portGlobals->tls_key);
+  if (ptBuffers)
+    {
+      hythread_tls_set (hythread_self (), portLibrary->portGlobals->tls_key,
+			NULL);
+
+      /* Unlink */
+      if (ptBuffers->next)
+	{
+	  ptBuffers->next->previous = ptBuffers->previous;
+	}
+      if (portLibrary->portGlobals->buffer_list == ptBuffers)
+	{
+	  portLibrary->portGlobals->buffer_list = ptBuffers->next;
+	}
+      else
+	{
+	  if (ptBuffers->previous)
+	    {
+	      ptBuffers->previous->next = ptBuffers->next;
+	    }
+	}
+
+      hyport_free_ptBuffer (portLibrary, ptBuffers);
+    }
+  MUTEX_EXIT (portLibrary->portGlobals->tls_mutex);
+}
+
+/**
+ * @internal
+ * @brief PortLibrary startup.
+ * 
+ * This function is called during startup of the portLibrary.  Any resources that are required for
+ * the portl library thread local storage operations may be created here.  All resources created here should be destroyed
+ * in @ref hyport_tls_shutdown.
+ *
+ * @param[in] portLibrary The port library
+ *
+ * @return 0 on success, negative error code on failure.  Error code values returned are
+ * \arg HYPORT_ERROR_STARTUP_TLS
+ * \arg HYPORT_ERROR_STARTUP_TLS_ALLOC
+ * \arg HYPORT_ERROR_STARTUP_TLS_MUTEX
+ */
+I_32 VMCALL
+hyport_tls_startup (struct HyPortLibrary *portLibrary)
+{
+  if (hythread_tls_alloc (&portLibrary->portGlobals->tls_key))
+    {
+      return HYPORT_ERROR_STARTUP_TLS_ALLOC;
+    }
+
+  if (!MUTEX_INIT (portLibrary->portGlobals->tls_mutex))
+    {
+      return HYPORT_ERROR_STARTUP_TLS_MUTEX;
+    }
+
+  return 0;
+}
+
+/**
+ * @internal
+ * @brief PortLibrary shutdown.
+ *
+ * This function is called during shutdown of the portLibrary.  Any resources that were created by 
+ * @ref hyport_tls_startup should be destroyed here.
+ *
+ * @param[in] HyPortLibrary The port library
+ */
+void VMCALL
+hyport_tls_shutdown (struct HyPortLibrary *portLibrary)
+{
+  PortlibPTBuffers_t ptBuffers, next;
+
+  /* Free all remaining buffer sets */
+  MUTEX_ENTER (portLibrary->portGlobals->tls_mutex);
+  ptBuffers = portLibrary->portGlobals->buffer_list;
+  while (NULL != ptBuffers)
+    {
+      next = ptBuffers->next;
+      hyport_free_ptBuffer (portLibrary, ptBuffers);
+      ptBuffers = next;
+    }
+  portLibrary->portGlobals->buffer_list = NULL;
+  MUTEX_EXIT (portLibrary->portGlobals->tls_mutex);
+
+  /* Now dispose of the tls_key and the mutex */
+  hythread_tls_free (portLibrary->portGlobals->tls_key);
+  MUTEX_DESTROY (portLibrary->portGlobals->tls_mutex);
+}
+
+/**
+ * @internal
+ * @brief Per Thread Buffer Support
+ * 
+ * Get the per thread buffer for a thread. If the buffer has not been allocated do not allocate a new
+ * one, the function @ref hyport_tls_get is used for that purpose. This function is not exported outside 
+ * the port library as most applications will want a per thread buffer created to store their data.  This 
+ * function is used to access existing data in the per thread buffers.
+ *
+ * @param[in] portLibrary The port library.
+ *
+ * @return The per thread buffer, may be NULL.
+ */
+void *VMCALL
+hyport_tls_peek (struct HyPortLibrary *portLibrary)
+{
+  return hythread_tls_get (hythread_self (),
+			   portLibrary->portGlobals->tls_key);
+}



Mime
View raw message