You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2005/12/01 07:04:00 UTC

svn commit: r350181 [178/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....

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/bigint.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/bigint.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/bigint.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/bigint.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,1280 @@
+/* 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.
+ */
+
+
+#include "jcl.h"
+
+/* macros for Endian portability
+at() mangles array indices to count 1,0,3,2,5,4,... on BigEndian platforms
+atx() mangles array indices to count 1,0,3,2,5,4,... on BigEndian platforms, except 64 bit platforms
+where counting slots must still go in numerical order
+copysize() mangles array sizes to copy so on BigEndian platforms, 5 becomes 6 because
+the 5th word in memory is skipped and the 5th word of the number is stored in the 6th memory word
+*/
+
+#define at(i) (i)
+#define copysize(i) (i)
+
+#define U64_ADD(addr1, addr2) (*(U_64*)(addr1) += *(U_64*)(addr2))
+#define U64_GREATER(addr1, addr2) (*(U_64*)(addr1) > *(U_64*)(addr2))
+#define U64_SUBTRACT_LONG(addr1, u32) (*(U_64*)(addr1) -= (U_64)(u32))
+#define LONG_MULT(i1,i2,res) (*(U_64*)res = (U_64)i1 * (U_64)i2)
+#define LONG_DIV(u64, div) ((U_32)(*(U_64*)(u64) / (U_32)(div)))
+#define LONG_REM(u64, div) ((U_32)(*(U_64*)(u64) % (U_32)(div)))
+
+/* 32 bit */
+#define IS_NEGATIVE(ar,len)     (((I_32*)ar)[at(len*2-1)] < 0)
+#define atx(i) (at(i))
+
+#define GET_LENGTH(obj) ((*env)->GetArrayLength(env,obj))
+#define GET_ELEMENTS(obj) ((U_32*)(*env)->GetLongArrayElements(env, obj, NULL))
+#define RELEASE_ELEMENTS(obj,ar,save) ((*env)->ReleaseLongArrayElements(env, obj, (jlong*)ar, save ? 0 : JNI_ABORT))
+#define GET_ELEMENTS_CRITICAL(obj) ((U_32*)(*env)->GetPrimitiveArrayCritical(env, obj, NULL))
+#define RELEASE_ELEMENTS_CRITICAL(obj,ar,save) ((*env)->ReleasePrimitiveArrayCritical(env, obj, (jlong*)ar, save ? 0 : JNI_ABORT))
+#define NEW_OBJECT(length) ((*env)->NewLongArray(env,length))
+
+jlongArray internalBigIntegerNormalize
+PROTOTYPE ((JNIEnv * env, jlongArray src1));
+jlongArray internalBigIntegerAdd
+PROTOTYPE ((JNIEnv * env, jlongArray src1, jlongArray src2));
+static void RIGHT_SHIFT PROTOTYPE ((void *arIn, IDATA lenIn, IDATA shiftval));
+jlongArray internalBigIntegerNeg PROTOTYPE ((JNIEnv * env, jlongArray src1));
+static U_32 internalIntegerSubtractWithCarry
+PROTOTYPE ((U_32 a1, U_32 a2, U_32 * carry));
+jlongArray grow PROTOTYPE ((JNIEnv * env, jlongArray src1, jlong element));
+static void LEFT_SHIFT PROTOTYPE ((void *arIn, IDATA lenIn, IDATA shiftval));
+static U_32 internalIntegerAddWithCarry
+PROTOTYPE ((U_32 a1, U_32 a2, U_32 * carry));
+
+static void
+LEFT_SHIFT (void *arIn, IDATA lenIn, IDATA shiftval)
+  {
+    IDATA oldAt, newAt, shiftvalr, i, len = (lenIn + 1) / 2;
+    U_64 *ar = (U_64 *) arIn;
+
+    oldAt = 0, newAt = shiftval / 64;
+    shiftval = shiftval % 64;
+    shiftvalr = 64 - shiftval;
+
+    if (shiftval == 0)
+      {
+        /* straight copy */
+        for (i = len - 1; i >= newAt; i--)
+          ar[i] = ar[i - newAt];
+      }
+    else
+      {
+        for (i = len - 1; i > newAt; i--)
+          ar[i] =
+          (ar[i - newAt] << shiftval) | (ar[i - newAt - 1] >> shiftvalr);
+        /* zero extend low word */
+        ar[newAt] = (ar[0] << shiftval);
+      }
+    for (i = 0; i < newAt; i++)
+      ar[newAt] = 0;
+  }
+
+static void
+RIGHT_SHIFT (void *arIn, IDATA lenIn, IDATA shiftval)
+  {
+    IDATA oldAt, newAt, shiftvalr, len = (lenIn + 1) / 2;
+    U_64 *ar = (U_64 *) arIn;
+
+    oldAt = shiftval / 64, newAt = 0;
+    shiftval = shiftval % 64;
+    shiftvalr = 64 - shiftval;
+
+    if (shiftval == 0)
+      {
+        /* straight copy */
+        for (; oldAt < len; oldAt++, newAt++)
+          ar[newAt] = ar[oldAt];
+      }
+    else
+      {
+        for (; oldAt < len - 1; oldAt++, newAt++)
+          ar[newAt] = (ar[oldAt] >> shiftval) | (ar[oldAt + 1] << shiftvalr);
+        /* sign extend high word */
+        ar[newAt++] = (((I_64) ar[oldAt]) >> shiftval);
+      }
+    for (; newAt < len; newAt++)
+      ar[newAt] = 0;
+  }
+
+jlongArray JNICALL
+Java_com_ibm_oti_util_math_BigInteger_addImpl (JNIEnv * env, jclass cls,
+                 jlongArray src1,
+                 jlongArray src2)
+{
+  return internalBigIntegerAdd (env, src1, src2);
+}
+
+jint JNICALL
+Java_com_ibm_oti_util_math_BigInteger_compImpl (JNIEnv * env, jclass cls,
+                                                jlongArray src1,
+                                                jlongArray src2)
+  {
+    /* return -1, 0, 1 if src1 is less than, equal to, or greater than src2 */
+    IDATA len1, len2;
+    UDATA *ar1, *ar2;
+    jint result = 0;
+    IDATA neg1 = 0, neg2 = 0, i;
+
+    len1 = GET_LENGTH (src1);
+    len2 = GET_LENGTH (src2);
+
+    if (!(ar1 = (UDATA *) GET_ELEMENTS_CRITICAL (src1)))
+      goto done;
+    if (!(ar2 = (UDATA *) GET_ELEMENTS_CRITICAL (src2)))
+      goto release1;
+
+    neg1 = IS_NEGATIVE (ar1, len1);
+    neg2 = IS_NEGATIVE (ar2, len2);
+
+    len1 *= 2;
+    len2 *= 2;
+
+    if (neg1 != neg2)   /* different signs */
+      result = neg2 ? 1 : -1;
+    else
+      {
+        if (len1 != len2)
+          {
+            if (neg1 == 0)  /* positive/zero case */
+              result = len1 > len2 ? 1 : -1;
+            else      /* negative case */
+              result = len1 > len2 ? -1 : 1;
+            goto release2;
+          }
+        else
+          {     /* len1==len2 */
+            if (ar1[atx (len1 - 1)] != ar2[atx (len1 - 1)])
+              {
+                result =
+                  ((IDATA *) ar1)[atx (len1 - 1)] >
+                  ((IDATA *) ar2)[atx (len1 - 1)] ? 1 : -1;
+                goto release2;
+              }
+            for (i = len1 - 2; i >= 0; i--)
+              if (ar1[atx (i)] != ar2[atx (i)])
+                {
+                  result = ar1[atx (i)] > ar2[atx (i)] ? 1 : -1;
+                  goto release2;
+                }
+          }
+      }
+  release2:
+    RELEASE_ELEMENTS_CRITICAL (src2, ar2, 0);
+  release1:
+    RELEASE_ELEMENTS_CRITICAL (src1, ar1, 0);
+  done:
+    return result;
+  }
+
+jlongArray JNICALL
+Java_com_ibm_oti_util_math_BigInteger_divImpl (JNIEnv * env, jclass cls,
+                                               jlongArray topObject,
+                                               jlongArray bottomObject)
+  {
+  /* ASSUME that bottomObject is nonzero, ie check and throw was done in java */
+  IDATA topLength, bottomLength, topSize, bottomSize, resultLength,
+    resultSize;
+  jlongArray resultObject;
+  U_32 *topStart = NULL, *bottomStart = NULL, *resultStart = NULL;
+  IDATA topAt, bottomAt, resultAt;
+  IDATA isNegative = 0;
+  I_32 signedTemp;
+  IDATA shift, tempNeg;
+
+  U_32 j;
+  IDATA fromPtr;
+  IDATA fromPtr2;
+  IDATA multPtr;
+  U_32 v1;
+  U_32 v2;
+  IDATA highDigit;
+
+  topLength = GET_LENGTH (topObject);
+  bottomLength = GET_LENGTH (bottomObject);
+
+  /* make both integers positive, store if the result will be positive or negative */
+  if (!(topStart = GET_ELEMENTS_CRITICAL (topObject)))
+    goto error;
+  tempNeg = IS_NEGATIVE (topStart, topLength);
+  RELEASE_ELEMENTS_CRITICAL (topObject, topStart, 0);
+  topStart = NULL;
+  if (tempNeg)
+    {
+      isNegative ^= 1;
+      if (!(topObject = internalBigIntegerNeg (env, topObject)))
+        goto error;
+      topLength = GET_LENGTH (topObject);
+    }
+
+  if (!(bottomStart = GET_ELEMENTS_CRITICAL (bottomObject)))
+    goto error;
+  tempNeg = IS_NEGATIVE (bottomStart, bottomLength);
+  RELEASE_ELEMENTS_CRITICAL (bottomObject, bottomStart, 0);
+  bottomStart = NULL;
+  if (tempNeg)
+    {
+      isNegative ^= 1;
+      if (!(bottomObject = internalBigIntegerNeg (env, bottomObject)))
+        goto error;
+      bottomLength = GET_LENGTH (bottomObject);
+    }
+
+  if (!(topStart = GET_ELEMENTS (topObject)))
+    goto error;
+  if (!(bottomStart = GET_ELEMENTS (bottomObject)))
+    goto error;
+
+  /* Get the magnitude of the bottom integer */
+  bottomSize = bottomLength * 2;
+  while (!bottomStart[at (bottomSize - 1)])
+    bottomSize--;
+
+  /* Get the magnitude of the top integer, will need a 0 on the end */
+  topSize = topLength * 2;
+  while (topSize > 1 && !topStart[at (topSize - 1)]
+    && !topStart[at (topSize - 2)])
+    topSize--;
+
+  /* easy case if the bottom is a U32 */
+  if (bottomSize == 1)
+    {
+      U_64 temp;
+      U_32 divisor = bottomStart[at (0)];
+
+      if (topSize > 1 && !topStart[at (topSize - 1)])
+        topSize--;
+
+      /* Add extra int on the end for sign */
+      resultSize = topSize + 1;
+      resultLength = (resultSize + 1) / 2;
+      if (!(resultObject = NEW_OBJECT (resultLength)))
+        goto error;
+      if (!(resultStart = GET_ELEMENTS (resultObject)))
+        goto error;
+
+      topAt = topSize - 1;
+      resultAt = resultSize - 2;
+      HIGH_LONG (temp) = 0;
+      do
+        {
+          LOW_LONG (temp) = topStart[at (topAt--)];
+          resultStart[at (resultAt--)] = LONG_DIV (&temp, divisor);
+          HIGH_LONG (temp) = LONG_REM (&temp, divisor);
+        }
+      while (!(--topSize == 0));
+
+      goto finished;
+    }
+
+  /* ensure top starts with a zero int */
+  if (topStart[at (topSize - 1)] != 0)
+    {
+    if (topSize >= topLength * 2)
+      {     /* allocate extra space */
+        IDATA i;
+        U_32 *tempPtr;
+        jlongArray tempObject;
+        if (!(tempObject = NEW_OBJECT (topLength + 1)))
+          goto error;   /* initialized to zero */
+        if (!(tempPtr = GET_ELEMENTS (tempObject)))
+          goto error;
+        for (i = 0; i < copysize (topSize); i++)
+          tempPtr[i] = topStart[i];
+        RELEASE_ELEMENTS (topObject, topStart, 0);
+        topObject = tempObject;
+        topStart = tempPtr;
+        topLength++;
+      }
+    topSize++;
+    }
+
+  /* If the bottom int has a larger size than the top int, the result
+  *         is 0.  Subtract one from the topSize before the comparison to account
+  *                 for the 0 added to the end. */
+
+  if (bottomSize > (topSize - 1))
+    {
+      /* release objects */
+      RELEASE_ELEMENTS (topObject, topStart, 0);
+      topStart = NULL;
+      RELEASE_ELEMENTS (bottomObject, bottomStart, 0);
+      bottomStart = NULL;
+      if (!(resultObject = NEW_OBJECT (1)))
+        goto error;   /* initialized to zero */
+      return resultObject;
+    }
+
+  /* Shift the bottom int until its high bit is set */
+
+  highDigit = bottomSize - 1;
+  signedTemp = (I_32) bottomStart[at (highDigit)];
+  shift = 0;
+  while (signedTemp >= 0)
+    ++shift, signedTemp <<= 1;
+  LEFT_SHIFT (bottomStart, bottomSize, shift);
+  LEFT_SHIFT (topStart, topSize, shift);
+  v1 = bottomStart[at (highDigit)];
+  v2 = bottomStart[at (highDigit - 1)];
+  j = topSize - bottomSize;
+
+  /* Create the result object.  It must have an extra long added for sign */
+  resultSize = j + 1;
+  resultLength = (resultSize + 1) / 2;
+  if (!(resultObject = NEW_OBJECT (resultLength)))
+    goto error;
+  if (!(resultStart = GET_ELEMENTS (resultObject)))
+    goto error;
+
+  /* Initialize */
+  bottomAt = 0;
+  topAt = 0;
+  fromPtr = topAt + topSize - 1;
+  fromPtr2 = fromPtr - 1;
+  resultAt = j;
+  multPtr = topAt + j;
+
+  /* Calculate the digits of the result */
+  do
+    {
+      U_64 t1;
+      U_64 t2;
+      U_32 qHat;
+      IDATA from;
+      IDATA to;
+      U_32 size;
+      U_32 carry;
+
+      /* Calculate qHat */
+
+      if ((HIGH_LONG (t1) = topStart[at (fromPtr--)]) == v1)
+        {
+          qHat = 0xFFFFFFFF;
+          --fromPtr2;
+        }
+      else
+        {
+          LOW_LONG (t1) = topStart[at (fromPtr)];
+          qHat = LONG_DIV (&t1, v1);
+          HIGH_LONG (t2) = LONG_REM (&t1, v1);
+          LOW_LONG (t2) = topStart[at (--fromPtr2)];
+          LONG_MULT (qHat, v2, &t1);
+          while (U64_GREATER (&t1, &t2))
+            {
+              --qHat;
+              carry = 0;
+              HIGH_LONG (t2) =
+                internalIntegerAddWithCarry (HIGH_LONG (t2), v1, &carry);
+              /* Stop if t2 grows larger than a U_64 */
+              if (carry)
+                {
+                  break;
+                }
+              U64_SUBTRACT_LONG (&t1, v2);
+            }
+        }
+      resultStart[at (--resultAt)] = qHat;
+
+      /* Subtract factored part */
+
+      from = bottomAt;
+      to = --multPtr;
+      size = bottomSize;
+      LOW_LONG (t1) = 0;
+      carry = 0;
+      do
+        {
+          HIGH_LONG (t1) = 0;
+          LONG_MULT (bottomStart[at (from++)], qHat, &t2);
+          U64_ADD (&t1, &t2);
+          topStart[at (to)] =
+            internalIntegerSubtractWithCarry (topStart[at (to)],
+            LOW_LONG (t1), &carry);
+          to++;
+          LOW_LONG (t1) = HIGH_LONG (t1);
+        }
+      while (!(--size == 0));
+      topStart[at (to)] =
+        internalIntegerSubtractWithCarry (topStart[at (to)], LOW_LONG (t1),
+        &carry);
+
+      /* Check for add back */
+
+      if (carry)
+        {
+          --resultStart[at (resultAt)];
+          carry = 0;
+          from = bottomAt;
+          to = multPtr;
+          size = bottomSize;
+          do
+            {
+              topStart[at (to)] =
+                internalIntegerAddWithCarry (topStart[at (to)],
+                bottomStart[at (from++)],
+                &carry);
+              to++;
+            }
+          while (!(--size == 0));
+          topStart[at (to)] = 0;
+        }
+    }
+  while (!(--j == 0));
+
+finished:
+  /* release objects */
+  RELEASE_ELEMENTS (topObject, topStart, 0);
+  RELEASE_ELEMENTS (bottomObject, bottomStart, 0);
+  RELEASE_ELEMENTS (resultObject, resultStart, 1);
+
+  /* ensure result is normalized */
+  if (!(resultObject = internalBigIntegerNormalize (env, resultObject)))
+    return NULL;
+  /* negate the result if inputs had opposite signs */
+  if (isNegative)
+    if (!(resultObject = internalBigIntegerNeg (env, resultObject)))
+      return NULL;
+  return resultObject;
+
+error:
+  if (topStart)
+    RELEASE_ELEMENTS (topObject, topStart, 0);
+  if (bottomStart)
+    RELEASE_ELEMENTS (bottomObject, bottomStart, 0);
+  if (resultStart)
+    RELEASE_ELEMENTS (resultObject, resultStart, 0);
+  return NULL;
+  }
+
+
+jlongArray JNICALL
+Java_com_ibm_oti_util_math_BigInteger_mulImpl (JNIEnv * env, jclass cls,
+                                               jlongArray src1,
+                                               jlongArray src2)
+  {
+    IDATA len1, len2, lenR;
+    jlongArray resultObject;
+    U_32 *ar1 = NULL, *ar2 = NULL, *arR = NULL;
+    IDATA isNegative = 0, tempNeg;
+    IDATA shortAt, resultAt;
+
+    IDATA shortSize, longSize;
+    U_32 *longer, *shorter, *result;
+
+    len1 = GET_LENGTH (src1);
+    len2 = GET_LENGTH (src2);
+
+    /* make both integers positive, store if the result will be positive or negative */
+    if (!(ar1 = GET_ELEMENTS_CRITICAL (src1)))
+      goto error;
+    tempNeg = IS_NEGATIVE (ar1, len1);
+    RELEASE_ELEMENTS_CRITICAL (src1, ar1, 0);
+    ar1 = NULL;
+    if (tempNeg)
+      {
+        isNegative ^= 1;
+        if (!(src1 = internalBigIntegerNeg (env, src1)))
+          goto error;
+        len1 = GET_LENGTH (src1);
+      }
+
+    if (!(ar2 = GET_ELEMENTS_CRITICAL (src2)))
+      goto error;
+    tempNeg = IS_NEGATIVE (ar2, len2);
+    RELEASE_ELEMENTS_CRITICAL (src2, ar2, 0);
+    ar2 = NULL;
+    if (tempNeg)
+      {
+        isNegative ^= 1;
+        if (!(src2 = internalBigIntegerNeg (env, src2)))
+          goto error;
+        len2 = GET_LENGTH (src2);
+      }
+    if (!(ar1 = GET_ELEMENTS (src1)))
+      goto error;
+    if (!(ar2 = GET_ELEMENTS (src2)))
+      goto error;
+
+    /* make ar1 the longer integer */
+    if (len2 > len1)
+      {
+        void *temp;
+        IDATA tempint;
+        temp = src1;
+        src1 = src2;
+        src2 = temp;
+        temp = ar1;
+        ar1 = ar2;
+        ar2 = temp;
+        tempint = len1;
+        len1 = len2;
+        len2 = tempint;
+      }
+
+    /* allocate new long of length len1+len2 */
+    lenR = len1 + len2;
+    if (!(resultObject = NEW_OBJECT (lenR)))
+      goto error;
+    if (!(arR = GET_ELEMENTS (resultObject)))
+      goto error;
+
+    /* Perform long multiplication with the second integer "on the bottom" */
+    shorter = ar2;
+    shortAt = 0;
+    longer = ar1;
+    shortSize = len2 * 2;
+    longSize = len1 * 2;
+    result = arR;
+    resultAt = 0;
+    do
+      {
+        U_32 fromShort = shorter[at (shortAt++)];
+        IDATA longAt = 0;
+        IDATA toAt = resultAt++;
+        U_32 size = longSize;
+        U_32 addCarry = 0;
+        U_32 multCarry = 0;
+        U_64 mult;
+        U_32 carry;
+
+        do
+          {
+            LONG_MULT (fromShort, longer[at (longAt++)], &mult);
+            carry = 0;
+            LOW_LONG (mult) =
+              internalIntegerAddWithCarry (LOW_LONG (mult), multCarry, &carry);
+            HIGH_LONG (mult) =
+              internalIntegerAddWithCarry (HIGH_LONG (mult), 0, &carry);
+            multCarry = HIGH_LONG (mult);
+            carry = addCarry;
+            result[at (toAt)] =
+              internalIntegerAddWithCarry (result[at (toAt)], LOW_LONG (mult),
+              &carry);
+            toAt++;
+            addCarry = carry;
+          }
+        while (!(--size == 0));
+        result[at (toAt++)] = multCarry + addCarry;
+      }
+    while (!(--shortSize == 0));
+
+    RELEASE_ELEMENTS (src1, ar1, 0);
+    RELEASE_ELEMENTS (src2, ar2, 0);
+    RELEASE_ELEMENTS (resultObject, arR, 1);
+
+    /* ensure result is normalized */
+    if (!(resultObject = internalBigIntegerNormalize (env, resultObject)))
+      return NULL;
+    /* negate the result if inputs had opposite signs */
+    if (isNegative)
+      if (!(resultObject = internalBigIntegerNeg (env, resultObject)))
+        return NULL;
+    return resultObject;
+
+  error:
+    if (ar1)
+      RELEASE_ELEMENTS (src1, ar1, 0);
+    if (ar2)
+      RELEASE_ELEMENTS (src2, ar2, 0);
+    if (arR)
+      RELEASE_ELEMENTS (resultObject, arR, 0);
+    return NULL;
+  }
+
+
+jlongArray JNICALL
+Java_com_ibm_oti_util_math_BigInteger_negImpl (JNIEnv * env, jclass cls,
+                                               jlongArray src)
+  {
+    return internalBigIntegerNeg (env, src);
+  }
+
+jlongArray JNICALL
+Java_com_ibm_oti_util_math_BigInteger_remImpl (JNIEnv * env, jclass cls,
+                                               jlongArray topObject,
+                                               jlongArray bottomObject)
+  {
+    /* ASSUME that bottomObject is nonzero, ie check and throw was done in java */
+    IDATA topLength, bottomLength, topSize, bottomSize, resultLength,
+      resultSize;
+    jlongArray resultObject;
+    U_32 *topStart = NULL, *bottomStart = NULL, *resultStart = NULL;
+    IDATA topAt, bottomAt, resultAt, i, topZeroAdded = 0, tempNeg;
+    I_32 signedTemp;
+
+    BOOLEAN firstNegative = 0;
+    U_32 j;
+    IDATA fromPtr, fromPtr2, multPtr;
+    U_32 v1;
+    U_32 v2;
+    UDATA shift;
+    IDATA highDigit;
+
+    topLength = GET_LENGTH (topObject);
+    bottomLength = GET_LENGTH (bottomObject);
+
+    /* make both integers positive, store if the result will be positive or negative */
+    if (!(topStart = GET_ELEMENTS_CRITICAL (topObject)))
+      goto error;
+    tempNeg = IS_NEGATIVE (topStart, topLength);
+    RELEASE_ELEMENTS_CRITICAL (topObject, topStart, 0);
+    topStart = NULL;
+    if (tempNeg)
+      {
+        firstNegative = 1;
+        if (!(topObject = internalBigIntegerNeg (env, topObject)))
+          goto error;
+        topLength = GET_LENGTH (topObject);
+      }
+
+    if (!(bottomStart = GET_ELEMENTS_CRITICAL (bottomObject)))
+      goto error;
+    tempNeg = IS_NEGATIVE (bottomStart, bottomLength);
+    RELEASE_ELEMENTS_CRITICAL (bottomObject, bottomStart, 0);
+    bottomStart = NULL;
+    if (tempNeg)
+      {
+        if (!(bottomObject = internalBigIntegerNeg (env, bottomObject)))
+          goto error;
+        bottomLength = GET_LENGTH (bottomObject);
+      }
+
+    if (!(topStart = GET_ELEMENTS (topObject)))
+      goto error;
+    if (!(bottomStart = GET_ELEMENTS (bottomObject)))
+      goto error;
+
+    /* Get the magnitude of the bottom integer */
+    bottomSize = bottomLength * 2;
+    while (!bottomStart[at (bottomSize - 1)])
+      bottomSize--;
+
+    /* Get the magnitude of the top integer, will need a 0 on the end */
+    topSize = topLength * 2;
+    while (topSize > 1 && !topStart[at (topSize - 1)]
+      && !topStart[at (topSize - 2)])
+      topSize--;
+
+    /* easy case of divide by a U32 - answer is a U32 */
+    if (bottomSize == 1)
+      {
+        U_64 temp;
+        U_32 divisor = bottomStart[at (0)];
+
+        if (topSize > 1 && !topStart[at (topSize - 1)])
+          topSize--;
+
+        resultLength = resultSize = 1;
+        if (!(resultObject = NEW_OBJECT (resultLength)))
+          goto error;
+        if (!(resultStart = GET_ELEMENTS (resultObject)))
+          goto error;
+
+        topAt = topSize - 1;
+
+        HIGH_LONG (temp) = 0;
+        do
+          {
+            LOW_LONG (temp) = topStart[at (topAt--)];
+            HIGH_LONG (temp) = LONG_REM (&temp, divisor);
+          }
+        while (!(--topSize == 0));
+
+        resultStart[at (0)] = HIGH_LONG (temp);
+
+        RELEASE_ELEMENTS (topObject, topStart, 0);
+        goto finished;
+      }
+
+  /* ensure top starts with a zero int */
+  if (topStart[at (topSize - 1)] != 0)
+    {
+      if (topSize >= topLength * 2)
+        {     /* allocate extra space */
+          IDATA i;
+          U_32 *tempPtr;
+          jlongArray tempObject;
+          if (!(tempObject = NEW_OBJECT (topLength + 1)))
+            goto error;   /* initialized to zero */
+          if (!(tempPtr = GET_ELEMENTS (tempObject)))
+            goto error;
+          for (i = 0; i < copysize (topSize); i++)
+            tempPtr[i] = topStart[i];
+          RELEASE_ELEMENTS (topObject, topStart, 0);
+          topObject = tempObject;
+          topStart = tempPtr;
+          topLength++;
+          topZeroAdded = 1;
+        }
+      topSize++;
+    }
+
+  /* If the bottom int is larger than the top int, the result is the top
+  int.  Subtract one from the topSize before comparison to account for
+  the 0 added to the end.
+  */
+  if (bottomSize > (topSize - 1))
+    {
+      /* clean up and ensure we are returning a new long[] with the same value as that passed in */
+      RELEASE_ELEMENTS (bottomObject, bottomStart, 0);
+      bottomStart = NULL;
+
+      if (!topZeroAdded)
+        {
+          if (firstNegative)
+            {
+              /* un-negate to get a copy */
+              RELEASE_ELEMENTS (topObject, topStart, 0);
+              topStart = NULL;
+              if (!(resultObject = internalBigIntegerNeg (env, topObject)))
+                goto error;
+            }
+          else
+            {
+              /* we still have the original top, so must copy before returning because
+              we don't want to return the passed in object */
+              if (!(resultObject = NEW_OBJECT (topLength)))
+                goto error;
+              if (!(resultStart = GET_ELEMENTS (resultObject)))
+                goto error;
+              for (i = 0; i < copysize (topSize); i++)
+                resultStart[i] = topStart[i];
+              RELEASE_ELEMENTS (topObject, topStart, 0);
+              RELEASE_ELEMENTS (resultObject, resultStart, 1);
+            }
+        }
+      else if (topZeroAdded)
+        {
+          /* else topObject is already a copy, normalize it and return */
+          RELEASE_ELEMENTS (topObject, topStart, 1);
+          topStart = NULL;
+          if (!(resultObject = internalBigIntegerNormalize (env, topObject)))
+            goto error;
+          if (firstNegative)
+            if (!(resultObject = internalBigIntegerNeg (env, resultObject)))
+              goto error;
+        }
+      return resultObject;
+    }
+
+    /* Shift the bottom int until its high bit is set */
+
+    highDigit = bottomSize - 1;
+    shift = 0;
+    signedTemp = (I_32) bottomStart[at (highDigit)];
+    while (signedTemp >= 0)
+      ++shift, signedTemp <<= 1;
+    LEFT_SHIFT (bottomStart, bottomSize, shift);
+    LEFT_SHIFT (topStart, topSize, shift);
+    v1 = bottomStart[at (highDigit)];
+    v2 = bottomStart[at (highDigit - 1)];
+    j = topSize - bottomSize;
+
+    /* Initialize */
+
+    /* algorithm wants to make the result a modified (in place) top,
+    * so allocate new result and copy top into it, point top at the result */
+    resultLength = topLength;
+    if (!(resultObject = NEW_OBJECT (resultLength)))
+      goto error;
+    if (!(resultStart = GET_ELEMENTS (resultObject)))
+      goto error;
+    resultSize = topSize;
+    for (i = 0; i < resultLength * 2; i++)
+      resultStart[i] = topStart[i];
+
+    /* release top object now, then point at result object */
+    RELEASE_ELEMENTS (topObject, topStart, 0);
+    topStart = resultStart;
+    topAt = 0;
+
+    resultAt = resultSize;
+    bottomAt = 0;
+    fromPtr = topAt + topSize - 1;
+    fromPtr2 = fromPtr - 1;
+    multPtr = topAt + j;
+
+    /* Calculate the digits of the result */
+
+    do
+      {
+        U_64 t1;
+        U_64 t2;
+        U_32 qHat;
+        IDATA from, to;
+        U_32 size;
+        U_32 carry;
+
+        /* Calculate qHat */
+
+        if ((HIGH_LONG (t1) = topStart[at (fromPtr--)]) == v1)
+          {
+            qHat = 0xFFFFFFFF;
+            --fromPtr2;
+          }
+        else
+          {
+            LOW_LONG (t1) = topStart[at (fromPtr)];
+            qHat = LONG_DIV (&t1, v1);
+            HIGH_LONG (t2) = LONG_REM (&t1, v1);
+            LOW_LONG (t2) = topStart[at (--fromPtr2)];
+            LONG_MULT (qHat, v2, &t1);
+            while (U64_GREATER (&t1, &t2))
+              {
+                --qHat;
+                carry = 0;
+                HIGH_LONG (t2) =
+                  internalIntegerAddWithCarry (HIGH_LONG (t2), v1, &carry);
+                /* Stop if t2 grows larger than a U_64 */
+                if (carry)
+                  {
+                    break;
+                  }
+                U64_SUBTRACT_LONG (&t1, v2);
+              }
+          }
+
+        /* Subtract factored part */
+
+        from = bottomAt;
+        to = --multPtr;
+        size = bottomSize;
+        LOW_LONG (t1) = 0;
+        carry = 0;
+        do
+          {
+            HIGH_LONG (t1) = 0;
+            LONG_MULT (bottomStart[at (from++)], qHat, &t2);
+            U64_ADD (&t1, &t2);
+            topStart[at (to)] =
+              internalIntegerSubtractWithCarry (topStart[at (to)],
+              LOW_LONG (t1), &carry);
+            to++;
+            LOW_LONG (t1) = HIGH_LONG (t1);
+          }
+        while (!(--size == 0));
+        topStart[at (to)] =
+          internalIntegerSubtractWithCarry (topStart[at (to)], LOW_LONG (t1),
+          &carry);
+
+        /* Check for add back */
+
+        if (carry)
+          {
+            carry = 0;
+            from = bottomAt;
+            to = multPtr;
+            size = bottomSize;
+            do
+              {
+                topStart[at (to)] =
+                  internalIntegerAddWithCarry (topStart[at (to)],
+                  bottomStart[at (from++)],
+                  &carry);
+                to++;
+              }
+            while (!(--size == 0));
+            topStart[at (to)] = 0;
+          }
+      }
+    while (!(--j == 0));
+
+    /* Shift the result int back */
+    RIGHT_SHIFT (resultStart, resultSize, shift);
+
+    finished:
+    /* release objects */
+    RELEASE_ELEMENTS (bottomObject, bottomStart, 0);
+    RELEASE_ELEMENTS (resultObject, resultStart, 1);
+
+    /* ensure result is normalized */
+    if (!(resultObject = internalBigIntegerNormalize (env, resultObject)))
+      return NULL;
+    /* If top integer was negative, the result must be negated.     */
+    if (firstNegative)
+      if (!(resultObject = internalBigIntegerNeg (env, resultObject)))
+        return NULL;
+    return resultObject;
+
+    error:
+    if (topStart)
+      RELEASE_ELEMENTS (topObject, topStart, 0);
+    if (bottomStart)
+      RELEASE_ELEMENTS (bottomObject, bottomStart, 0);
+    if (resultStart)
+      RELEASE_ELEMENTS (resultObject, resultStart, 0);
+    return NULL;
+  }
+
+jlongArray JNICALL
+Java_com_ibm_oti_util_math_BigInteger_shlImpl (JNIEnv * env, jclass cls,
+                                               jlongArray src, jint shiftval)
+  {
+    IDATA len, lenR;
+    jlongArray resultObject;
+    U_64 *ar = NULL, *shifted = NULL;
+    IDATA oldAt, newAt, shiftvalr, shortenedFlag = 0;
+
+    len = GET_LENGTH (src);
+
+    if (shiftval > 0)
+      {       /* shift left */
+        oldAt = 0, newAt = shiftval / 64;
+        shiftval = shiftval % 64;
+        shiftvalr = 64 - shiftval;
+        lenR = len + newAt + 1;
+
+        /* attemp to pre-normalize */
+        if (!(ar = (U_64 *) GET_ELEMENTS_CRITICAL (src)))
+          goto error;
+        if (shiftval == 0
+          || ((((I_64) ar[len - 1]) >> shiftvalr) == 0
+          && (((I_64) ar[len - 1]) << shiftval) > 0))
+          shortenedFlag = 1, lenR--;
+        RELEASE_ELEMENTS_CRITICAL (src, ar, 0);
+        ar = NULL;
+
+        if (!(resultObject = NEW_OBJECT (lenR)))
+          goto error;
+        if (!(ar = (U_64 *) GET_ELEMENTS_CRITICAL (src)))
+          goto error;
+        if (!(shifted = (U_64 *) GET_ELEMENTS_CRITICAL (resultObject)))
+          goto error;
+        if (shiftval == 0)
+          {
+            /* straight copy */
+            for (; oldAt < len; oldAt++, newAt++)
+              shifted[newAt] = ar[oldAt];
+          }
+        else
+          {
+            /* zero extend low word */
+            shifted[newAt++] = (ar[oldAt++] << shiftval);
+            for (; oldAt < len; oldAt++, newAt++)
+              shifted[newAt] =
+              (ar[oldAt] << shiftval) | (ar[oldAt - 1] >> shiftvalr);
+            /* sign extend high word */
+            if (!shortenedFlag)
+              shifted[newAt] = (((I_64) ar[oldAt - 1]) >> shiftvalr);
+          }
+      }
+    else if (shiftval < 0)
+      {       /* shift right */
+        shiftval = -shiftval;
+        oldAt = shiftval / 64, newAt = 0;
+        shiftval = shiftval % 64;
+        shiftvalr = 64 - shiftval;
+        if (oldAt >= len)
+          {
+            /* shifting off the end */
+            if (!(resultObject = NEW_OBJECT (1)))
+              goto error;
+            if (!(shifted = (U_64 *) GET_ELEMENTS_CRITICAL (resultObject)))
+              goto error;
+            if (!(ar = (U_64 *) GET_ELEMENTS_CRITICAL (src)))
+              goto error;
+            shifted[0] = (((I_64) ar[len - 1]) < 0) ? -1 : 0;
+            RELEASE_ELEMENTS_CRITICAL (src, ar, 0);
+            RELEASE_ELEMENTS_CRITICAL (resultObject, shifted, 1);
+            return resultObject;
+          }
+        else
+          {
+            lenR = len - oldAt;
+            if (lenR <= 1)
+              lenR = 1;
+            else
+              {
+                /* attemp to pre-normalize */
+                if (!(ar = (U_64 *) GET_ELEMENTS_CRITICAL (src)))
+                  goto error;
+                if (shiftval != 0
+                  && ((((I_64) ar[len - 1]) >> shiftval) == 0
+                  && (((I_64) ar[len - 1]) << shiftvalr) > 0))
+                  shortenedFlag = 1, lenR--;
+                RELEASE_ELEMENTS_CRITICAL (src, ar, 0);
+                ar = NULL;
+              }
+
+            if (!(resultObject = NEW_OBJECT (lenR)))
+              goto error;
+            if (!(ar = (U_64 *) GET_ELEMENTS_CRITICAL (src)))
+              goto error;
+            if (!(shifted = (U_64 *) GET_ELEMENTS_CRITICAL (resultObject)))
+              goto error;
+            if (shiftval == 0)
+              {
+                /* straight copy */
+                for (; oldAt < len; oldAt++, newAt++)
+                  shifted[newAt] = ar[oldAt];
+              }
+            else
+              {
+                for (; oldAt < len - 1; oldAt++, newAt++)
+                  shifted[newAt] =
+                  (ar[oldAt] >> shiftval) | (ar[oldAt + 1] << shiftvalr);
+                /* sign extend high word */
+                if (!shortenedFlag)
+                  shifted[newAt] = (((I_64) ar[oldAt]) >> shiftval);
+              }
+          }
+      }
+    else
+      {
+        /* shift by zero - do nothing */
+        return src;
+      }
+
+    RELEASE_ELEMENTS_CRITICAL (src, ar, 0);
+    RELEASE_ELEMENTS_CRITICAL (resultObject, shifted, 1);
+
+    /* ensure result is normalized */
+    if (!(resultObject = internalBigIntegerNormalize (env, resultObject)))
+      return NULL;
+    return resultObject;
+
+  error:
+    if (ar)
+      RELEASE_ELEMENTS_CRITICAL (src, ar, 0);
+    if (shifted)
+      RELEASE_ELEMENTS_CRITICAL (resultObject, shifted, 0);
+    return NULL;
+  }
+
+jlongArray JNICALL
+Java_com_ibm_oti_util_math_BigInteger_subImpl (JNIEnv * env, jclass cls,
+                                               jlongArray src1,
+                                               jlongArray src2)
+  {
+    jlongArray negSrc2;
+    negSrc2 = internalBigIntegerNeg (env, src2);
+    if (!negSrc2)     /* OutOfMemory exception was thrown */
+      return NULL;
+    /* add returns normalized number, so we don't need to renormalize */
+    return internalBigIntegerAdd (env, src1, negSrc2);
+  }
+
+static U_32
+internalIntegerAddWithCarry (U_32 a1, U_32 a2, U_32 * carry)
+  {
+    U_32 result = a1 + a2 + *carry;
+    *carry = ((a1 > result) || ((a1 == result) && (*carry == 1))) ? 1 : 0;
+    return (result);
+  }
+
+static U_32
+internalIntegerSubtractWithCarry (U_32 a1, U_32 a2, U_32 * carry)
+  {
+    U_32 result = a1 - a2 - *carry;
+    *carry = ((a2 > a1) || ((a2 == a1) && (*carry == 1))) ? 1 : 0;
+    return (result);
+  }
+
+jlongArray
+internalBigIntegerNormalize (JNIEnv * env, jlongArray src1)
+  {
+    IDATA len1, lenR;
+    jlong *ar1, *arR;
+    IDATA neg1 = 0;
+    jlongArray resultObject = NULL;
+
+    len1 = GET_LENGTH (src1);
+    if (!(ar1 = (jlong *) GET_ELEMENTS_CRITICAL (src1)))
+      goto done;
+    neg1 = IS_NEGATIVE (ar1, len1);
+
+    lenR = len1;
+    if (neg1)
+      {
+        while (lenR >= 2 && ar1[lenR - 1] == -1L && ar1[lenR - 2] < 0L)
+          {
+          lenR--;
+          }
+      }
+    else
+      {
+        while (lenR >= 2 && ar1[lenR - 1] == 0L && ar1[lenR - 2] >= 0L)
+          {
+          lenR--;
+          }
+      }
+    RELEASE_ELEMENTS_CRITICAL (src1, ar1, 0);
+    if (lenR == len1)
+      return src1;
+
+    if (!(resultObject = NEW_OBJECT (lenR)))
+      goto done;
+    if (!(ar1 = (jlong *) GET_ELEMENTS_CRITICAL (src1)))
+      goto done;
+    if (!(arR = (jlong *) GET_ELEMENTS_CRITICAL (resultObject)))
+      goto release1;
+    memcpy (arR, ar1, lenR * sizeof (jlong));
+    RELEASE_ELEMENTS_CRITICAL (resultObject, arR, 0);
+
+  release1:
+    RELEASE_ELEMENTS_CRITICAL (src1, ar1, 0);
+  done:
+    return resultObject;
+  }
+
+jlongArray
+grow (JNIEnv * env, jlongArray src1, jlong element)
+  {
+    IDATA len1;
+    jlong *ar1, *arR;
+    jlongArray resultObject = NULL;
+
+    len1 = GET_LENGTH (src1);
+    if (!(resultObject = NEW_OBJECT (len1 + 1)))
+      goto done;
+
+    if (!(ar1 = (jlong *) GET_ELEMENTS_CRITICAL (src1)))
+      goto done;
+    if (!(arR = (jlong *) GET_ELEMENTS_CRITICAL (resultObject)))
+      goto release1;
+    memcpy (arR, ar1, len1 * sizeof (jlong));
+    arR[len1] = element;
+    RELEASE_ELEMENTS_CRITICAL (resultObject, arR, 0);
+
+  release1:
+    RELEASE_ELEMENTS_CRITICAL (src1, ar1, 0);
+  done:
+    return resultObject;
+  }
+
+jlongArray
+internalBigIntegerAdd (JNIEnv * env, jlongArray src1, jlongArray src2)
+  {
+    IDATA len1, len2;
+    U_64 *ar1, *ar2, *arR, s, s2, r;
+    IDATA neg1, neg2, negR, i;
+    jlongArray resultObject = NULL;
+    U_32 carry = 0;
+
+    len1 = GET_LENGTH (src1);
+    len2 = GET_LENGTH (src2);
+    if (len2 > len1)
+      {
+        /* Swap src1 and src2, so src1 is longer */
+        void *temp;
+        IDATA tempint;
+        temp = src1;
+        src1 = src2;
+        src2 = temp;
+        tempint = len1;
+        len1 = len2;
+        len2 = tempint;
+      }
+
+    if (!(resultObject = NEW_OBJECT (len1)))
+      goto done;
+
+    if (!(ar1 = (U_64 *) GET_ELEMENTS_CRITICAL (src1)))
+      goto done;
+    if (!(ar2 = (U_64 *) GET_ELEMENTS_CRITICAL (src2)))
+      goto release1;
+    if (!(arR = (U_64 *) GET_ELEMENTS_CRITICAL (resultObject)))
+      goto release2;
+
+    for (i = 0; i < len2; i++)
+      {
+      arR[i] = r = (s = ar1[i]) + ar2[i] + carry;
+      carry = s > r || (s == r && carry == 1);
+      }
+
+    neg2 = IS_NEGATIVE (ar2, len2);
+    s2 = neg2 ? -1 : 0;
+    for (i = len2; i < len1; i++)
+      {
+      arR[i] = r = (s = ar1[i]) + s2 + carry;
+      carry = s > r || (s == r && carry == 1);
+      }
+
+    neg1 = IS_NEGATIVE (ar1, len1);
+    RELEASE_ELEMENTS_CRITICAL (src2, ar2, 0);
+    RELEASE_ELEMENTS_CRITICAL (src1, ar1, 0);
+
+    negR = IS_NEGATIVE (arR, len1);
+    RELEASE_ELEMENTS_CRITICAL (resultObject, arR, 0);
+
+    if (!neg1 && !neg2)
+      {
+        if (negR)
+          {
+            resultObject = grow (env, resultObject, 0);
+          }
+      }
+    else if (neg1 && neg2)
+      {
+        if (!negR)
+          {
+            resultObject = grow (env, resultObject, -1);
+          }
+      }
+    return internalBigIntegerNormalize (env, resultObject);
+
+  release2:
+    RELEASE_ELEMENTS_CRITICAL (src2, ar2, 0);
+  release1:
+    RELEASE_ELEMENTS_CRITICAL (src1, ar1, 0);
+  done:
+    return resultObject;
+  }
+
+jlongArray
+internalBigIntegerNeg (JNIEnv * env, jlongArray src1)
+  {
+    IDATA len1;
+    U_64 *ar1, *arN, *arO;
+    IDATA i;
+    jlongArray negObject, oneObject;
+    jlongArray resultObject = NULL;
+
+    len1 = GET_LENGTH (src1);
+    if (!(negObject = NEW_OBJECT (len1)))
+      goto done;
+    if (!(oneObject = NEW_OBJECT (1)))
+      goto done;
+
+    if (!(ar1 = (U_64 *) GET_ELEMENTS_CRITICAL (src1)))
+      goto done;
+    if (!(arN = (U_64 *) GET_ELEMENTS_CRITICAL (negObject)))
+      goto release1;
+    if (!(arO = (U_64 *) GET_ELEMENTS_CRITICAL (oneObject)))
+      goto releaseN;
+    arO[0] = 1;
+    RELEASE_ELEMENTS_CRITICAL (oneObject, arO, 0);
+
+    for (i = 0; i < len1; i++)
+      {
+        arN[i] = ~ar1[i];
+      }
+    RELEASE_ELEMENTS_CRITICAL (negObject, arN, 0);
+    RELEASE_ELEMENTS_CRITICAL (src1, ar1, 0);
+
+    resultObject = internalBigIntegerAdd (env, negObject, oneObject);
+    return resultObject;
+
+  releaseN:
+    RELEASE_ELEMENTS_CRITICAL (negObject, arN, 0);
+  release1:
+    RELEASE_ELEMENTS_CRITICAL (src1, ar1, 0);
+  done:
+    return resultObject;
+  }

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/bigint.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/bigint.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/bigint.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/bigint.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,36 @@
+/* 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(bigint_h)
+#define bigint_h
+jlongArray JNICALL Java_com_ibm_oti_util_math_BigInteger_subImpl
+PROTOTYPE ((JNIEnv * env, jclass cls, jlongArray src1, jlongArray src2));
+jlongArray JNICALL Java_com_ibm_oti_util_math_BigInteger_divImpl
+PROTOTYPE ((JNIEnv * env, jclass cls, jlongArray topObject,
+      jlongArray bottomObject));
+jlongArray JNICALL Java_com_ibm_oti_util_math_BigInteger_mulImpl
+PROTOTYPE ((JNIEnv * env, jclass cls, jlongArray src1, jlongArray src2));
+jlongArray JNICALL Java_com_ibm_oti_util_math_BigInteger_negImpl
+PROTOTYPE ((JNIEnv * env, jclass cls, jlongArray src));
+jlongArray JNICALL Java_com_ibm_oti_util_math_BigInteger_addImpl
+PROTOTYPE ((JNIEnv * env, jclass cls, jlongArray src1, jlongArray src2));
+jlongArray JNICALL Java_com_ibm_oti_util_math_BigInteger_remImpl
+PROTOTYPE ((JNIEnv * env, jclass cls, jlongArray topObject,
+      jlongArray bottomObject));
+jlongArray JNICALL Java_com_ibm_oti_util_math_BigInteger_shlImpl
+PROTOTYPE ((JNIEnv * env, jclass cls, jlongArray src, jint shiftval));
+jint JNICALL Java_com_ibm_oti_util_math_BigInteger_compImpl
+PROTOTYPE ((JNIEnv * env, jclass cls, jlongArray src1, jlongArray src2));
+#endif /* bigint_h */

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/file.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/file.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/file.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/file.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,517 @@
+/* Copyright 1998, 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.
+ */
+
+#include <string.h>
+#include <ctype.h>
+#include "iohelp.h"
+#include "jclglob.h"
+#include "helpers.h"
+#include "jclprots.h"
+
+jboolean JNICALL
+Java_java_io_File_deleteFileImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  I_32 result;
+  jsize length = (*env)->GetArrayLength (env, path);
+  char pathCopy[HyMaxPath];
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  result = hyfile_unlink (pathCopy);
+  return result == 0;
+}
+
+jboolean JNICALL
+Java_java_io_File_deleteDirImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  I_32 result;
+  jsize length = (*env)->GetArrayLength (env, path);
+  char pathCopy[HyMaxPath];
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  result = hyfile_unlinkdir (pathCopy);
+  return result == 0;
+}
+
+jobject JNICALL
+Java_java_io_File_listImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+  struct dirEntry
+  {
+    char pathEntry[HyMaxPath];
+    struct dirEntry *next;
+  } *dirList, *currentEntry;
+
+  PORT_ACCESS_FROM_ENV (env);
+  jsize length = (*env)->GetArrayLength (env, path);
+  char pathCopy[HyMaxPath];
+  char filename[HyMaxPath];
+  I_32 result = 0, index;
+  I_32 numEntries = 0;
+  UDATA findhandle;
+  jarray answer = NULL;
+
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  if (length >= 1 && pathCopy[length - 1] != '\\'
+      && pathCopy[length - 1] != '/')
+    {
+      pathCopy[length] = jclSeparator;
+      length++;
+    }
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  findhandle = hyfile_findfirst (pathCopy, filename);
+  if (findhandle == (UDATA) - 1)
+    return NULL;
+
+  while (result > -1)
+    {
+      if (strcmp (".", filename) != 0 && (strcmp ("..", filename) != 0))
+        {
+          if (numEntries > 0)
+            {
+              currentEntry->next =
+                (struct dirEntry *) jclmem_allocate_memory (env,
+                sizeof (struct
+                dirEntry));
+              currentEntry = currentEntry->next;
+            }
+          else
+            {
+              dirList =
+                (struct dirEntry *) jclmem_allocate_memory (env,
+                sizeof (struct
+                dirEntry));
+              currentEntry = dirList;
+            }
+          if (currentEntry == NULL)
+            {
+              hyfile_findclose (findhandle);
+              throwNewOutOfMemoryError (env, "");
+              goto cleanup;
+            }
+          strcpy (currentEntry->pathEntry, filename);
+          numEntries++;
+        }
+      result = hyfile_findnext (findhandle, filename);
+    }
+  hyfile_findclose (findhandle);
+
+  if (numEntries == 0)
+    return NULL;
+
+  answer =
+    (*env)->NewObjectArray (env, numEntries,
+          JCL_CACHE_GET (env, CLS_array_of_byte), NULL);
+cleanup:
+  for (index = 0; index < numEntries; index++)
+    {
+      jbyteArray entrypath;
+      jsize entrylen = strlen (dirList->pathEntry);
+      currentEntry = dirList;
+      if (answer)
+        {
+          entrypath = (*env)->NewByteArray (env, entrylen);
+          (*env)->SetByteArrayRegion (env, entrypath, 0, entrylen,
+            (jbyte *) dirList->pathEntry);
+          (*env)->SetObjectArrayElement (env, answer, index, entrypath);
+          (*env)->DeleteLocalRef (env, entrypath);
+        }
+      dirList = dirList->next;
+      jclmem_free_memory (env, currentEntry);
+    }
+  return answer;
+}
+
+jboolean JNICALL
+Java_java_io_File_isDirectoryImpl (JNIEnv * env, jobject recv,
+           jbyteArray path)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  I_32 result;
+  jsize length = (*env)->GetArrayLength (env, path);
+  char pathCopy[HyMaxPath];
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  result = hyfile_attr (pathCopy);
+  return result == HyIsDir;
+}
+
+jboolean JNICALL
+Java_java_io_File_existsImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  I_32 result;
+  char pathCopy[HyMaxPath];
+  jsize length = (*env)->GetArrayLength (env, path);
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  result = hyfile_attr (pathCopy);
+  return result >= 0;
+}
+
+jboolean JNICALL
+Java_java_io_File_isFileImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  I_32 result;
+  jsize length = (*env)->GetArrayLength (env, path);
+  char pathCopy[HyMaxPath];
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  result = hyfile_attr (pathCopy);
+  return result == HyIsFile;
+}
+
+jlong JNICALL
+Java_java_io_File_lastModifiedImpl (JNIEnv * env, jobject recv,
+            jbyteArray path)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  I_64 result;
+  jsize length = (*env)->GetArrayLength (env, path);
+  char pathCopy[HyMaxPath];
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  result = hyfile_lastmod (pathCopy);
+  return result;
+}
+
+jlong JNICALL
+Java_java_io_File_lengthImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  I_64 result;
+  jsize length = (*env)->GetArrayLength (env, path);
+  char pathCopy[HyMaxPath];
+
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  result = hyfile_length (pathCopy);
+  if (result < 0)
+    {
+      return 0L;
+    }
+  return result;
+}
+
+jboolean JNICALL
+Java_java_io_File_isAbsoluteImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+  I_32 result = 0;
+  jsize length = (*env)->GetArrayLength (env, path);
+  jbyte *lpath = (jbyte *) ((*env)->GetPrimitiveArrayCritical (env, path, 0));
+
+  if (jclSeparator == '/' && length > 0)
+    {
+      result = (lpath[0] == jclSeparator);
+      goto release;
+    }
+  if (length > 1 && lpath[0] == '\\' && lpath[1] == '\\')
+    {
+      result = 1;
+      goto release;
+    }
+  if (length > 2)
+    {
+      if (isalpha (lpath[0]) && lpath[1] == ':'
+        && (lpath[2] == '\\' || lpath[2] == '/'))
+        result = 1;
+    }
+
+release:
+  /* Easier to release in one area than copy the code around */
+  (*env)->ReleasePrimitiveArrayCritical (env, path, lpath, JNI_ABORT);
+  return result;
+}
+
+jboolean JNICALL
+Java_java_io_File_mkdirImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  I_32 result;
+  jsize length = (*env)->GetArrayLength (env, path);
+  char pathCopy[HyMaxPath];
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  result = hyfile_mkdir (pathCopy);
+  return result == 0;
+}
+
+jboolean JNICALL
+Java_java_io_File_renameToImpl (JNIEnv * env, jobject recv,
+        jbyteArray pathExist, jbyteArray pathNew)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  I_32 result;
+  jsize length;
+  char pathExistCopy[HyMaxPath], pathNewCopy[HyMaxPath];
+  length = (*env)->GetArrayLength (env, pathExist);
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, pathExist, 0, length, pathExistCopy));
+  pathExistCopy[length] = '\0';
+  length = (*env)->GetArrayLength (env, pathNew);
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, pathNew, 0, length, pathNewCopy));
+  pathNewCopy[length] = '\0';
+  ioh_convertToPlatform (pathExistCopy);
+  ioh_convertToPlatform (pathNewCopy);
+  result = hyfile_move (pathExistCopy, pathNewCopy);
+  return result == 0;
+}
+
+jobject JNICALL
+Java_java_io_File_getCanonImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+  /* This needs work.
+   * Should figure out '..', '.', and really resolve references.
+   */
+  jbyteArray answer;
+  jsize answerlen;
+  char pathCopy[HyMaxPath];
+  U_32 length = (U_32) (*env)->GetArrayLength (env, path);
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  (*env)->GetByteArrayRegion (env, path, 0, length, pathCopy);
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+#if defined(WIN32)
+  platformCanonicalPath (pathCopy);
+#endif
+
+  answerlen = strlen (pathCopy);
+  answer = (*env)->NewByteArray (env, answerlen);
+  (*env)->SetByteArrayRegion (env, answer, 0, answerlen, (jbyte *) pathCopy);
+  return answer;
+}
+
+jint JNICALL
+Java_java_io_File_newFileImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  I_32 result;
+  IDATA portFD;
+  jsize length = (*env)->GetArrayLength (env, path);
+  char pathCopy[HyMaxPath];
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+
+  /* First check to see if file already exists */
+  result = hyfile_attr (pathCopy);
+  if (result == HyIsDir)
+    return 3;
+  if (result >= 0)
+    return 1;
+
+  /* Now create the file and close it */
+  portFD =
+    hyfile_open (pathCopy, HyOpenCreate | HyOpenWrite | HyOpenTruncate, 0666);
+  if (portFD == -1)
+    return 2;
+  hyfile_close (portFD);
+  return 0;
+}
+
+jobject JNICALL
+Java_java_io_File_rootsImpl (JNIEnv * env, jclass clazz)
+{
+  char rootStrings[HyMaxPath], *rootCopy;
+  I_32 numRoots;
+  I_32 index = 0;
+  jarray answer;
+
+  /**
+   * It is the responsibility of #getPlatformRoots to return a char array
+   * with volume names separated by null with a trailing extra null, so for
+   * Unix it should be '\<null><null>' .
+   */
+  numRoots = getPlatformRoots (rootStrings);
+  if (numRoots == 0)
+    return NULL;
+  rootCopy = rootStrings;
+
+  answer =
+    (*env)->NewObjectArray (env, numRoots,
+          JCL_CACHE_GET (env, CLS_array_of_byte), NULL);
+  if (!answer)
+    {
+      return NULL;
+    }
+  while (TRUE)
+    {
+      jbyteArray rootname;
+      jsize entrylen = strlen (rootCopy);
+      /* Have we hit the second null? */
+      if (entrylen == 0)
+        break;
+      rootname = (*env)->NewByteArray (env, entrylen);
+      (*env)->SetByteArrayRegion (env, rootname, 0, entrylen,
+        (jbyte *) rootCopy);
+      (*env)->SetObjectArrayElement (env, answer, index++, rootname);
+      (*env)->DeleteLocalRef (env, rootname);
+      rootCopy = rootCopy + entrylen + 1;
+    }
+  return answer;
+}
+
+jboolean JNICALL
+Java_java_io_File_isHiddenImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+  I_32 result;
+  char pathCopy[HyMaxPath];
+  jsize length = (*env)->GetArrayLength (env, path);
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  result = getPlatformIsHidden (env, pathCopy);
+  return result;
+}
+
+jboolean JNICALL
+Java_java_io_File_setLastModifiedImpl (JNIEnv * env, jobject recv,
+               jbyteArray path, jlong time)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  I_32 result;
+  jsize length = (*env)->GetArrayLength (env, path);
+  char pathCopy[HyMaxPath];
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+
+  result = setPlatformLastModified (env, pathCopy, (I_64) time);
+
+  return result;
+}
+
+jboolean JNICALL
+Java_java_io_File_setReadOnlyImpl (JNIEnv * env, jobject recv,
+           jbyteArray path)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  jsize length = (*env)->GetArrayLength (env, path);
+  char pathCopy[HyMaxPath];
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  return setPlatformReadOnly (env, pathCopy);
+}
+
+void JNICALL
+Java_java_io_File_oneTimeInitialization (JNIEnv * env, jclass clazz)
+{
+  jclass arrayClass = (*env)->FindClass (env, "[B");
+  if (arrayClass)
+    {
+      jobject globalRef = (*env)->NewWeakGlobalRef (env, arrayClass);
+      if (globalRef)
+        JCL_CACHE_SET (env, CLS_array_of_byte, globalRef);
+    }
+  return;
+}
+
+jbyteArray JNICALL
+Java_java_io_File_properPathImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+  return getPlatformPath (env, path);
+}
+
+jboolean JNICALL
+Java_java_io_File_isReadOnlyImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+  I_32 result;
+  char pathCopy[HyMaxPath];
+  jsize length = (*env)->GetArrayLength (env, path);
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  result = getPlatformIsReadOnly (env, pathCopy);
+  return result;
+}
+
+jboolean JNICALL
+Java_java_io_File_isWriteOnlyImpl (JNIEnv * env, jobject recv,
+           jbyteArray path)
+{
+  I_32 result;
+  char pathCopy[HyMaxPath];
+  jsize length = (*env)->GetArrayLength (env, path);
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  result = getPlatformIsWriteOnly (env, pathCopy);
+  return result;
+}
+
+jobject JNICALL
+Java_java_io_File_getLinkImpl (JNIEnv * env, jobject recv, jbyteArray path)
+{
+  jbyteArray answer;
+  jsize answerlen;
+  char pathCopy[HyMaxPath];
+  U_32 length = (U_32) (*env)->GetArrayLength (env, path);
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  (*env)->GetByteArrayRegion (env, path, 0, length, pathCopy);
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+  if (platformReadLink (pathCopy))
+    {
+      answerlen = strlen (pathCopy);
+      answer = (*env)->NewByteArray (env, answerlen);
+      (*env)->SetByteArrayRegion (env, answer, 0, answerlen,
+          (jbyte *) pathCopy);
+    }
+  else
+    {
+      answer = path;
+    }
+  return answer;
+}
+
+jboolean JNICALL
+Java_java_io_File_isCaseSensitiveImpl (JNIEnv * env, jclass clazz)
+{
+/* Assume all other platforms ARE case sensitive and add to this list when they prove otherwise */
+#if (defined(WIN32))
+  return FALSE;
+#else
+  return TRUE;
+#endif
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/filedesc.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/filedesc.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/filedesc.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/filedesc.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,68 @@
+/* Copyright 1998, 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.
+ */
+
+#include "iohelp.h"
+#include "jclglob.h"
+
+jboolean JNICALL
+Java_java_io_FileDescriptor_valid (JNIEnv * env, jobject recv)
+{
+  /* Currently only answer false if the descriptor is -1.  Possibly there * could be an OS check to see if the handle 
+     has been invalidated */
+  void *descriptor = getJavaIoFileDescriptorContentsAsPointer (env, recv);
+  return (IDATA) descriptor != -1;
+}
+
+void JNICALL
+Java_java_io_FileDescriptor_sync (JNIEnv * env, jobject recv)
+{
+  /* Cause all unwritten data to be written out to the OS */
+  IDATA descriptor;
+  I_32 syncfailed = 0;
+  PORT_ACCESS_FROM_ENV (env);
+
+  descriptor = (IDATA) getJavaIoFileDescriptorContentsAsPointer (env, recv);
+  if (descriptor == -1)
+    {
+      syncfailed = 1;
+    }
+  if (!syncfailed && (descriptor > 2))
+    {
+      /* Don't attempt to sync stdin, out, or err */
+      syncfailed = hyfile_sync (descriptor) != 0;
+    }
+  if (syncfailed)
+    {
+      /* Find and throw SyncFailedException */
+      jclass exceptionClass = (*env)->FindClass(env, "java/io/SyncFailedException");
+      if (0 == exceptionClass) { 
+        /* Just return if we can't load the exception class. */
+        return;
+        }
+      (*env)->ThrowNew(env, exceptionClass, "Failed to Sync File");
+      return;
+    }
+}
+
+void JNICALL
+Java_java_io_FileDescriptor_oneTimeInitialization (JNIEnv * env,
+               jclass fdClazz)
+{
+  jfieldID descriptorFID =
+    (*env)->GetFieldID (env, fdClazz, "descriptor", "J");
+  if (!descriptorFID)
+    return;
+  JCL_CACHE_SET (env, FID_java_io_FileDescriptor_descriptor, descriptorFID);
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/fileis.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/fileis.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/fileis.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/fileis.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,132 @@
+/* Copyright 1998, 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.
+ */
+
+#include "iohelp.h"
+#include "jclglob.h"
+
+jlong JNICALL
+Java_java_io_FileInputStream_skip (JNIEnv * env, jobject recv, jlong count)
+{
+  jobject fd;
+  IDATA descriptor;
+  I_64 currentPosition, endOfFile, charsToSkip;
+  PORT_ACCESS_FROM_ENV (env);
+  if (count <= 0)
+    return 0;
+
+  fd =
+    (*env)->GetObjectField (env, recv,
+          JCL_CACHE_GET (env,
+             FID_java_io_FileInputStream_fd));
+  descriptor = (IDATA) getJavaIoFileDescriptorContentsAsPointer (env, fd);
+
+  if (descriptor == -1)
+    {
+      throwJavaIoIOExceptionClosed (env);
+      return 0;
+    }
+
+  currentPosition = hyfile_seek (descriptor, 0, HySeekCur);
+  endOfFile = hyfile_seek (descriptor, 0, HySeekEnd);
+  charsToSkip = (I_64) count > endOfFile
+    || (endOfFile - (I_64) count <
+  currentPosition) ? endOfFile - currentPosition : (I_64) count;
+  hyfile_seek (descriptor, charsToSkip + currentPosition, HySeekSet);
+  return (jlong) charsToSkip;
+}
+
+jint JNICALL
+Java_java_io_FileInputStream_openImpl (JNIEnv * env, jobject recv,
+               jbyteArray path)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  IDATA portFD;
+  jobject fd;
+  jsize length;
+  char pathCopy[HyMaxPath];
+  if (path == NULL)
+    {
+      throwNPException (env, "path is null");
+      return 0;
+    }
+  length = (*env)->GetArrayLength (env, path);
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+
+  /* Now have the filename, open the file using a portlib call */
+  portFD = hyfile_open (pathCopy, (I_32) HyOpenRead, (I_32) 0);
+
+  if (portFD == -1)
+    return 1;
+
+  fd =
+    (*env)->GetObjectField (env, recv,
+          JCL_CACHE_GET (env,
+             FID_java_io_FileInputStream_fd));
+  setJavaIoFileDescriptorContentsAsPointer (env, fd, (void *) portFD);
+  return 0;
+}
+
+jint JNICALL
+Java_java_io_FileInputStream_available (JNIEnv * env, jobject recv)
+{
+  /* Call the helper. The helper may throw an exception so either * check for -1 or return immediately */
+  return new_ioh_available (env, recv,
+          JCL_CACHE_GET (env,
+             FID_java_io_FileInputStream_fd));
+}
+
+jint JNICALL
+Java_java_io_FileInputStream_readImpl (JNIEnv * env, jobject recv,
+               jbyteArray buffer, jint offset,
+               jint count, jlong descriptor)
+{
+  /* Call the helper. The helper may throw an exception so this
+   * must return immediately.
+   */
+  return ioh_readbytesImpl (env, recv, buffer, offset, count,
+          (IDATA) descriptor);
+}
+
+jint JNICALL
+Java_java_io_FileInputStream_readByteImpl (JNIEnv * env, jobject recv,
+             jlong descriptor)
+{
+  /* Call the helper. The helper may throw an exception so this
+   * must return immediately.
+   */
+  return ioh_readcharImpl (env, recv, (IDATA) descriptor);
+}
+
+void JNICALL
+Java_java_io_FileInputStream_oneTimeInitialization (JNIEnv * env,
+                jclass clazz)
+{
+  jfieldID fdFID =
+    (*env)->GetFieldID (env, clazz, "fd", "Ljava/io/FileDescriptor;");
+  if (!fdFID)
+    return;
+  JCL_CACHE_SET (env, FID_java_io_FileInputStream_fd, fdFID);
+}
+
+void JNICALL
+Java_java_io_FileInputStream_closeImpl (JNIEnv * env, jobject recv)
+{
+  /* Call the helper */
+  new_ioh_close (env, recv,
+     JCL_CACHE_GET (env, FID_java_io_FileInputStream_fd));
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/fileos.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/fileos.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/fileos.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/fileos.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,104 @@
+/* Copyright 1998, 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.
+ */
+
+#include <string.h>
+#include "iohelp.h"
+#include "jclglob.h"
+
+jint JNICALL
+Java_java_io_FileOutputStream_openImpl (JNIEnv * env, jobject recv,
+          jbyteArray path, jboolean append)
+{
+  jobject fd;
+  I_32 flags =
+    append ==
+    0 ? HyOpenCreate | HyOpenWrite | HyOpenTruncate : HyOpenWrite |
+    HyOpenCreate;
+  IDATA portFD;
+  PORT_ACCESS_FROM_ENV (env);
+  jsize length;
+  char pathCopy[HyMaxPath];
+
+  if (path == NULL)
+    {
+      throwNPException (env, "path is null");
+      return 0;
+    }
+  length = (*env)->GetArrayLength (env, path);
+  length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+  ((*env)->GetByteArrayRegion (env, path, 0, length, pathCopy));
+  pathCopy[length] = '\0';
+  ioh_convertToPlatform (pathCopy);
+
+  /* Now have the filename, open the file using a portlib call */
+  portFD = hyfile_open (pathCopy, flags, 0666);
+
+  if (portFD == -1)
+    {
+      return 1;
+    }
+
+  if (append != 0)
+    {
+      hyfile_seek (portFD, 0, HySeekEnd);
+    }
+
+  fd =
+    (*env)->GetObjectField (env, recv,
+          JCL_CACHE_GET (env,
+             FID_java_io_FileOutputStream_fd));
+  setJavaIoFileDescriptorContentsAsPointer (env, fd, (void *) portFD);
+  return 0;
+}
+
+void JNICALL
+Java_java_io_FileOutputStream_writeImpl (JNIEnv * env, jobject recv,
+           jbyteArray buffer, jint offset,
+           jint count, jlong descriptor)
+{
+  /* Call the helper. The helper may throw an exception so this
+   * must return immediately.
+   */
+  ioh_writebytesImpl (env, recv, buffer, offset, count, (IDATA) descriptor);
+}
+
+void JNICALL
+Java_java_io_FileOutputStream_writeByteImpl (JNIEnv * env, jobject recv,
+               jint c, jlong descriptor)
+{
+  /* Call the helper. The helper may throw an exception so this
+   * must return immediately.
+   */
+  ioh_writecharImpl (env, recv, c, (IDATA) descriptor);
+}
+
+void JNICALL
+Java_java_io_FileOutputStream_oneTimeInitialization (JNIEnv * env,
+                 jclass clazz)
+{
+  jfieldID fdFID =
+    (*env)->GetFieldID (env, clazz, "fd", "Ljava/io/FileDescriptor;");
+  if (!fdFID)
+    return;
+  JCL_CACHE_SET (env, FID_java_io_FileOutputStream_fd, fdFID);
+}
+
+void JNICALL
+Java_java_io_FileOutputStream_closeImpl (JNIEnv * env, jobject recv)
+{
+  /* Call the helper */
+  new_ioh_close (env, recv,
+     JCL_CACHE_GET (env, FID_java_io_FileOutputStream_fd));
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/floatbits.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/floatbits.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/floatbits.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/floatbits.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,81 @@
+/* Copyright 2004, 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.
+ */
+
+#include <string.h>
+#include <math.h>
+#include "jcl.h"
+#include "fltconst.h"
+
+#define DOUBLE_SIGN_MASK        HYCONST64(0x8000000000000000)
+#define DOUBLE_EXPONENT_MASK    HYCONST64(0x7FF0000000000000)
+#define DOUBLE_MANTISSA_MASK    HYCONST64(0x000FFFFFFFFFFFFF)
+#define DOUBLE_NAN_BITS         (DOUBLE_EXPONENT_MASK | HYCONST64(0x0008000000000000))
+
+JNIEXPORT jlong JNICALL
+Java_java_lang_Double_doubleToLongBits (JNIEnv * env, jclass cls,
+          jdouble doubleValue)
+{
+  jlong longValue = *(jlong *) & doubleValue;
+  if ((longValue & DOUBLE_EXPONENT_MASK) == DOUBLE_EXPONENT_MASK)
+    {
+      if (longValue & DOUBLE_MANTISSA_MASK)
+        {
+          return DOUBLE_NAN_BITS;
+        }
+    }
+  return longValue;
+}
+
+JNIEXPORT jlong JNICALL
+Java_java_lang_Double_doubleToRawLongBits (JNIEnv * env, jclass cls,
+             jdouble doubleValue)
+{
+  return *(jlong *) & doubleValue;
+}
+
+JNIEXPORT jdouble JNICALL
+Java_java_lang_Double_longBitsToDouble (JNIEnv * env, jclass cls,
+          jlong longValue)
+{
+  return *(jdouble *) & longValue;
+}
+
+JNIEXPORT jint JNICALL
+Java_java_lang_Float_floatToIntBits (JNIEnv * env, jclass cls,
+             jfloat floatValue)
+{
+  jint intValue = *(jint *) & floatValue;
+  if ((intValue & SINGLE_EXPONENT_MASK) == SINGLE_EXPONENT_MASK)
+    {
+      if (intValue & SINGLE_MANTISSA_MASK)
+        {
+          return SINGLE_NAN_BITS;
+        }
+    }
+  return intValue;
+}
+
+JNIEXPORT jint JNICALL
+Java_java_lang_Float_floatToRawIntBits (JNIEnv * env, jclass cls,
+          jfloat floatValue)
+{
+  return *(jint *) & floatValue;
+}
+
+JNIEXPORT jfloat JNICALL
+Java_java_lang_Float_intBitsToFloat (JNIEnv * env, jclass cls, jint intValue)
+{
+  return *(jfloat *) & intValue;
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/helpers.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/helpers.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/helpers.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/win.IA32/luni/helpers.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,401 @@
+/* Copyright 1998, 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.
+ */
+
+/* Undefine the winsockapi because winsock2 defines it.  Removes warnings. */
+#if defined(_WINSOCKAPI_) && !defined(_WINSOCK2API_)
+#undef _WINSOCKAPI_
+#endif
+
+#include <winsock2.h>
+
+#include <windows.h>
+#include <winbase.h>
+#include <stdlib.h>
+#include <LMCONS.H>
+#include <direct.h>
+
+#include "jcl.h"
+#include "jclprots.h"
+#include "jclglob.h"
+
+#include "portsock.h"
+
+int platformReadLink (char *link);
+jbyteArray getPlatformPath (JNIEnv * env, jbyteArray path);
+void setDefaultServerSocketOptions (JNIEnv * env, hysocket_t socketP);
+jint getPlatformDatagramNominalSize (JNIEnv * env, hysocket_t socketP);
+I_32 getPlatformRoots (char *rootStrings);
+jstring getCustomTimeZoneInfo (JNIEnv * env, jintArray tzinfo,
+             jbooleanArray isCustomTimeZone);
+I_32 getPlatformIsHidden (JNIEnv * env, char *path);
+jint getPlatformDatagramMaxSize (JNIEnv * env, hysocket_t socketP);
+char *getCommports (JNIEnv * env);
+I_32 getPlatformIsWriteOnly (JNIEnv * env, char *path);
+I_32 setPlatformFileLength (JNIEnv * env, IDATA descriptor, jlong newLength);
+void platformCanonicalPath (char *pathCopy);
+I_32 getPlatformIsReadOnly (JNIEnv * env, char *path);
+void setPlatformBindOptions (JNIEnv * env, hysocket_t socketP);
+I_32 setPlatformLastModified (JNIEnv * env, char *path, I_64 time);
+I_32 setPlatformReadOnly (JNIEnv * env, char *path);
+
+UDATA platformFindfirst (char *path, char *resultbuf);
+int portCmp (const void **a, const void **b);
+static void unmangle (JNIEnv * env, LPWSTR data);
+I_32 getPlatformAttribute (JNIEnv * env, char *path, DWORD attribute);
+static LPWSTR mangle (JNIEnv * env, char *path);
+
+/* This function converts a char array into a unicode wide string */
+static LPWSTR
+mangle (JNIEnv * env, char *path)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  int convSize;
+  LPWSTR unicodeBuffer;
+
+  convSize = MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, path, -1, NULL, 0);
+  convSize = (convSize + 1) * 2;
+  unicodeBuffer = jclmem_allocate_memory (env, convSize);
+  if (!unicodeBuffer)
+    return NULL;
+  MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, path, -1, unicodeBuffer,
+           convSize);
+  return unicodeBuffer;
+}
+
+/* This function frees the memory allocated in mangle */
+static void
+unmangle (JNIEnv * env, LPWSTR data)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  jclmem_free_memory (env, data);
+}
+
+/**
+ * It is the responsibility of #getPlatformRoots to return a char array
+ * with volume names separated by null with a trailing extra null, so for
+ * Unix it should be '\<null><null>' .
+ */
+I_32
+getPlatformRoots (char *rootStrings)
+{
+
+  I_32 result = GetLogicalDriveStrings (HyMaxPath, rootStrings);
+  return result / 4;    /* Letter, colon, slash, null = 4 bytes */
+
+}
+
+/**
+ * Answer 1 if the path is hidden, 0 otherwise even in fail cases.
+ */
+I_32
+getPlatformIsHidden (JNIEnv * env, char *path)
+{
+  return getPlatformAttribute (env, path, FILE_ATTRIBUTE_HIDDEN);
+}
+
+/**
+ * Answer 1 if the file time was updated, 0 otherwise even in fail cases.
+ */
+I_32
+setPlatformLastModified (JNIEnv * env, char *path, I_64 time)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  FILETIME fileTime;
+  I_32 result, dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
+  IDATA hFile;
+  I_64 tempLongLong;
+
+  char *unicodePath;
+  unicodePath = path;
+
+  /**
+   * Open the path ensuring GENERIC_WRITE and FILE_FLAG_BACKUP_SEMANTICS if it's a directory.
+   * The directory modification is only supported on some platforms (NT, Windows2000).
+   */
+  result = GetFileAttributes ((LPCTSTR) unicodePath);
+  if (result == 0xFFFFFFFF)
+    {
+      return 0;
+    }
+  if (result & FILE_ATTRIBUTE_DIRECTORY)
+    dwFlagsAndAttributes = FILE_FLAG_BACKUP_SEMANTICS;
+
+  hFile = (IDATA) CreateFile (unicodePath,
+            GENERIC_WRITE,
+            FILE_SHARE_READ | FILE_SHARE_WRITE,
+            NULL,
+            OPEN_EXISTING, dwFlagsAndAttributes, NULL);
+  if ((IDATA) hFile == (IDATA) INVALID_HANDLE_VALUE)
+    {
+      return 0;
+    }
+
+  tempLongLong = (time * (I_64) 10000) + 116444736000000000;
+
+  fileTime.dwHighDateTime = (I_32) (tempLongLong >> 32);
+  fileTime.dwLowDateTime = (I_32) tempLongLong;
+  result =
+    SetFileTime ((HANDLE) hFile, (LPFILETIME) NULL, (LPFILETIME) NULL,
+     &fileTime);
+  hyfile_close (hFile);
+
+  return result;
+}
+
+/**
+ * Answer 1 if the path is now readOnly, 0 otherwise even in fail cases.
+ */
+I_32
+setPlatformReadOnly (JNIEnv * env, char *path)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  I_32 attrs, result;
+
+  char *unicodePath;
+  unicodePath = path;
+
+  attrs = GetFileAttributes (unicodePath);
+  if (attrs == 0xFFFFFFFF)
+    {
+      return 0;
+    }
+  attrs = attrs | FILE_ATTRIBUTE_READONLY;
+  result = SetFileAttributes (unicodePath, attrs);
+
+  return result;
+}
+
+/**
+ * Answer 1 if the file length was set, 0 otherwise even in fail cases.
+ */
+I_32
+setPlatformFileLength (JNIEnv * env, IDATA descriptor, jlong newLength)
+{
+  I_32 result;
+  I_32 lowValue, highValue;
+  lowValue = (I_32) newLength;
+  highValue = (I_32) (newLength >> 32);
+  result =
+    SetFilePointer ((HANDLE) descriptor, lowValue, &highValue, FILE_BEGIN);
+  if (result == INVALID_FILE_SIZE && (GetLastError ()) != NO_ERROR)
+    return 0;
+  return SetEndOfFile ((HANDLE) descriptor);
+}
+
+jbyteArray
+getPlatformPath (JNIEnv * env, jbyteArray path)
+{
+  char buffer[256];
+  jbyteArray answer = NULL;
+  jsize length = (*env)->GetArrayLength (env, path);
+  jbyte *lpath = (*env)->GetByteArrayElements (env, path, 0);
+
+  if (lpath != NULL)
+    {
+      if (length >= 2 && lpath[1] == ':')
+        {
+          char next = lpath[2];
+          int drive = tolower (lpath[0]) - 'a' + 1;
+          if ((next == 0 || (lpath[2] != '/' && next != '\\')) && drive >= 1
+            && drive <= 26)
+            {
+              int buflen = 2, needSlash;
+              if (_getdcwd (drive, buffer, sizeof (buffer)) != NULL)
+                {
+                  buflen = strlen (buffer);
+                  if (buffer[buflen - 1] == '\\')
+                    buflen--;
+                }
+              needSlash = length > 2 || buflen < 3;
+              answer =
+                (*env)->NewByteArray (env,
+                buflen + length - (needSlash ? 1 : 2));
+              if (answer != NULL)
+                {
+                  /* Copy drive and colon */
+                  (*env)->SetByteArrayRegion (env, answer, 0, 2, lpath);
+                  if (buflen > 2)
+                    (*env)->SetByteArrayRegion (env, answer, 2, buflen - 2,
+                    buffer + 2);
+                  if (needSlash)
+                    (*env)->SetByteArrayRegion (env, answer, buflen, 1, "\\");
+                  if (length > 2)
+                    (*env)->SetByteArrayRegion (env, answer, buflen + 1,
+                    length - 2, lpath + 2);
+                }
+            }
+        }
+      (*env)->ReleaseByteArrayElements (env, path, lpath, JNI_ABORT);
+    }
+  return answer;
+}
+
+UDATA
+platformFindfirst (char *path, char *resultbuf)
+{
+  /*
+   * Takes a path and a preallocated resultbuf.  Answers a handle to be used
+   * in subsequent calls to hyfile_findnext and hyfile_findclose.  Handle may
+   * be -1 if hyfile_findfirst fails.
+   * The parameter @path will only be a valid directory name, any info that must
+   * be added to it and passed to the os (c:\\) should be (c:\\*) for Win32
+   */
+  WIN32_FIND_DATA lpFindFileData;
+  HANDLE handle;
+
+  handle = FindFirstFile ((LPCTSTR) path, &lpFindFileData);
+
+  if (handle == INVALID_HANDLE_VALUE)
+    return (UDATA) - 1;
+
+  lstrcpy (resultbuf, lpFindFileData.cFileName);
+  FindClose (handle);
+  return 1;
+}
+
+void
+platformCanonicalPath (char *pathCopy)
+{
+  UDATA result;
+  U_32 pos, start, length, rpos, rlen;
+  char newpath[HyMaxPath], filename[HyMaxPath];
+
+  pos = 0;
+  length = strlen (pathCopy);
+  if (length >= 2 && pathCopy[1] == ':')
+    {
+      pathCopy[0] = toupper (pathCopy[0]);
+      pos = 2;
+    }
+  else if (pathCopy[0] == '\\')
+    {
+      pos++;
+      if (length >= 2 && pathCopy[1] == '\\')
+        {
+          pos++;
+          /* Found network path, skip server and volume */
+          while (pos < length && pathCopy[pos] != '\\')
+            pos++;
+          if (pathCopy[pos] == '\\')
+            pos++;
+          while (pos < length && pathCopy[pos] != '\\')
+            pos++;
+          if (pos == length)
+            return;
+        }
+    }
+  if (pathCopy[pos] == '\\')
+    pos++;
+  start = pos;
+  memcpy (newpath, pathCopy, pos);
+  rpos = pos;
+  while (pos <= length)
+    {
+      if (pathCopy[pos] == '\\' || pos == length)
+        {
+          if (pos == length && pathCopy[pos - 1] == '\\')
+            break;
+          pathCopy[pos] = 0;
+          result = platformFindfirst (pathCopy, filename);
+          if (pos != length)
+            pathCopy[pos] = '\\';
+          if (result == (UDATA) - 1)
+            {
+              break;
+            }
+          else
+            {
+              rlen = strlen (filename);
+              if (rpos + rlen + 2 >= HyMaxPath)
+                break;
+              strcpy (&newpath[rpos], filename);
+              rpos += rlen;
+              if (pos != length)
+                newpath[rpos++] = '\\';
+              else
+                newpath[rpos] = 0;
+              start = pos + 1;
+            }
+        }
+      else if (pathCopy[pos] == '*' || pathCopy[pos] == '?')
+        break;
+      pos++;
+    }
+  if (start <= length)
+    strncpy (&newpath[rpos], &pathCopy[start], HyMaxPath - 1 - rpos);
+  strcpy (pathCopy, newpath);
+
+}
+
+void
+setPlatformBindOptions (JNIEnv * env, hysocket_t socketP)
+{
+}
+
+/**
+ * Answer 1 if the path is hidded, 0 otherwise even in fail cases.
+ */
+I_32
+getPlatformAttribute (JNIEnv * env, char *path, DWORD attribute)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  I_32 attrs;
+
+  char *unicodePath;
+  unicodePath = path;
+
+  attrs = GetFileAttributes (unicodePath);
+
+  if (attrs == 0xFFFFFFFF)
+    return 0;
+  return (attrs & attribute) == attribute;
+}
+
+/**
+ * Answer 1 if the path is read-only, 0 otherwise even in fail cases.
+ */
+I_32
+getPlatformIsReadOnly (JNIEnv * env, char *path)
+{
+  return getPlatformAttribute (env, path, FILE_ATTRIBUTE_READONLY);
+}
+
+/**
+ * Answer 1 if the path is write-only, 0 otherwise even in fail cases.
+ */
+I_32
+getPlatformIsWriteOnly (JNIEnv * env, char *path)
+{
+  return 0;
+}
+
+/* Resolve link if it is a symbolic link and put the result in link. */
+int
+platformReadLink (char *link)
+{
+  return FALSE;
+}
+
+jstring
+getCustomTimeZoneInfo (JNIEnv * env, jintArray tzinfo,
+           jbooleanArray isCustomTimeZone)
+{
+  return NULL;
+}
+
+void
+setDefaultServerSocketOptions (JNIEnv * env, hysocket_t socketP)
+{
+}