harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r382065 [4/10] - in /incubator/harmony/enhanced/classlib/trunk: modules/security/make/ modules/security/make/native/linux/ modules/security/make/native/windows/ native-src/ native-src/linux.IA32/ native-src/linux.IA32/archive/ native-src/li...
Date Wed, 01 Mar 2006 15:43:11 GMT
Added: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/oos.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/oos.c?rev=382065&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/oos.c (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/oos.c Wed Mar  1 07:42:53 2006
@@ -0,0 +1,213 @@
+/* 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 "jni.h"
+
+jlong JNICALL
+Java_java_io_ObjectOutputStream_getFieldLong (JNIEnv * env, jclass clazz,
+                                              jobject targetObject,
+                                              jobject declaringClass,
+                                              jobject fieldName)
+{
+  const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
+  jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "J");
+  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
+
+  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */
+  if (fid == 0)
+    {
+      /* Field not found. I believe we must throw an exception here */
+      return (jlong) 0L;
+    }
+  else
+    {
+      return (*env)->GetLongField (env, targetObject, fid);
+    }
+}
+jshort JNICALL
+Java_java_io_ObjectOutputStream_getFieldShort (JNIEnv * env, jclass clazz,
+                                               jobject targetObject,
+                                               jobject declaringClass,
+                                               jobject fieldName)
+{
+  const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
+  jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "S");
+  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
+
+  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */
+  if (fid == 0)
+    {
+      /* Field not found. I believe we must throw an exception here */
+      return (jshort) 0;
+    }
+  else
+    {
+      return (*env)->GetShortField (env, targetObject, fid);
+    }
+}
+jdouble JNICALL
+Java_java_io_ObjectOutputStream_getFieldDouble (JNIEnv * env, jclass clazz,
+                                                jobject targetObject,
+                                                jobject declaringClass,
+                                                jobject fieldName)
+{
+  const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
+  jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "D");
+  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
+
+  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */
+  if (fid == 0)
+    {
+      /* Field not found. I believe we must throw an exception here */
+      return (jdouble) 0.0;
+    }
+  else
+    {
+      return (*env)->GetDoubleField (env, targetObject, fid);
+    }
+}
+jboolean JNICALL
+Java_java_io_ObjectOutputStream_getFieldBool (JNIEnv * env, jclass clazz,
+                                              jobject targetObject,
+                                              jobject declaringClass,
+                                              jobject fieldName)
+{
+  const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
+  jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "Z");
+  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
+
+  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */
+  if (fid == 0)
+    {
+      /* Field not found. I believe we must throw an exception here */
+      return (jboolean) 0;
+    }
+  else
+    {
+      return (*env)->GetBooleanField (env, targetObject, fid);
+    }
+}
+jbyte JNICALL
+Java_java_io_ObjectOutputStream_getFieldByte (JNIEnv * env, jclass clazz,
+                                              jobject targetObject,
+                                              jobject declaringClass,
+                                              jobject fieldName)
+{
+  const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
+  jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "B");
+  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
+
+  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */
+  if (fid == 0)
+    {
+      /* Field not found. I believe we must throw an exception here */
+      return (jbyte) 0;
+    }
+  else
+    {
+      return (*env)->GetByteField (env, targetObject, fid);
+    }
+}
+jfloat JNICALL
+Java_java_io_ObjectOutputStream_getFieldFloat (JNIEnv * env, jclass clazz,
+                                               jobject targetObject,
+                                               jobject declaringClass,
+                                               jobject fieldName)
+{
+  const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
+  jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "F");
+  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
+
+  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */
+  if (fid == 0)
+    {
+      /* Field not found. I believe we must throw an exception here */
+      return (jfloat) 0.0f;
+    }
+  else
+    {
+      return (*env)->GetFloatField (env, targetObject, fid);
+    }
+
+}
+
+jchar JNICALL
+Java_java_io_ObjectOutputStream_getFieldChar (JNIEnv * env, jclass clazz,
+                                              jobject targetObject,
+                                              jobject declaringClass,
+                                              jobject fieldName)
+{
+  const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
+  jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "C");
+  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
+
+  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */
+  if (fid == 0)
+    {
+      /* Field not found. I believe we must throw an exception here */
+      return (jchar) 0;
+    }
+  else
+    {
+      return (*env)->GetCharField (env, targetObject, fid);
+    }
+}
+jobject JNICALL
+Java_java_io_ObjectOutputStream_getFieldObj (JNIEnv * env, jclass clazz,
+                                             jobject targetObject,
+                                             jobject declaringClass,
+                                             jobject fieldName,
+                                             jobject fieldTypeName)
+{
+  const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
+  const char *fieldTypeNameInC =
+    (*env)->GetStringUTFChars (env, fieldTypeName, NULL);
+  jfieldID fid =
+    (*env)->GetFieldID (env, declaringClass, fieldNameInC, fieldTypeNameInC);
+  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
+  (*env)->ReleaseStringUTFChars (env, fieldTypeName, fieldTypeNameInC);
+
+  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */
+  if (fid == 0)
+    {
+      /* Field not found. I believe we must throw an exception here */
+      return (jobject) 0;
+    }
+  else
+    {
+      return (*env)->GetObjectField (env, targetObject, fid);
+    }
+}
+jint JNICALL
+Java_java_io_ObjectOutputStream_getFieldInt (JNIEnv * env, jclass clazz,
+                                             jobject targetObject,
+                                             jobject declaringClass,
+                                             jobject fieldName)
+{
+  const char *fieldNameInC = (*env)->GetStringUTFChars (env, fieldName, NULL);
+  jfieldID fid = (*env)->GetFieldID (env, declaringClass, fieldNameInC, "I");
+  (*env)->ReleaseStringUTFChars (env, fieldName, fieldNameInC);
+
+  /* Two options now. Maybe getFieldID caused an exception, or maybe it returned the real value */
+  if (fid == 0)
+    {
+      /* Field not found. I believe we must throw an exception here */
+      return (jint) 0;
+    }
+  else
+    {
+      return (*env)->GetIntField (env, targetObject, fid);
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/osc.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/osc.c?rev=382065&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/osc.c (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/osc.c Wed Mar  1 07:42:53 2006
@@ -0,0 +1,108 @@
+/* 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 "jcl.h"
+#include "jclglob.h"
+
+jobject JNICALL
+Java_java_io_ObjectStreamClass_getFieldSignature (JNIEnv * env, jclass clazz,
+                                                  jobject reflectField)
+{
+  jclass fieldClass = (*env)->GetObjectClass (env, reflectField);
+  return (*env)->CallNonvirtualObjectMethod (env, reflectField, fieldClass,
+                                             JCL_CACHE_GET (env,
+                                                            MID_java_lang_reflect_Field_getSignature));
+}
+
+jobject JNICALL
+Java_java_io_ObjectStreamClass_getMethodSignature (JNIEnv * env, jclass clazz,
+                                                   jobject reflectMethod)
+{
+  jclass methodClass = (*env)->GetObjectClass (env, reflectMethod);
+  return (*env)->CallNonvirtualObjectMethod (env, reflectMethod, methodClass,
+                                             JCL_CACHE_GET (env,
+                                                            MID_java_lang_reflect_Method_getSignature));
+}
+
+jobject JNICALL
+Java_java_io_ObjectStreamClass_getConstructorSignature (JNIEnv * env,
+                                                        jclass clazz,
+                                                        jobject
+                                                        reflectConstructor)
+{
+  jclass constructorClass = (*env)->GetObjectClass (env, reflectConstructor);
+  return (*env)->CallNonvirtualObjectMethod (env, reflectConstructor,
+                                             constructorClass,
+                                             JCL_CACHE_GET (env,
+                                                            MID_java_lang_reflect_Constructor_getSignature));
+}
+
+jboolean JNICALL
+Java_java_io_ObjectStreamClass_hasClinit (JNIEnv * env, jclass clazz,
+                                          jobject targetClass)
+{
+  jmethodID mid =
+    (*env)->GetStaticMethodID (env, targetClass, "<clinit>", "()V");
+  (*env)->ExceptionClear (env);
+
+  /* Can I just return mid and rely on typecast to convert to jboolean ? Safe implementation for now */
+  if (mid == 0)
+    {
+      /* No <clinit>... */
+      return (jboolean) 0;
+    }
+  else
+    {
+      return (jboolean) 1;
+    }
+}
+
+void JNICALL
+Java_java_io_ObjectStreamClass_oneTimeInitialization (JNIEnv * env,
+                                                      jclass clazz)
+{
+  jclass lookupClass;
+  jmethodID mid;
+
+  lookupClass = (*env)->FindClass (env, "java/lang/reflect/Field");
+  if (!lookupClass)
+    return;
+  mid =
+    (*env)->GetMethodID (env, lookupClass, "getSignature",
+                         "()Ljava/lang/String;");
+  if (!mid)
+    return;
+  JCL_CACHE_SET (env, MID_java_lang_reflect_Field_getSignature, mid);
+
+  lookupClass = (*env)->FindClass (env, "java/lang/reflect/Method");
+  if (!lookupClass)
+    return;
+  mid =
+    (*env)->GetMethodID (env, lookupClass, "getSignature",
+                         "()Ljava/lang/String;");
+  if (!mid)
+    return;
+  JCL_CACHE_SET (env, MID_java_lang_reflect_Method_getSignature, mid);
+
+  lookupClass = (*env)->FindClass (env, "java/lang/reflect/Constructor");
+  if (!lookupClass)
+    return;
+  mid =
+    (*env)->GetMethodID (env, lookupClass, "getSignature",
+                         "()Ljava/lang/String;");
+  if (!mid)
+    return;
+  JCL_CACHE_SET (env, MID_java_lang_reflect_Constructor_getSignature, mid);
+}

Added: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pmsimpl.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pmsimpl.c?rev=382065&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pmsimpl.c (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pmsimpl.c Wed Mar  1 07:42:53 2006
@@ -0,0 +1,65 @@
+/* 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 <stdlib.h>
+#include "jclglob.h"
+#include "nethelp.h"
+#include "helpers.h"
+#include "jclprots.h"
+
+#if defined(LINUX)
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>         /* for struct in_addr */
+#include <sys/ioctl.h>
+#include <net/if.h>             /* for struct ifconf */
+#endif
+
+#include "portsock.h"
+
+/**
+ * Create a new socket, for multicast datagrams.  The system socket is created and 'linked' to the
+ * the java PlainMulticastSocketImpl by setting the file descriptor value (which is an integer 
+ * reference to socket maintained by the system).  For Multicast sockets, the REUSEADDR is on by
+ * default for all platforms tested so far including windows.  In addition on platforms which support REUSEPORT
+ * this should also be on by default as well.
+ *
+ * @param	env				pointer to the JNI library
+ * @param	thisClz			pointer to the class of the receiver (of the java message)
+ * @param	thisObjFD	pointer to the file descriptor of the java PlainDatagramSocketImpl
+ * @param preferIPv4Stack if application preference is to use only IPv4 sockets (default is false)
+ */
+
+void JNICALL
+Java_java_net_PlainMulticastSocketImpl_createMulticastSocketImpl (JNIEnv *
+                                                                  env,
+                                                                  jclass
+                                                                  thisClz,
+                                                                  jobject
+                                                                  thisObjFD,
+                                                                  jboolean
+                                                                  preferIPv4Stack)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  BOOLEAN value = TRUE;
+  hysocket_t socketP;
+  createSocket (env, thisObjFD, HYSOCK_DGRAM, preferIPv4Stack);
+  socketP =
+    (hysocket_t) getJavaIoFileDescriptorContentsAsPointer (env, thisObjFD);
+
+  hysock_setopt_bool (socketP, HY_SOL_SOCKET, HY_SO_REUSEPORT, &value);
+  hysock_setopt_bool (socketP, HY_SOL_SOCKET, HY_SO_REUSEADDR, &value);
+}

Added: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pmsimpl.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pmsimpl.h?rev=382065&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pmsimpl.h (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pmsimpl.h Wed Mar  1 07:42:53 2006
@@ -0,0 +1,27 @@
+/* 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.
+ */
+
+#if !defined(pmsimpl_h)
+#define pmsimpl_h
+void JNICALL
+Java_java_net_PlainMulticastSocketImpl_createMulticastSocketImpl (JNIEnv *
+                                                                  env,
+                                                                  jclass
+                                                                  thisClz,
+                                                                  jobject
+                                                                  thisObjFD,
+                                                                  jboolean
+                                                                  preferIPv4Stack);
+#endif /* pmsimpl_h */

Added: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/proxy.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/proxy.c?rev=382065&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/proxy.c (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/proxy.c Wed Mar  1 07:42:53 2006
@@ -0,0 +1,50 @@
+/* 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"
+
+jclass JNICALL
+Java_java_lang_reflect_Proxy_defineClassImpl (JNIEnv * env, jclass recvClass,
+                                              jobject classLoader,
+                                              jstring className,
+                                              jbyteArray classBytes)
+{
+  const char *name;
+  jbyte *bytes;
+  jclass returnClass;
+  jint length;
+
+  name = (*env)->GetStringUTFChars (env, className, NULL);
+  if (!name)
+    {
+      throwNewOutOfMemoryError (env, "");
+      return 0;
+    };
+  bytes = (*env)->GetByteArrayElements (env, classBytes, NULL);
+  if (!bytes)
+    {
+      (*env)->ReleaseStringUTFChars (env, className, name);
+      throwNewOutOfMemoryError (env, "");
+      return 0;
+    }
+  length = (*env)->GetArrayLength (env, classBytes);
+
+  returnClass = (*env)->DefineClass (env, name, classLoader, bytes, length);
+
+  (*env)->ReleaseByteArrayElements (env, classBytes, bytes, JNI_COMMIT);
+  (*env)->ReleaseStringUTFChars (env, className, name);
+  return returnClass;
+}

Added: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/psimpl2.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/psimpl2.c?rev=382065&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/psimpl2.c (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/psimpl2.c Wed Mar  1 07:42:53 2006
@@ -0,0 +1,477 @@
+/* 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 <stdlib.h>
+#include "nethelp.h"
+#include "jclglob.h"
+#include "jclprots.h"
+#include "portsock.h"
+
+/**
+ * Create a socket, of type stream.
+ *
+ * @param	env						pointer to the JNI library
+ * @param	thisClz					pointer to the class of the receiver (of the java message)
+ * @param	thisObjFD			pointer to the socket file descriptor
+ * @param preferIPv4Stack if application preference is to use only IPv4 sockets (default is false)
+ * @exception	SocketException	if an error occurs creating the socket
+ */
+
+void JNICALL
+Java_java_net_PlainSocketImpl2_createStreamSocketImpl2 (JNIEnv * env,
+                                                        jclass thisClz,
+                                                        jobject thisObjFD,
+                                                        jboolean
+                                                        preferIPv4Stack)
+{
+  createSocket (env, thisObjFD, HYSOCK_STREAM, preferIPv4Stack);
+}
+
+/**
+ * Connect the socket to the nominated remote host address/port.  The socket may then be used to send
+ * and receive data from the remote host.
+ *
+ * @param	env						pointer to the JNI library
+ * @param	thisClz					pointer to the class of the receiver (of the java message)
+ * @param	fileDescriptor		pointer to the socket file descriptor
+ * @param	remotePort			the port on the remote host to connect to
+ * @param   inetAddress		    the address to connect to
+ *
+ * @exception	SocketException	if an error occurs connected to the remote host
+ */
+
+void JNICALL
+Java_java_net_PlainSocketImpl2_connectStreamSocketImpl2 (JNIEnv * env,
+                                                         jclass thisClz,
+                                                         jobject
+                                                         fileDescriptor,
+                                                         jint remotePort,
+                                                         jint trafficClass,
+                                                         jobject inetAddress)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  jbyte nAddrBytes[HYSOCK_INADDR6_LEN];
+  int length;
+  U_16 nPort;
+  I_32 result;
+  hysocket_t socketP;
+  hysockaddr_struct sockaddrP;
+  U_32 scope_id = 0;
+
+  socketP = getJavaIoFileDescriptorContentsAsPointer (env, fileDescriptor);
+  if (!hysock_socketIsValid (socketP))
+    {
+      throwJavaNetSocketException (env, HYPORT_ERROR_SOCKET_BADSOCKET);
+      return;
+    }
+  else
+    {
+      netGetJavaNetInetAddressValue (env, inetAddress, nAddrBytes, &length);
+
+      nPort = hysock_htons ((U_16) remotePort);
+      if (length == HYSOCK_INADDR_LEN)
+        {
+          hysock_sockaddr_init6 (&sockaddrP, (U_8 *) nAddrBytes, length,
+                                 HYADDR_FAMILY_AFINET4, nPort, 0, scope_id,
+                                 socketP);
+        }
+      else
+        {
+          netGetJavaNetInetAddressScopeId (env, inetAddress, &scope_id);
+          hysock_sockaddr_init6 (&sockaddrP, (U_8 *) nAddrBytes, length,
+                                 HYADDR_FAMILY_AFINET6, nPort,
+                                 (trafficClass & 0xFF) << 20, scope_id,
+                                 socketP);
+        }
+
+      result = hysock_connect (socketP, &sockaddrP);
+      if (0 != result)
+        {
+          throwJavaNetConnectException (env, result);
+          return;
+        }
+    }
+}
+
+/**
+ * Connect the socket to the nominated remote host address/port.  The socket may then be used to send
+ * and receive data from the remote host.
+ *
+ * @param	env						pointer to the JNI library
+ * @param	thisClz					pointer to the class of the receiver (of the java message)
+ * @param	fileDescriptor		pointer to the socket file descriptor
+ * @param	remotePort			the port on the remote host to connect to
+ * @param   timeout				timeout in milliseconds 
+ * @param   trafficClass			the traffic class to be used for the connection
+ * @param   inetAddress			the address to be used for the connection
+ *
+ * @exception	SocketException	if an error occurs connected to the remote host
+ */
+
+void JNICALL
+Java_java_net_PlainSocketImpl2_connectStreamWithTimeoutSocketImpl2 (JNIEnv *
+                                                                    env,
+                                                                    jclass
+                                                                    thisClz,
+                                                                    jobject
+                                                                    fileDescriptor,
+                                                                    jint
+                                                                    remotePort,
+                                                                    jint
+                                                                    timeout,
+                                                                    jint
+                                                                    trafficClass,
+                                                                    jobject
+                                                                    inetAddress)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  jbyte nAddrBytes[HYSOCK_INADDR6_LEN];
+  int length;
+  U_16 nPort;
+  I_32 result;
+  hysocket_t socketP;
+  hysockaddr_struct sockaddrP;
+  U_8 *context = NULL;
+  I_32 remainingTimeout = timeout;
+  I_32 passedTimeout = 0;
+  UDATA finishTime = 0;
+  BOOLEAN hasTimeout = timeout > 0;
+  U_32 scope_id = 0;
+
+  /* if a timeout was specified calculate the finish time value */
+  if (hasTimeout)
+    {
+      finishTime = hytime_msec_clock () + (UDATA) timeout;
+    }
+
+  socketP = getJavaIoFileDescriptorContentsAsPointer (env, fileDescriptor);
+  if (!hysock_socketIsValid (socketP))
+    {
+      throwJavaNetSocketException (env, HYPORT_ERROR_SOCKET_BADSOCKET);
+      return;
+    }
+  else
+    {
+      netGetJavaNetInetAddressValue (env, inetAddress, nAddrBytes, &length);
+      nPort = hysock_htons ((U_16) remotePort);
+      if (length == HYSOCK_INADDR_LEN)
+        {
+          hysock_sockaddr_init6 (&sockaddrP, (U_8 *) nAddrBytes, length,
+                                 HYADDR_FAMILY_AFINET4, nPort, 0, scope_id,
+                                 socketP);
+        }
+      else
+        {
+          netGetJavaNetInetAddressScopeId (env, inetAddress, &scope_id);
+          hysock_sockaddr_init6 (&sockaddrP, (U_8 *) nAddrBytes, length,
+                                 HYADDR_FAMILY_AFINET6, nPort,
+                                 (trafficClass & 0xFF) << 20, scope_id,
+                                 socketP);
+        }
+
+      result =
+        hysock_connect_with_timeout (socketP, &sockaddrP, 0,
+                                     HY_PORT_SOCKET_STEP_START, &context);
+      if (0 == result)
+        {
+          /* ok we connected right away so we are done */
+          hysock_connect_with_timeout (socketP, &sockaddrP, 0,
+                                       HY_PORT_SOCKET_STEP_DONE, &context);
+          return;
+        }
+      else if (result != HYPORT_ERROR_SOCKET_NOTCONNECTED)
+        {
+          /* we got an error other than NOTCONNECTED so we cannot continue */
+          if ((HYPORT_ERROR_SOCKET_CONNRESET == result) ||
+              (HYPORT_ERROR_SOCKET_CONNECTION_REFUSED == result) ||
+              (HYPORT_ERROR_SOCKET_ADDRNOTAVAIL == result) ||
+              (HYPORT_ERROR_SOCKET_ADDRINUSE == result) ||
+              (HYPORT_ERROR_SOCKET_ENETUNREACH == result) ||
+              (HYPORT_ERROR_SOCKET_EACCES == result))
+            {
+              hysock_connect_with_timeout (socketP, &sockaddrP,
+                                           remainingTimeout,
+                                           HY_PORT_SOCKET_STEP_DONE,
+                                           &context);
+              throwJavaNetConnectException (env, result);
+              return;
+            }
+          else
+            {
+              hysock_connect_with_timeout (socketP, &sockaddrP, 0,
+                                           HY_PORT_SOCKET_STEP_DONE,
+                                           &context);
+              throwJavaNetSocketException (env, result);
+              return;
+            }
+        }
+
+      while (HYPORT_ERROR_SOCKET_NOTCONNECTED == result)
+        {
+
+          passedTimeout = remainingTimeout;
+
+          /**
+			* ok now try and connect.  Depending on the platform this may sleep for 
+            * up to passedTimeout milliseconds 
+            */
+          result =
+            hysock_connect_with_timeout (socketP, &sockaddrP, passedTimeout,
+                                         HY_PORT_SOCKET_STEP_CHECK, &context);
+
+          /**
+			* now check if the socket is still connected.  
+            * Do it here as some platforms seem to think they are connected if the socket 
+            * is closed on them 
+            */
+          socketP =
+            getJavaIoFileDescriptorContentsAsPointer (env, fileDescriptor);
+          if (!hysock_socketIsValid (socketP))
+            {
+              hysock_connect_with_timeout (socketP, &sockaddrP, 0,
+                                           HY_PORT_SOCKET_STEP_DONE,
+                                           &context);
+              throwJavaNetSocketException (env,
+                                           HYPORT_ERROR_SOCKET_BADSOCKET);
+              return;
+            }
+
+          /* check if we are now connected, if so we can finish the process and return */
+          if (0 == result)
+            {
+              hysock_connect_with_timeout (socketP, &sockaddrP, 0,
+                                           HY_PORT_SOCKET_STEP_DONE,
+                                           &context);
+              return;
+            }
+
+         /**
+           * if the error is HYPORT_ERROR_SOCKET_NOTCONNECTED then we have not yet connected 
+           * and we may not be done yet 
+           */
+          if (HYPORT_ERROR_SOCKET_NOTCONNECTED == result)
+            {
+              /* check if the timeout has expired */
+              if (hasTimeout)
+                {
+                  remainingTimeout = finishTime - hytime_msec_clock ();
+                  if (remainingTimeout <= 0)
+                    {
+                      hysock_connect_with_timeout (socketP, &sockaddrP, 0,
+                                                   HY_PORT_SOCKET_STEP_DONE,
+                                                   &context);
+                      throwJavaNetSocketTimeoutException (env, result);
+                      return;
+                    }
+                }
+              else
+                {
+                  remainingTimeout = 100;
+                }
+
+            }
+          else
+            {
+              if ((HYPORT_ERROR_SOCKET_CONNRESET == result) ||
+                  (HYPORT_ERROR_SOCKET_CONNECTION_REFUSED == result) ||
+                  (HYPORT_ERROR_SOCKET_ADDRNOTAVAIL == result) ||
+                  (HYPORT_ERROR_SOCKET_ADDRINUSE == result) ||
+                  (HYPORT_ERROR_SOCKET_ENETUNREACH == result) ||
+                  (HYPORT_ERROR_SOCKET_EACCES == result))
+                {
+                  hysock_connect_with_timeout (socketP, &sockaddrP,
+                                               remainingTimeout,
+                                               HY_PORT_SOCKET_STEP_DONE,
+                                               &context);
+                  throwJavaNetConnectException (env, result);
+                  return;
+                }
+              else
+                {
+                  hysock_connect_with_timeout (socketP, &sockaddrP,
+                                               remainingTimeout,
+                                               HY_PORT_SOCKET_STEP_DONE,
+                                               &context);
+                  throwJavaNetSocketException (env, result);
+                  return;
+                }
+            }
+        }
+    }
+}
+
+/**
+ * Send data on this socket to the nominated host address/port.
+ *
+ * @param	env						pointer to the JNI library
+ * @param	thisClz					pointer to the class of the receiver (of the java message)
+ * @param	fileDescriptor		pointer to the file descriptor of the java PlainDatagramSocketImpl
+ * @param	data						pointer to the java read buffer
+ * @param	msgLength			the length of the read buffer
+ * @param	targetPort				target port, in host order
+ * @param  inetAddress			the address to send the datagram to
+ *
+ * @return	the number of bytes sent
+ * @exception	SocketException	if an error occurs during the call
+ */
+
+jint JNICALL
+Java_java_net_PlainSocketImpl2_sendDatagramImpl2 (JNIEnv * env,
+                                                  jclass thisClz,
+                                                  jobject fileDescriptor,
+                                                  jbyteArray data,
+                                                  jint offset, jint msgLength,
+                                                  jint targetPort,
+                                                  jobject inetAddress)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  jbyte *message;
+  jbyte nhostAddrBytes[HYSOCK_INADDR6_LEN];
+  U_16 nPort;
+  I_32 result = 0, sent = 0;
+  hysocket_t socketP;
+  hysockaddr_struct sockaddrP;
+  int length;
+  U_32 scope_id = 0;
+
+  if (inetAddress != NULL)
+    {
+      netGetJavaNetInetAddressValue (env, inetAddress, nhostAddrBytes,
+                                     &length);
+
+      socketP =
+        (hysocket_t) getJavaIoFileDescriptorContentsAsPointer (env,
+                                                               fileDescriptor);
+      nPort = hysock_htons ((U_16) targetPort);
+      if (length == HYSOCK_INADDR_LEN)
+        {
+          hysock_sockaddr_init6 (&sockaddrP, (U_8 *) nhostAddrBytes, length,
+                                 HYPROTOCOL_FAMILY_INET4, nPort, 0, scope_id,
+                                 socketP);
+        }
+      else
+        {
+          netGetJavaNetInetAddressScopeId (env, inetAddress, &scope_id);
+          hysock_sockaddr_init6 (&sockaddrP, (U_8 *) nhostAddrBytes, length,
+                                 HYPROTOCOL_FAMILY_INET6, nPort, 0, scope_id,
+                                 socketP);
+        }
+    }
+
+  message = jclmem_allocate_memory (env, msgLength);
+  if (message == NULL)
+    {
+      throwNewOutOfMemoryError (env, "");
+      return 0;
+    }
+  (*env)->GetByteArrayRegion (env, data, offset, msgLength, message);
+  while (sent < msgLength)
+    {
+      socketP =
+        (hysocket_t) getJavaIoFileDescriptorContentsAsPointer (env,
+                                                               fileDescriptor);
+      if (!hysock_socketIsValid (socketP))
+        {
+          jclmem_free_memory (env, message);
+          throwJavaNetSocketException (env,
+                                       sent ==
+                                       0 ? HYPORT_ERROR_SOCKET_BADSOCKET :
+                                       HYPORT_ERROR_SOCKET_INTERRUPTED);
+          return (jint) 0;
+        }
+      result =
+        hysock_writeto (socketP, (U_8 *) message + sent,
+                        (I_32) msgLength - sent, HYSOCK_NOFLAGS, &sockaddrP);
+      if (result < 0)
+        break;
+      sent += result;
+    }
+  jclmem_free_memory (env, message);
+   /**
+	 * We should always throw an exception if all the data cannot be sent because Java methods
+	 * assume all the data will be sent or an error occurs.
+	 */
+  if (result < 0)
+    {
+      throwJavaNetSocketException (env, result);
+      return (jint) 0;
+    }
+  else
+    {
+      return (jint) sent;
+    }
+}
+
+/**
+ * Bind the socket to the specified local address/port.  This call is made after socket creation
+ * and prior to read/write operations.
+ *
+ * @param	env					pointer to the JNI library
+ * @param	thisClz				pointer to the class of the receiver (of the java message)
+ * @param	fileDescriptor 	pointer to the file descriptor of the socket to bind
+ * @param	localPort			the port, in host order, to bind the socket on
+ * @param   inetAddress    address to be used for the bind
+ *
+ * @exception SocketException	if an error occurs during the call
+ */
+
+void JNICALL
+Java_java_net_PlainSocketImpl2_socketBindImpl2 (JNIEnv * env, jclass thisClz,
+                                                jobject fileDescriptor,
+                                                jint localPort,
+                                                jobject inetAddress)
+{
+  PORT_ACCESS_FROM_ENV (env);
+  jbyte nlocalAddrBytes[HYSOCK_INADDR6_LEN];
+  int length;
+  U_16 nPort;
+  I_32 result;
+  hysocket_t socketP;
+  hysockaddr_struct sockaddrP;
+  U_32 scope_id = 0;
+
+  socketP = getJavaIoFileDescriptorContentsAsPointer (env, fileDescriptor);
+  if (!hysock_socketIsValid (socketP))
+    {
+      throwJavaNetSocketException (env, HYPORT_ERROR_SOCKET_BADSOCKET);
+      return;
+    }
+  else
+    {
+      netGetJavaNetInetAddressValue (env, inetAddress, nlocalAddrBytes,
+                                     &length);
+
+      nPort = hysock_htons ((U_16) localPort);
+      if (length == HYSOCK_INADDR6_LEN)
+        {
+          netGetJavaNetInetAddressScopeId (env, inetAddress, &scope_id);
+          hysock_sockaddr_init6 (&sockaddrP, nlocalAddrBytes, length,
+                                 HYADDR_FAMILY_AFINET6, nPort, 0, scope_id,
+                                 socketP);
+        }
+      else
+        {
+          hysock_sockaddr_init6 (&sockaddrP, nlocalAddrBytes, length,
+                                 HYADDR_FAMILY_AFINET4, nPort, 0, scope_id,
+                                 socketP);
+        }
+      result = hysock_bind (socketP, &sockaddrP);
+      if (0 != result)
+        {
+          throwJavaNetBindException (env, result);
+          return;
+        }
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/psimpl2.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/psimpl2.h?rev=382065&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/psimpl2.h (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/psimpl2.h Wed Mar  1 07:42:53 2006
@@ -0,0 +1,72 @@
+/* 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.
+ */
+
+#if !defined(psimpl2_h)
+#define psimpl2_h
+void JNICALL
+Java_java_net_PlainSocketImpl2_connectStreamWithTimeoutSocketImpl2 (JNIEnv *
+                                                                    env,
+                                                                    jclass
+                                                                    thisClz,
+                                                                    jobject
+                                                                    fileDescriptor,
+                                                                    jint
+                                                                    remotePort,
+                                                                    jint
+                                                                    timeout,
+                                                                    jint
+                                                                    trafficClass,
+                                                                    jobject
+                                                                    inetAddress);
+void JNICALL Java_java_net_PlainSocketImpl2_socketBindImpl2 (JNIEnv * env,
+                                                             jclass thisClz,
+                                                             jobject
+                                                             fileDescriptor,
+                                                             jint localPort,
+                                                             jobject
+                                                             inetAddress);
+void JNICALL Java_java_net_PlainSocketImpl2_createStreamSocketImpl2 (JNIEnv *
+                                                                     env,
+                                                                     jclass
+                                                                     thisClz,
+                                                                     jobject
+                                                                     thisObjFD,
+                                                                     jboolean
+                                                                     preferIPv4Stack);
+void JNICALL Java_java_net_PlainSocketImpl2_connectStreamSocketImpl2 (JNIEnv *
+                                                                      env,
+                                                                      jclass
+                                                                      thisClz,
+                                                                      jobject
+                                                                      fileDescriptor,
+                                                                      jint
+                                                                      remotePort,
+                                                                      jint
+                                                                      trafficClass,
+                                                                      jobject
+                                                                      inetAddress);
+jint JNICALL Java_java_net_PlainSocketImpl2_sendDatagramImpl2 (JNIEnv * env,
+                                                               jclass thisClz,
+                                                               jobject
+                                                               fileDescriptor,
+                                                               jbyteArray
+                                                               data,
+                                                               jint offset,
+                                                               jint msgLength,
+                                                               jint
+                                                               targetPort,
+                                                               jobject
+                                                               inetAddress);
+#endif /* psimpl2_h */

Added: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pssimpl.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pssimpl.c?rev=382065&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pssimpl.c (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pssimpl.c Wed Mar  1 07:42:53 2006
@@ -0,0 +1,61 @@
+/* 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 <stdlib.h>
+#include "jclglob.h"
+#include "nethelp.h"
+#include "helpers.h"
+#include "jclprots.h"
+
+#if defined(LINUX)
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>         /* for struct in_addr */
+#include <sys/ioctl.h>
+#include <net/if.h>             /* for struct ifconf */
+#endif
+
+#include "portsock.h"
+
+/**
+ * Create a new socket, for serversockets.  The system socket is created and 'linked' to the
+ * the java PlainServerSocketImpl by setting the file descriptor value (which is an integer 
+ * reference to socket maintained by the system).  For Server Sockets, the REUSEADDR is on by
+ * default for unix and off on other platforms.  The value is set based on what is set for the platform in
+ * setPlatformBindOptions
+ *
+ * @param	env				pointer to the JNI library
+ * @param	thisClz			pointer to the class of the receiver (of the java message)
+ * @param	thisObjFD	pointer to the file descriptor of the java PlainDatagramSocketImpl
+ * @param preferIPv4Stack if application preference is to use only IPv4 sockets (default is false)
+ */
+
+void JNICALL
+Java_java_net_PlainServerSocketImpl_createServerStreamSocketImpl (JNIEnv *
+                                                                  env,
+                                                                  jclass
+                                                                  thisClz,
+                                                                  jobject
+                                                                  thisObjFD,
+                                                                  jboolean
+                                                                  preferIPv4Stack)
+{
+  hysocket_t socketP;
+  createSocket (env, thisObjFD, HYSOCK_STREAM, preferIPv4Stack);
+  socketP =
+    (hysocket_t) getJavaIoFileDescriptorContentsAsPointer (env, thisObjFD);
+  setDefaultServerSocketOptions (env, socketP);
+}

Added: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pssimpl.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pssimpl.h?rev=382065&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pssimpl.h (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/pssimpl.h Wed Mar  1 07:42:53 2006
@@ -0,0 +1,27 @@
+/* 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.
+ */
+
+#if !defined(pssimpl_h)
+#define pssimpl_h
+void JNICALL
+Java_java_net_PlainServerSocketImpl_createServerStreamSocketImpl (JNIEnv *
+                                                                  env,
+                                                                  jclass
+                                                                  thisClz,
+                                                                  jobject
+                                                                  thisObjFD,
+                                                                  jboolean
+                                                                  preferIPv4Stack);
+#endif /* pssimpl_h */

Added: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/rafile.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/rafile.c?rev=382065&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/rafile.c (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/rafile.c Wed Mar  1 07:42:53 2006
@@ -0,0 +1,237 @@
+/* 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"
+#include "helpers.h"
+
+jlong JNICALL
+Java_java_io_RandomAccessFile_getFilePointer (JNIEnv * env, jobject recv)
+{
+  jobject fd;
+  IDATA descriptor;
+  PORT_ACCESS_FROM_ENV (env);
+
+  fd =
+    (*env)->GetObjectField (env, recv,
+                            JCL_CACHE_GET (env,
+                                           FID_java_io_RandomAccessFile_fd));
+  descriptor = (IDATA) getJavaIoFileDescriptorContentsAsPointer (env, fd);
+
+  if (descriptor == -1)
+    {
+      throwJavaIoIOExceptionClosed (env);
+      return 0;
+    }
+
+  return (jlong) hyfile_seek (descriptor, 0, HySeekCur);
+}
+
+void JNICALL
+Java_java_io_RandomAccessFile_seek (JNIEnv * env, jobject recv, jlong pos)
+{
+  jobject fd;
+  IDATA descriptor;
+  PORT_ACCESS_FROM_ENV (env);
+
+  if (pos < 0)
+    {
+      throwJavaIoIOException (env, "");
+      return;
+    }
+
+  fd =
+    (*env)->GetObjectField (env, recv,
+                            JCL_CACHE_GET (env,
+                                           FID_java_io_RandomAccessFile_fd));
+  descriptor = (IDATA) getJavaIoFileDescriptorContentsAsPointer (env, fd);
+
+  if (descriptor == -1)
+    {
+      throwJavaIoIOExceptionClosed (env);
+      return;
+    }
+
+  hyfile_seek (descriptor, (I_64) pos, HySeekSet);
+}
+
+jint JNICALL
+Java_java_io_RandomAccessFile_openImpl (JNIEnv * env, jobject recv,
+                                        jbyteArray path, jboolean writable)
+{
+  jobject fd;
+  I_32 flags =
+    writable == 0 ? HyOpenRead : HyOpenRead | HyOpenWrite | HyOpenCreate;
+  I_32 mode = writable == 0 ? 0 : 0666;
+  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, mode);
+
+  if (portFD == -1)
+    return 1;
+
+  fd =
+    (*env)->GetObjectField (env, recv,
+                            JCL_CACHE_GET (env,
+                                           FID_java_io_RandomAccessFile_fd));
+  setJavaIoFileDescriptorContentsAsPointer (env, fd, (void *) portFD);
+  return 0;
+}
+
+jlong JNICALL
+Java_java_io_RandomAccessFile_length (JNIEnv * env, jobject recv)
+{
+  jobject fd;
+  I_64 currentPosition, endOfFile;
+  IDATA descriptor;
+  PORT_ACCESS_FROM_ENV (env);
+
+  fd =
+    (*env)->GetObjectField (env, recv,
+                            JCL_CACHE_GET (env,
+                                           FID_java_io_RandomAccessFile_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);
+  hyfile_seek (descriptor, currentPosition, HySeekSet);
+  return (jlong) endOfFile;
+}
+
+jint JNICALL
+Java_java_io_RandomAccessFile_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);
+}
+
+jint JNICALL
+Java_java_io_RandomAccessFile_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);
+}
+
+void JNICALL
+Java_java_io_RandomAccessFile_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_RandomAccessFile_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_RandomAccessFile_oneTimeInitialization (JNIEnv * env,
+                                                     jclass rafClazz)
+{
+  jfieldID fdFid =
+    (*env)->GetFieldID (env, rafClazz, "fd", "Ljava/io/FileDescriptor;");
+  if (!fdFid)
+    return;
+  JCL_CACHE_SET (env, FID_java_io_RandomAccessFile_fd, fdFid);
+}
+
+void JNICALL
+Java_java_io_RandomAccessFile_setLengthImpl (JNIEnv * env, jobject recv,
+                                             jlong newLength)
+{
+  jobject fd;
+  IDATA descriptor;
+  I_64 oldPos;
+  PORT_ACCESS_FROM_ENV (env);
+
+  if (newLength < 0)
+    {
+      throwJavaIoIOException (env, "Length must be positive");
+      return;
+    }
+
+  fd =
+    (*env)->GetObjectField (env, recv,
+                            JCL_CACHE_GET (env,
+                                           FID_java_io_RandomAccessFile_fd));
+  descriptor = (IDATA) getJavaIoFileDescriptorContentsAsPointer (env, fd);
+
+  if (descriptor == -1)
+    {
+      throwJavaIoIOExceptionClosed (env);
+      return;
+    }
+
+  oldPos = hyfile_seek (descriptor, 0, HySeekCur);
+  if (!setPlatformFileLength (env, descriptor, newLength))
+    {
+      throwJavaIoIOException (env, "SetLength failed");
+      return;
+    }
+  if (oldPos < (I_64) newLength)
+    {
+      hyfile_seek (descriptor, oldPos, HySeekSet);
+    }
+  else
+    {
+      hyfile_seek (descriptor, (I_64) newLength, HySeekSet);
+    }
+}
+
+void JNICALL
+Java_java_io_RandomAccessFile_closeImpl (JNIEnv * env, jobject recv)
+{
+  /* Call the helper */
+  new_ioh_close (env, recv,
+                 JCL_CACHE_GET (env, FID_java_io_RandomAccessFile_fd));
+}

Added: incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/timezone.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/timezone.c?rev=382065&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/timezone.c (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/luni/timezone.c Wed Mar  1 07:42:53 2006
@@ -0,0 +1,28 @@
+/* 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 <stdlib.h>
+#include "jcl.h"
+#include "helpers.h"
+
+jstring JNICALL
+Java_java_util_TimeZone_getCustomTimeZone (JNIEnv * env, jclass clazz,
+                                           jintArray tzinfo,
+                                           jbooleanArray isCustomTimeZone)
+{
+  /* fill tzinfo array with Custom timezone information and return timezone location name */
+  return getCustomTimeZoneInfo (env, tzinfo, isCustomTimeZone);
+}

Propchange: incubator/harmony/enhanced/classlib/trunk/native-src/shared/math/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Mar  1 07:42:53 2006
@@ -0,0 +1 @@
+*.obj

Added: incubator/harmony/enhanced/classlib/trunk/native-src/shared/math/bigint.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/math/bigint.h?rev=382065&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/math/bigint.h (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/math/bigint.h Wed Mar  1 07:42:53 2006
@@ -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/classlib/trunk/native-src/shared/math/cbigint.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/native-src/shared/math/cbigint.c?rev=382065&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/native-src/shared/math/cbigint.c (added)
+++ incubator/harmony/enhanced/classlib/trunk/native-src/shared/math/cbigint.c Wed Mar  1 07:42:53 2006
@@ -0,0 +1,866 @@
+/* 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 "cbigint.h"
+
+#if defined(LINUX)
+#define USE_LL
+#endif
+
+#define at(i) (i)
+
+#define HIGH_IN_U64(u64) ((u64) >> 32)
+#if defined(USE_LL)
+#define LOW_IN_U64(u64) ((u64) & 0x00000000FFFFFFFFLL)
+#else
+#if defined(USE_L)
+#define LOW_IN_U64(u64) ((u64) & 0x00000000FFFFFFFFL)
+#else
+#define LOW_IN_U64(u64) ((u64) & 0x00000000FFFFFFFF)
+#endif /* USE_L */
+#endif /* USE_LL */
+
+#if defined(USE_LL)
+#define TEN_E1 (0xALL)
+#define TEN_E2 (0x64LL)
+#define TEN_E3 (0x3E8LL)
+#define TEN_E4 (0x2710LL)
+#define TEN_E5 (0x186A0LL)
+#define TEN_E6 (0xF4240LL)
+#define TEN_E7 (0x989680LL)
+#define TEN_E8 (0x5F5E100LL)
+#define TEN_E9 (0x3B9ACA00LL)
+#define TEN_E19 (0x8AC7230489E80000LL)
+#else
+#if defined(USE_L)
+#define TEN_E1 (0xAL)
+#define TEN_E2 (0x64L)
+#define TEN_E3 (0x3E8L)
+#define TEN_E4 (0x2710L)
+#define TEN_E5 (0x186A0L)
+#define TEN_E6 (0xF4240L)
+#define TEN_E7 (0x989680L)
+#define TEN_E8 (0x5F5E100L)
+#define TEN_E9 (0x3B9ACA00L)
+#define TEN_E19 (0x8AC7230489E80000L)
+#else
+#define TEN_E1 (0xA)
+#define TEN_E2 (0x64)
+#define TEN_E3 (0x3E8)
+#define TEN_E4 (0x2710)
+#define TEN_E5 (0x186A0)
+#define TEN_E6 (0xF4240)
+#define TEN_E7 (0x989680)
+#define TEN_E8 (0x5F5E100)
+#define TEN_E9 (0x3B9ACA00)
+#define TEN_E19 (0x8AC7230489E80000)
+#endif /* USE_L */
+#endif /* USE_LL */
+
+#define TIMES_TEN(x) (((x) << 3) + ((x) << 1))
+#define bitSection(x, mask, shift) (((x) & (mask)) >> (shift))
+#define DOUBLE_TO_LONGBITS(dbl) (*((U_64 *)(&dbl)))
+#define FLOAT_TO_INTBITS(flt) (*((U_32 *)(&flt)))
+#define CREATE_DOUBLE_BITS(normalizedM, e) (((normalizedM) & MANTISSA_MASK) | (((U_64)((e) + E_OFFSET)) << 52))
+
+#if defined(USE_LL)
+#define MANTISSA_MASK (0x000FFFFFFFFFFFFFLL)
+#define EXPONENT_MASK (0x7FF0000000000000LL)
+#define NORMAL_MASK (0x0010000000000000LL)
+#define SIGN_MASK (0x8000000000000000LL)
+#else
+#if defined(USE_L)
+#define MANTISSA_MASK (0x000FFFFFFFFFFFFFL)
+#define EXPONENT_MASK (0x7FF0000000000000L)
+#define NORMAL_MASK (0x0010000000000000L)
+#define SIGN_MASK (0x8000000000000000L)
+#else
+#define MANTISSA_MASK (0x000FFFFFFFFFFFFF)
+#define EXPONENT_MASK (0x7FF0000000000000)
+#define NORMAL_MASK (0x0010000000000000)
+#define SIGN_MASK (0x8000000000000000)
+#endif /* USE_L */
+#endif /* USE_LL */
+
+#define E_OFFSET (1075)
+
+#define FLOAT_MANTISSA_MASK (0x007FFFFF)
+#define FLOAT_EXPONENT_MASK (0x7F800000)
+#define FLOAT_NORMAL_MASK   (0x00800000)
+#define FLOAT_E_OFFSET (150)
+
+IDATA
+simpleAddHighPrecision (U_64 * arg1, IDATA length, U_64 arg2)
+{
+  /* assumes length > 0 */
+  IDATA index = 1;
+
+  *arg1 += arg2;
+  if (arg2 <= *arg1)
+    return 0;
+  else if (length == 1)
+    return 1;
+
+  while (++arg1[index] == 0 && ++index < length);
+
+  return (IDATA) index == length;
+}
+
+IDATA
+addHighPrecision (U_64 * arg1, IDATA length1, U_64 * arg2, IDATA length2)
+{
+  /* addition is limited by length of arg1 as it this function is
+   * storing the result in arg1 */
+  /* fix for cc (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7): code generated does not
+   * do the temp1 + temp2 + carry addition correct.  carry is 64 bit because gcc has
+   * subtle issues when you mix 64 / 32 bit maths. */
+  U_64 temp1, temp2, temp3;     /* temporary variables to help the SH-4, and gcc */
+  U_64 carry;
+  IDATA index;
+
+  if (length1 == 0 || length2 == 0)
+    {
+      return 0;
+    }
+  else if (length1 < length2)
+    {
+      length2 = length1;
+    }
+
+  carry = 0;
+  index = 0;
+  do
+    {
+      temp1 = arg1[index];
+      temp2 = arg2[index];
+      temp3 = temp1 + temp2;
+      arg1[index] = temp3 + carry;
+      if (arg2[index] < arg1[index])
+        carry = 0;
+      else if (arg2[index] != arg1[index])
+        carry = 1;
+    }
+  while (++index < length2);
+  if (!carry)
+    return 0;
+  else if (index == length1)
+    return 1;
+
+  while (++arg1[index] == 0 && ++index < length1);
+
+  return (IDATA) index == length1;
+}
+
+void
+subtractHighPrecision (U_64 * arg1, IDATA length1, U_64 * arg2, IDATA length2)
+{
+  /* assumes arg1 > arg2 */
+  IDATA index;
+  for (index = 0; index < length1; ++index)
+    arg1[index] = ~arg1[index];
+  simpleAddHighPrecision (arg1, length1, 1);
+
+  while (length2 > 0 && arg2[length2 - 1] == 0)
+    --length2;
+
+  addHighPrecision (arg1, length1, arg2, length2);
+
+  for (index = 0; index < length1; ++index)
+    arg1[index] = ~arg1[index];
+  simpleAddHighPrecision (arg1, length1, 1);
+}
+
+U_32
+simpleMultiplyHighPrecision (U_64 * arg1, IDATA length, U_64 arg2)
+{
+  /* assumes arg2 only holds 32 bits of information */
+  U_64 product;
+  IDATA index;
+
+  index = 0;
+  product = 0;
+
+  do
+    {
+      product =
+        HIGH_IN_U64 (product) + arg2 * LOW_U32_FROM_PTR (arg1 + index);
+      LOW_U32_FROM_PTR (arg1 + index) = LOW_U32_FROM_VAR (product);
+      product =
+        HIGH_IN_U64 (product) + arg2 * HIGH_U32_FROM_PTR (arg1 + index);
+      HIGH_U32_FROM_PTR (arg1 + index) = LOW_U32_FROM_VAR (product);
+    }
+  while (++index < length);
+
+  return HIGH_U32_FROM_VAR (product);
+}
+
+void
+simpleMultiplyAddHighPrecision (U_64 * arg1, IDATA length, U_64 arg2,
+                                U_32 * result)
+{
+  /* Assumes result can hold the product and arg2 only holds 32 bits
+     of information */
+  U_64 product;
+  IDATA index, resultIndex;
+
+  index = resultIndex = 0;
+  product = 0;
+
+  do
+    {
+      product =
+        HIGH_IN_U64 (product) + result[at (resultIndex)] +
+        arg2 * LOW_U32_FROM_PTR (arg1 + index);
+      result[at (resultIndex)] = LOW_U32_FROM_VAR (product);
+      ++resultIndex;
+      product =
+        HIGH_IN_U64 (product) + result[at (resultIndex)] +
+        arg2 * HIGH_U32_FROM_PTR (arg1 + index);
+      result[at (resultIndex)] = LOW_U32_FROM_VAR (product);
+      ++resultIndex;
+    }
+  while (++index < length);
+
+  result[at (resultIndex)] += HIGH_U32_FROM_VAR (product);
+  if (result[at (resultIndex)] < HIGH_U32_FROM_VAR (product))
+    {
+      /* must be careful with ++ operator and macro expansion */
+      ++resultIndex;
+      while (++result[at (resultIndex)] == 0)
+        ++resultIndex;
+    }
+}
+
+void
+multiplyHighPrecision (U_64 * arg1, IDATA length1, U_64 * arg2, IDATA length2,
+                       U_64 * result, IDATA length)
+{
+  /* assumes result is large enough to hold product */
+  U_64 *temp;
+  U_32 *resultIn32;
+  IDATA count, index;
+
+  if (length1 < length2)
+    {
+      temp = arg1;
+      arg1 = arg2;
+      arg2 = temp;
+      count = length1;
+      length1 = length2;
+      length2 = count;
+    }
+
+  memset (result, 0, sizeof (U_64) * length);
+
+  /* length1 > length2 */
+  resultIn32 = (U_32 *) result;
+  index = -1;
+  for (count = 0; count < length2; ++count)
+    {
+      simpleMultiplyAddHighPrecision (arg1, length1, LOW_IN_U64 (arg2[count]),
+                                      resultIn32 + (++index));
+      simpleMultiplyAddHighPrecision (arg1, length1,
+                                      HIGH_IN_U64 (arg2[count]),
+                                      resultIn32 + (++index));
+
+    }
+}
+
+U_32
+simpleAppendDecimalDigitHighPrecision (U_64 * arg1, IDATA length, U_64 digit)
+{
+  /* assumes digit is less than 32 bits */
+  U_64 arg;
+  IDATA index = 0;
+
+  digit <<= 32;
+  do
+    {
+      arg = LOW_IN_U64 (arg1[index]);
+      digit = HIGH_IN_U64 (digit) + TIMES_TEN (arg);
+      LOW_U32_FROM_PTR (arg1 + index) = LOW_U32_FROM_VAR (digit);
+
+      arg = HIGH_IN_U64 (arg1[index]);
+      digit = HIGH_IN_U64 (digit) + TIMES_TEN (arg);
+      HIGH_U32_FROM_PTR (arg1 + index) = LOW_U32_FROM_VAR (digit);
+    }
+  while (++index < length);
+
+  return HIGH_U32_FROM_VAR (digit);
+}
+
+void
+simpleShiftLeftHighPrecision (U_64 * arg1, IDATA length, IDATA arg2)
+{
+  /* assumes length > 0 */
+  IDATA index, offset;
+  if (arg2 >= 64)
+    {
+      offset = arg2 >> 6;
+      index = length;
+
+      while (--index - offset >= 0)
+        arg1[index] = arg1[index - offset];
+      do
+        {
+          arg1[index] = 0;
+        }
+      while (--index >= 0);
+
+      arg2 &= 0x3F;
+    }
+
+  if (arg2 == 0)
+    return;
+  while (--length > 0)
+    {
+      arg1[length] = arg1[length] << arg2 | arg1[length - 1] >> (64 - arg2);
+    }
+  *arg1 <<= arg2;
+}
+
+IDATA
+highestSetBit (U_64 * y)
+{
+  U_32 x;
+  IDATA result;
+
+  if (*y == 0)
+    return 0;
+
+#if defined(USE_LL)
+  if (*y & 0xFFFFFFFF00000000LL)
+    {
+      x = HIGH_U32_FROM_PTR (y);
+      result = 32;
+    }
+  else
+    {
+      x = LOW_U32_FROM_PTR (y);
+      result = 0;
+    }
+#else
+#if defined(USE_L)
+  if (*y & 0xFFFFFFFF00000000L)
+    {
+      x = HIGH_U32_FROM_PTR (y);
+      result = 32;
+    }
+  else
+    {
+      x = LOW_U32_FROM_PTR (y);
+      result = 0;
+    }
+#else
+  if (*y & 0xFFFFFFFF00000000)
+    {
+      x = HIGH_U32_FROM_PTR (y);
+      result = 32;
+    }
+  else
+    {
+      x = LOW_U32_FROM_PTR (y);
+      result = 0;
+    }
+#endif /* USE_L */
+#endif /* USE_LL */
+
+  if (x & 0xFFFF0000)
+    {
+      x = bitSection (x, 0xFFFF0000, 16);
+      result += 16;
+    }
+  if (x & 0xFF00)
+    {
+      x = bitSection (x, 0xFF00, 8);
+      result += 8;
+    }
+  if (x & 0xF0)
+    {
+      x = bitSection (x, 0xF0, 4);
+      result += 4;
+    }
+  if (x > 0x7)
+    return result + 4;
+  else if (x > 0x3)
+    return result + 3;
+  else if (x > 0x1)
+    return result + 2;
+  else
+    return result + 1;
+}
+
+IDATA
+lowestSetBit (U_64 * y)
+{
+  U_32 x;
+  IDATA result;
+
+  if (*y == 0)
+    return 0;
+
+#if defined(USE_LL)
+  if (*y & 0x00000000FFFFFFFFLL)
+    {
+      x = LOW_U32_FROM_PTR (y);
+      result = 0;
+    }
+  else
+    {
+      x = HIGH_U32_FROM_PTR (y);
+      result = 32;
+    }
+#else
+#if defined(USE_L)
+  if (*y & 0x00000000FFFFFFFFL)
+    {
+      x = LOW_U32_FROM_PTR (y);
+      result = 0;
+    }
+  else
+    {
+      x = HIGH_U32_FROM_PTR (y);
+      result = 32;
+    }
+#else
+  if (*y & 0x00000000FFFFFFFF)
+    {
+      x = LOW_U32_FROM_PTR (y);
+      result = 0;
+    }
+  else
+    {
+      x = HIGH_U32_FROM_PTR (y);
+      result = 32;
+    }
+#endif /* USE_L */
+#endif /* USE_LL */
+
+  if (!(x & 0xFFFF))
+    {
+      x = bitSection (x, 0xFFFF0000, 16);
+      result += 16;
+    }
+  if (!(x & 0xFF))
+    {
+      x = bitSection (x, 0xFF00, 8);
+      result += 8;
+    }
+  if (!(x & 0xF))
+    {
+      x = bitSection (x, 0xF0, 4);
+      result += 4;
+    }
+
+  if (x & 0x1)
+    return result + 1;
+  else if (x & 0x2)
+    return result + 2;
+  else if (x & 0x4)
+    return result + 3;
+  else
+    return result + 4;
+}
+
+IDATA
+highestSetBitHighPrecision (U_64 * arg, IDATA length)
+{
+  IDATA highBit;
+
+  while (--length >= 0)
+    {
+      highBit = highestSetBit (arg + length);
+      if (highBit)
+        return highBit + 64 * length;
+    }
+
+  return 0;
+}
+
+IDATA
+lowestSetBitHighPrecision (U_64 * arg, IDATA length)
+{
+  IDATA lowBit, index = -1;
+
+  while (++index < length)
+    {
+      lowBit = lowestSetBit (arg + index);
+      if (lowBit)
+        return lowBit + 64 * index;
+    }
+
+  return 0;
+}
+
+IDATA
+compareHighPrecision (U_64 * arg1, IDATA length1, U_64 * arg2, IDATA length2)
+{
+  while (--length1 >= 0 && arg1[length1] == 0);
+  while (--length2 >= 0 && arg2[length2] == 0);
+
+  if (length1 > length2)
+    return 1;
+  else if (length1 < length2)
+    return -1;
+  else if (length1 > -1)
+    {
+      do
+        {
+          if (arg1[length1] > arg2[length1])
+            return 1;
+          else if (arg1[length1] < arg2[length1])
+            return -1;
+        }
+      while (--length1 >= 0);
+    }
+
+  return 0;
+}
+
+jdouble
+toDoubleHighPrecision (U_64 * arg, IDATA length)
+{
+  IDATA highBit;
+  U_64 mantissa, test64;
+  U_32 test;
+  jdouble result;
+
+  while (length > 0 && arg[length - 1] == 0)
+    --length;
+
+  if (length == 0)
+    result = 0.0;
+  else if (length > 16)
+    {
+      DOUBLE_TO_LONGBITS (result) = EXPONENT_MASK;
+    }
+  else if (length == 1)
+    {
+      highBit = highestSetBit (arg);
+      if (highBit <= 53)
+        {
+          highBit = 53 - highBit;
+          mantissa = *arg << highBit;
+          DOUBLE_TO_LONGBITS (result) =
+            CREATE_DOUBLE_BITS (mantissa, -highBit);
+        }
+      else
+        {
+          highBit -= 53;
+          mantissa = *arg >> highBit;
+          DOUBLE_TO_LONGBITS (result) =
+            CREATE_DOUBLE_BITS (mantissa, highBit);
+
+          /* perform rounding, round to even in case of tie */
+          test = (LOW_U32_FROM_PTR (arg) << (11 - highBit)) & 0x7FF;
+          if (test > 0x400 || ((test == 0x400) && (mantissa & 1)))
+            DOUBLE_TO_LONGBITS (result) = DOUBLE_TO_LONGBITS (result) + 1;
+        }
+    }
+  else
+    {
+      highBit = highestSetBit (arg + (--length));
+      if (highBit <= 53)
+        {
+          highBit = 53 - highBit;
+          if (highBit > 0)
+            {
+              mantissa =
+                (arg[length] << highBit) | (arg[length - 1] >>
+                                            (64 - highBit));
+            }
+          else
+            {
+              mantissa = arg[length];
+            }
+          DOUBLE_TO_LONGBITS (result) =
+            CREATE_DOUBLE_BITS (mantissa, length * 64 - highBit);
+
+          /* perform rounding, round to even in case of tie */
+          test64 = arg[--length] << highBit;
+          if (test64 > SIGN_MASK || ((test64 == SIGN_MASK) && (mantissa & 1)))
+            DOUBLE_TO_LONGBITS (result) = DOUBLE_TO_LONGBITS (result) + 1;
+          else if (test64 == SIGN_MASK)
+            {
+              while (--length >= 0)
+                {
+                  if (arg[length] != 0)
+                    {
+                      DOUBLE_TO_LONGBITS (result) =
+                        DOUBLE_TO_LONGBITS (result) + 1;
+                      break;
+                    }
+                }
+            }
+        }
+      else
+        {
+          highBit -= 53;
+          mantissa = arg[length] >> highBit;
+          DOUBLE_TO_LONGBITS (result) =
+            CREATE_DOUBLE_BITS (mantissa, length * 64 + highBit);
+
+          /* perform rounding, round to even in case of tie */
+          test = (LOW_U32_FROM_PTR (arg + length) << (11 - highBit)) & 0x7FF;
+          if (test > 0x400 || ((test == 0x400) && (mantissa & 1)))
+            DOUBLE_TO_LONGBITS (result) = DOUBLE_TO_LONGBITS (result) + 1;
+          else if (test == 0x400)
+            {
+              do
+                {
+                  if (arg[--length] != 0)
+                    {
+                      DOUBLE_TO_LONGBITS (result) =
+                        DOUBLE_TO_LONGBITS (result) + 1;
+                      break;
+                    }
+                }
+              while (length > 0);
+            }
+        }
+    }
+
+  return result;
+}
+
+IDATA
+tenToTheEHighPrecision (U_64 * result, IDATA length, jint e)
+{
+  /* size test */
+  if (length < ((e / 19) + 1))
+    return 0;
+
+  memset (result, 0, length * sizeof (U_64));
+  *result = 1;
+
+  if (e == 0)
+    return 1;
+
+  length = 1;
+  length = timesTenToTheEHighPrecision (result, length, e);
+  /* bad O(n) way of doing it, but simple */
+  /*
+     do {
+     overflow = simpleAppendDecimalDigitHighPrecision(result, length, 0);
+     if (overflow)
+     result[length++] = overflow; 
+     } while (--e);
+   */
+  return length;
+}
+
+IDATA
+timesTenToTheEHighPrecision (U_64 * result, IDATA length, jint e)
+{
+  /* assumes result can hold value */
+  U_64 overflow;
+  int exp10 = e;
+
+  if (e == 0)
+    return length;
+
+  /* bad O(n) way of doing it, but simple */
+  /*
+     do {
+     overflow = simpleAppendDecimalDigitHighPrecision(result, length, 0);
+     if (overflow)
+     result[length++] = overflow; 
+     } while (--e);
+   */
+  /* Replace the current implementaion which performs a
+   * "multiplication" by 10 e number of times with an actual
+   * mulitplication. 10e19 is the largest exponent to the power of ten
+   * that will fit in a 64-bit integer, and 10e9 is the largest exponent to
+   * the power of ten that will fit in a 64-bit integer. Not sure where the
+   * break-even point is between an actual multiplication and a
+   * simpleAappendDecimalDigit() so just pick 10e3 as that point for
+   * now.
+   */
+  while (exp10 >= 19)
+    {
+      overflow = simpleMultiplyHighPrecision64 (result, length, TEN_E19);
+      if (overflow)
+        result[length++] = overflow;
+      exp10 -= 19;
+    }
+  while (exp10 >= 9)
+    {
+      overflow = simpleMultiplyHighPrecision (result, length, TEN_E9);
+      if (overflow)
+        result[length++] = overflow;
+      exp10 -= 9;
+    }
+  if (exp10 == 0)
+    return length;
+  else if (exp10 == 1)
+    {
+      overflow = simpleAppendDecimalDigitHighPrecision (result, length, 0);
+      if (overflow)
+        result[length++] = overflow;
+    }
+  else if (exp10 == 2)
+    {
+      overflow = simpleAppendDecimalDigitHighPrecision (result, length, 0);
+      if (overflow)
+        result[length++] = overflow;
+      overflow = simpleAppendDecimalDigitHighPrecision (result, length, 0);
+      if (overflow)
+        result[length++] = overflow;
+    }
+  else if (exp10 == 3)
+    {
+      overflow = simpleMultiplyHighPrecision (result, length, TEN_E3);
+      if (overflow)
+        result[length++] = overflow;
+    }
+  else if (exp10 == 4)
+    {
+      overflow = simpleMultiplyHighPrecision (result, length, TEN_E4);
+      if (overflow)
+        result[length++] = overflow;
+    }
+  else if (exp10 == 5)
+    {
+      overflow = simpleMultiplyHighPrecision (result, length, TEN_E5);
+      if (overflow)
+        result[length++] = overflow;
+    }
+  else if (exp10 == 6)
+    {
+      overflow = simpleMultiplyHighPrecision (result, length, TEN_E6);
+      if (overflow)
+        result[length++] = overflow;
+    }
+  else if (exp10 == 7)
+    {
+      overflow = simpleMultiplyHighPrecision (result, length, TEN_E7);
+      if (overflow)
+        result[length++] = overflow;
+    }
+  else if (exp10 == 8)
+    {
+      overflow = simpleMultiplyHighPrecision (result, length, TEN_E8);
+      if (overflow)
+        result[length++] = overflow;
+    }
+  return length;
+}
+
+U_64
+doubleMantissa (jdouble z)
+{
+  U_64 m = DOUBLE_TO_LONGBITS (z);
+
+  if ((m & EXPONENT_MASK) != 0)
+    m = (m & MANTISSA_MASK) | NORMAL_MASK;
+  else
+    m = (m & MANTISSA_MASK);
+
+  return m;
+}
+
+IDATA
+doubleExponent (jdouble z)
+{
+  /* assumes positive double */
+  IDATA k = HIGH_U32_FROM_VAR (z) >> 20;
+
+  if (k)
+    k -= E_OFFSET;
+  else
+    k = 1 - E_OFFSET;
+
+  return k;
+}
+
+UDATA
+floatMantissa (jfloat z)
+{
+  UDATA m = (UDATA) FLOAT_TO_INTBITS (z);
+
+  if ((m & FLOAT_EXPONENT_MASK) != 0)
+    m = (m & FLOAT_MANTISSA_MASK) | FLOAT_NORMAL_MASK;
+  else
+    m = (m & FLOAT_MANTISSA_MASK);
+
+  return m;
+}
+
+IDATA
+floatExponent (jfloat z)
+{
+  /* assumes positive float */
+  IDATA k = FLOAT_TO_INTBITS (z) >> 23;
+  if (k)
+    k -= FLOAT_E_OFFSET;
+  else
+    k = 1 - FLOAT_E_OFFSET;
+
+  return k;
+}
+
+/* Allow a 64-bit value in arg2 */
+U_64
+simpleMultiplyHighPrecision64 (U_64 * arg1, IDATA length, U_64 arg2)
+{
+  U_64 intermediate, *pArg1, carry1, carry2, prod1, prod2, sum;
+  IDATA index;
+  U_32 buf32;
+
+  index = 0;
+  intermediate = 0;
+  pArg1 = arg1 + index;
+  carry1 = carry2 = 0;
+
+  do
+    {
+      if ((*pArg1 != 0) || (intermediate != 0))
+        {
+          prod1 =
+            (U_64) LOW_U32_FROM_VAR (arg2) * (U_64) LOW_U32_FROM_PTR (pArg1);
+          sum = intermediate + prod1;
+          if ((sum < prod1) || (sum < intermediate))
+            {
+              carry1 = 1;
+            }
+          else
+            {
+              carry1 = 0;
+            }
+          prod1 =
+            (U_64) LOW_U32_FROM_VAR (arg2) * (U_64) HIGH_U32_FROM_PTR (pArg1);
+          prod2 =
+            (U_64) HIGH_U32_FROM_VAR (arg2) * (U_64) LOW_U32_FROM_PTR (pArg1);
+          intermediate = carry2 + HIGH_IN_U64 (sum) + prod1 + prod2;
+          if ((intermediate < prod1) || (intermediate < prod2))
+            {
+              carry2 = 1;
+            }
+          else
+            {
+              carry2 = 0;
+            }
+          LOW_U32_FROM_PTR (pArg1) = LOW_U32_FROM_VAR (sum);
+          buf32 = HIGH_U32_FROM_PTR (pArg1);
+          HIGH_U32_FROM_PTR (pArg1) = LOW_U32_FROM_VAR (intermediate);
+          intermediate = carry1 + HIGH_IN_U64 (intermediate)
+            + (U_64) HIGH_U32_FROM_VAR (arg2) * (U_64) buf32;
+        }
+      pArg1++;
+    }
+  while (++index < length);
+  return intermediate;
+}



Mime
View raw message