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 [139/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/linux.IA32/archive/inflater.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/inflater.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/inflater.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/inflater.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,289 @@
+/* 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 "iohelp.h"
+#include "jclglob.h"
+#include "jclprots.h"
+
+#include "inflater.h"
+
+void throwNewDataFormatException (JNIEnv * env, char *message);
+
+/* Create a new stream . This stream cannot be used until it has been properly initialized. */
+jlong JNICALL
+Java_java_util_zip_Inflater_createStream (JNIEnv * env, jobject recv,
+ jboolean noHeader)
+{
+ PORT_ACCESS_FROM_ENV (env);
+
+ JCLZipStream *jstream;
+ z_stream *stream;
+ int err = 0;
+ int wbits = 15; /*Use MAX for fastest */
+
+ /*Allocate mem for wrapped struct */
+ jstream = jclmem_allocate_memory (env, sizeof (JCLZipStream));
+ if (jstream == NULL)
+ {
+ throwNewOutOfMemoryError (env, "");
+ return -1;
+ }
+
+ /*Allocate the z_stream */
+ stream = jclmem_allocate_memory (env, sizeof (z_stream));
+ if (stream == NULL)
+ {
+ jclmem_free_memory (env, jstream);
+ throwNewOutOfMemoryError (env, "");
+ return -1;
+ }
+ stream->opaque = (void *) privatePortLibrary;
+ stream->zalloc = zalloc;
+ stream->zfree = zfree;
+ /* Initialize adler for compatibility with zlib 1.1.4 */
+ stream->adler = 1;
+ jstream->stream = stream;
+ jstream->dict = NULL;
+ jstream->inaddr = NULL;
+
+ if (noHeader) /*Unable to find official doc that this is the way to avoid zlib header use. However doc in zipsup.c claims it is so. */
+ wbits = wbits / -1;
+ err = inflateInit2 (stream, wbits); /*Window bits to use. 15 is fastest but consumes the most memory */
+
+ if (err != Z_OK)
+ {
+ jclmem_free_memory (env, stream);
+ jclmem_free_memory (env, jstream);
+ throwNewIllegalArgumentException (env, "");
+ return -1;
+ }
+
+ return (jlong) ((IDATA) jstream);
+}
+
+void JNICALL
+Java_java_util_zip_Inflater_setInputImpl (JNIEnv * env, jobject recv,
+ jbyteArray buf, jint off, jint len,
+ jlong handle)
+{
+ PORT_ACCESS_FROM_ENV (env);
+
+ jbyte *in;
+ U_8 *baseAddr;
+ JCLZipStream *stream = (JCLZipStream *) ((IDATA) handle);
+
+ if (stream->inaddr != NULL) /*Input has already been provided, free the old buffer */
+ jclmem_free_memory (env, stream->inaddr);
+ baseAddr = jclmem_allocate_memory (env, len);
+ if (baseAddr == NULL)
+ {
+ throwNewOutOfMemoryError (env, "");
+ return;
+ }
+ stream->inaddr = baseAddr;
+ stream->stream->next_in = (Bytef *) baseAddr;
+ stream->stream->avail_in = len;
+ in = ((*env)->GetPrimitiveArrayCritical (env, buf, 0));
+ if (in == NULL)
+ return;
+ memcpy (baseAddr, (in + off), len);
+ ((*env)->ReleasePrimitiveArrayCritical (env, buf, in, JNI_ABORT));
+ return;
+}
+
+jint JNICALL
+Java_java_util_zip_Inflater_inflateImpl (JNIEnv * env, jobject recv,
+ jbyteArray buf, int off, int len,
+ jlong handle)
+{
+ PORT_ACCESS_FROM_ENV (env);
+
+ jbyte *out;
+ JCLZipStream *stream = (JCLZipStream *) ((IDATA) handle);
+ jint err = 0;
+ jfieldID fid = 0, fid2 = 0;
+ jint sin, sout, inBytes = 0;
+
+ /* We need to get the number of bytes already read */
+ fid = JCL_CACHE_GET (env, FID_java_util_zip_Inflater_inRead);
+ inBytes = ((*env)->GetIntField (env, recv, fid));
+
+ stream->stream->avail_out = len;
+ sin = stream->stream->total_in;
+ sout = stream->stream->total_out;
+ out = ((*env)->GetPrimitiveArrayCritical (env, buf, 0));
+ if (out == NULL)
+ return -1;
+ stream->stream->next_out = (Bytef *) out + off;
+ err = inflate (stream->stream, Z_SYNC_FLUSH);
+ ((*env)->ReleasePrimitiveArrayCritical (env, buf, out, 0));
+
+ if (err != Z_OK)
+ {
+ if (err == Z_STREAM_END || err == Z_NEED_DICT)
+ {
+ ((*env)->SetIntField (env, recv, fid, (jint) stream->stream->total_in - sin + inBytes)); /* Update inRead */
+ if (err == Z_STREAM_END)
+ fid2 = JCL_CACHE_GET (env, FID_java_util_zip_Inflater_finished);
+ else
+ fid2 =
+ JCL_CACHE_GET (env, FID_java_util_zip_Inflater_needsDictionary);
+
+ ((*env)->SetBooleanField (env, recv, fid2, JNI_TRUE));
+ return stream->stream->total_out - sout;
+ }
+ else
+ {
+ throwNewDataFormatException (env, "");
+ return -1;
+ }
+ }
+
+ /* Need to update the number of input bytes read. Is there a better way
+ * (Maybe global the fid then delete when end is called)?
+ */
+ ((*env)->
+ SetIntField (env, recv, fid,
+ (jint) stream->stream->total_in - sin + inBytes));
+
+ return stream->stream->total_out - sout;
+}
+
+jint JNICALL
+Java_java_util_zip_Inflater_getAdlerImpl (JNIEnv * env, jobject recv,
+ jlong handle)
+{
+ JCLZipStream *stream;
+
+ stream = (JCLZipStream *) ((IDATA) handle);
+
+ return stream->stream->adler;
+}
+
+void JNICALL
+Java_java_util_zip_Inflater_endImpl (JNIEnv * env, jobject recv, jlong handle)
+{
+ PORT_ACCESS_FROM_ENV (env);
+ JCLZipStream *stream;
+
+ stream = (JCLZipStream *) ((IDATA) handle);
+ inflateEnd (stream->stream);
+ if (stream->inaddr != NULL) /*Input has been provided, free the buffer */
+ jclmem_free_memory (env, stream->inaddr);
+ if (stream->dict != NULL)
+ jclmem_free_memory (env, stream->dict);
+ jclmem_free_memory (env, stream->stream);
+ jclmem_free_memory (env, stream);
+}
+
+void JNICALL
+Java_java_util_zip_Inflater_setDictionaryImpl (JNIEnv * env, jobject recv,
+ jbyteArray dict, int off,
+ int len, jlong handle)
+{
+ PORT_ACCESS_FROM_ENV (env);
+ int err = 0;
+ U_8 *dBytes;
+ JCLZipStream *stream = (JCLZipStream *) ((IDATA) handle);
+
+ dBytes = jclmem_allocate_memory (env, len);
+ if (dBytes == NULL)
+ {
+ throwNewOutOfMemoryError (env, "");
+ return;
+ }
+ (*env)->GetByteArrayRegion (env, dict, off, len, dBytes);
+ err = inflateSetDictionary (stream->stream, (Bytef *) dBytes, len);
+ if (err != Z_OK)
+ {
+ jclmem_free_memory (env, dBytes);
+ throwNewIllegalArgumentException (env, "");
+ return;
+ }
+ stream->dict = dBytes;
+}
+
+void JNICALL
+Java_java_util_zip_Inflater_resetImpl (JNIEnv * env, jobject recv,
+ jlong handle)
+{
+ JCLZipStream *stream;
+ int err = 0;
+ stream = (JCLZipStream *) ((IDATA) handle);
+
+ err = inflateReset (stream->stream);
+ if (err != Z_OK)
+ {
+ throwNewIllegalArgumentException (env, "");
+ return;
+ }
+}
+
+/**
+ * Throw java.util.zip.DataFormatException
+ */
+void
+throwNewDataFormatException (JNIEnv * env, char *message)
+{
+ jclass exceptionClass = (*env)->FindClass(env, "java/util/zip/DataFormatException");
+ if (0 == exceptionClass) {
+ /* Just return if we can't load the exception class. */
+ return;
+ }
+ (*env)->ThrowNew(env, exceptionClass, message);
+}
+
+int JNICALL
+Java_java_util_zip_Inflater_getTotalOutImpl (JNIEnv * env, jobject recv,
+ jlong handle)
+{
+ JCLZipStream *stream;
+
+ stream = (JCLZipStream *) ((IDATA) handle);
+ return stream->stream->total_out;
+
+}
+
+int JNICALL
+Java_java_util_zip_Inflater_getTotalInImpl (JNIEnv * env, jobject recv,
+ jlong handle)
+{
+ JCLZipStream *stream;
+
+ stream = (JCLZipStream *) ((IDATA) handle);
+ return stream->stream->total_in;
+}
+
+void JNICALL
+Java_java_util_zip_Inflater_oneTimeInitialization (JNIEnv * env, jclass clazz)
+{
+ jfieldID fid;
+
+ fid = (*env)->GetFieldID (env, clazz, "inRead", "I");
+ if (!fid)
+ return;
+ JCL_CACHE_SET (env, FID_java_util_zip_Inflater_inRead, fid);
+
+ fid = (*env)->GetFieldID (env, clazz, "finished", "Z");
+ if (!fid)
+ return;
+ JCL_CACHE_SET (env, FID_java_util_zip_Inflater_finished, fid);
+
+ fid = (*env)->GetFieldID (env, clazz, "needsDictionary", "Z");
+ if (!fid)
+ return;
+ JCL_CACHE_SET (env, FID_java_util_zip_Inflater_needsDictionary, fid);
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/inflater.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/inflater.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/inflater.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/inflater.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,63 @@
+/* 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(inflater_h)
+#define inflater_h
+
+#include "zlib.h"
+typedef struct JCLZipStream
+{
+ U_8 *inaddr;
+ U_8 *dict;
+ z_stream *stream;
+} JCLZipStream;
+
+void zfree PROTOTYPE ((void *opaque, void *address));
+void *zalloc PROTOTYPE ((void *opaque, U_32 items, U_32 size));
+void JNICALL Java_java_util_zip_Inflater_endImpl (JNIEnv * env, jobject recv,
+ jlong handle);
+void JNICALL Java_java_util_zip_Inflater_setInputImpl (JNIEnv * env,
+ jobject recv,
+ jbyteArray buf,
+ jint off, jint len,
+ jlong handle);
+jint JNICALL Java_java_util_zip_Inflater_inflateImpl (JNIEnv * env,
+ jobject recv,
+ jbyteArray buf, int off,
+ int len, jlong handle);
+void JNICALL Java_java_util_zip_Inflater_setDictionaryImpl (JNIEnv * env,
+ jobject recv,
+ jbyteArray dict,
+ int off, int len,
+ jlong handle);
+void JNICALL Java_java_util_zip_Inflater_oneTimeInitialization (JNIEnv * env,
+ jclass clazz);
+void JNICALL Java_java_util_zip_Inflater_resetImpl (JNIEnv * env,
+ jobject recv,
+ jlong handle);
+int JNICALL Java_java_util_zip_Inflater_getTotalOutImpl (JNIEnv * env,
+ jobject recv,
+ jlong handle);
+jlong JNICALL Java_java_util_zip_Inflater_createStream (JNIEnv * env,
+ jobject recv,
+ jboolean noHeader);
+int JNICALL Java_java_util_zip_Inflater_getTotalInImpl (JNIEnv * env,
+ jobject recv,
+ jlong handle);
+jint JNICALL Java_java_util_zip_Inflater_getAdlerImpl (JNIEnv * env,
+ jobject recv,
+ jlong handle);
+
+#endif /* inflater_h */
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/jarfile.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/jarfile.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/jarfile.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/jarfile.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,172 @@
+/* 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 "iohelp.h"
+#include "jclglob.h"
+#include "jclprots.h"
+
+#include "zipsup.h"
+
+/* Build a new ZipEntry from the C struct */
+jobject
+createZipEntry (JNIEnv * env, HyZipFile * zipFile, HyZipEntry * zipEntry)
+{
+ PORT_ACCESS_FROM_ENV (env);
+ jclass javaClass;
+ jobject java_ZipEntry, extra, entryName;
+ jmethodID mid;
+
+ /* Build a new ZipEntry from the C struct */
+ entryName = ((*env)->NewStringUTF (env, zipEntry->filename));
+ if (((*env)->ExceptionCheck (env)))
+ return NULL;
+
+ extra = NULL;
+ if (zipEntry->extraFieldLength > 0)
+ {
+ zip_getZipEntryExtraField (PORTLIB, zipFile, zipEntry, NULL,
+ zipEntry->extraFieldLength);
+ if (zipEntry->extraField == NULL)
+ return NULL;
+ extra = ((*env)->NewByteArray (env, zipEntry->extraFieldLength));
+ if (((*env)->ExceptionCheck (env)))
+ return NULL;
+ ((*env)->
+ SetByteArrayRegion (env, extra, 0, zipEntry->extraFieldLength,
+ zipEntry->extraField));
+ jclmem_free_memory (env, zipEntry->extraField);
+ zipEntry->extraField = NULL;
+ }
+
+ javaClass = JCL_CACHE_GET (env, CLS_java_util_zip_ZipEntry);
+ mid = JCL_CACHE_GET (env, MID_java_util_zip_ZipEntry_init);
+ java_ZipEntry = ((*env)->NewObject (env, javaClass, mid, entryName, NULL, /* comment */
+ extra,
+ (jlong) zipEntry->lastModTime,
+ (jlong) zipEntry->uncompressedSize,
+ (jlong) zipEntry->compressedSize,
+ (jlong) zipEntry->crc32,
+ zipEntry->compressionMethod,
+ (jlong) zipEntry->lastModDate,
+ (jlong) zipEntry->dataPointer));
+ return java_ZipEntry;
+}
+
+jarray JNICALL
+Java_java_util_jar_JarFile_getMetaEntriesImpl (JNIEnv * env, jobject recv,
+ jbyteArray zipName)
+{
+#define MAX_PATH 1024
+#define RESULT_BUF_SIZE 256
+
+ PORT_ACCESS_FROM_ENV (env);
+
+ JCLZipFile *jclZipFile;
+ HyZipFile *zipFile;
+ HyZipEntry zipEntry;
+ jobject current;
+ jclass javaClass;
+ jobject resultArray[RESULT_BUF_SIZE];
+ UDATA resultCount = 0, offset, i;
+ void *scanPtr;
+ char metaInfName[10]; /* 10 == strlen("META-INF/") + 1 */
+ const UDATA metaInfSize = 10; /* 10 == strlen("META-INF/") + 1 */
+ jobjectArray result = NULL;
+ char *nameBuf, *newNameBuf, *oldNameBuf = NULL;
+ char startNameBuf[MAX_PATH];
+ UDATA nameBufSize = MAX_PATH;
+ IDATA rc;
+
+ nameBuf = (char *) &startNameBuf;
+
+ jclZipFile =
+ (JCLZipFile *) (IDATA) (*env)->GetLongField (env, recv,
+ JCL_CACHE_GET (env,
+ FID_java_util_zip_ZipFile_descriptor));
+ if (jclZipFile == (void *) -1)
+ {
+ throwNewIllegalStateException (env, "");
+ return NULL;
+ }
+ zipFile = &(jclZipFile->hyZipFile);
+
+ if (zipFile->cache)
+ {
+ if (zipCache_enumNew (zipFile->cache, "META-INF/", &scanPtr))
+ return NULL;
+
+ if (0 !=
+ zipCache_enumGetDirName (scanPtr, (char *) &metaInfName,
+ sizeof (metaInfName)))
+ return NULL;
+
+ for (;;)
+ {
+ rc = zipCache_enumElement (scanPtr, nameBuf, nameBufSize, &offset);
+ if (rc < 0)
+ {
+ break; /* we're done, leave the loop */
+ }
+ else if (rc > 0)
+ {
+ /* the buffer wasn't big enough, grow it */
+ newNameBuf = jclmem_allocate_memory (env, rc);
+ nameBufSize = rc;
+ if (oldNameBuf)
+ {
+ jclmem_free_memory (env, oldNameBuf); /* free old before checking result so we clean up on fail */
+ oldNameBuf = NULL;
+ }
+ if (!newNameBuf)
+ goto cleanup;
+ nameBuf = oldNameBuf = newNameBuf;
+ continue; /* go to the top of the loop again */
+ }
+
+ zip_initZipEntry (PORTLIB, &zipEntry);
+ if (zip_getZipEntryFromOffset (PORTLIB, zipFile, &zipEntry, offset))
+ goto cleanup;
+ current = createZipEntry (env, zipFile, &zipEntry);
+ zip_freeZipEntry (PORTLIB, &zipEntry);
+ if (resultCount == RESULT_BUF_SIZE)
+ goto cleanup; /* fail - should fix. */
+ if (current)
+ resultArray[resultCount++] = current;
+ else
+ goto cleanup;
+ }
+ javaClass = JCL_CACHE_GET (env, CLS_java_util_zip_ZipEntry);
+ result = ((*env)->NewObjectArray (env, resultCount, javaClass, NULL));
+ if (((*env)->ExceptionCheck (env)))
+ {
+ result = NULL;
+ goto cleanup;
+ }
+ for (i = 0; i < resultCount; i++)
+ {
+ (*env)->SetObjectArrayElement (env, result, i, resultArray[i]);
+ }
+ cleanup:
+ zipCache_enumKill (scanPtr);
+ if (oldNameBuf)
+ jclmem_free_memory (env, oldNameBuf); /* free old before checking result so we clean up on fail */
+ return result;
+ }
+ return NULL;
+
+#undef MAX_PATH
+#undef RESULT_BUF_SIZE
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/jclcrc32.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/jclcrc32.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/jclcrc32.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/jclcrc32.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,42 @@
+/* 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 "zconf.h"
+
+uLong crc32 PROTOTYPE ((uLong crc, const Bytef * buf, uInt size));
+
+jlong JNICALL
+Java_java_util_zip_CRC32_updateImpl (JNIEnv * env, jobject recv,
+ jbyteArray buf, int off, int len,
+ jlong crc)
+{
+ jbyte *b;
+ jlong result;
+
+ b = ((*env)->GetPrimitiveArrayCritical (env, buf, 0));
+ if (b == NULL)
+ return -1;
+ result = crc32 ((uLong) crc, (Bytef *) (b + off), (uInt) len);
+ ((*env)->ReleasePrimitiveArrayCritical (env, buf, b, JNI_ABORT));
+ return result;
+}
+
+jlong JNICALL
+Java_java_util_zip_CRC32_updateByteImpl (JNIEnv * env, jobject recv,
+ jbyte val, jlong crc)
+{
+ return crc32 ((uLong) crc, (Bytef *) (&val), 1);
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/jclglob.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/jclglob.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/jclglob.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/jclglob.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,46 @@
+/* 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.
+ */
+
+#if !defined(jclglob_h)
+#define jclglob_h
+
+#include "jcl.h"
+#include "zip.h"
+
+extern void *Archive_JCL_ID_CACHE;
+
+#define JCL_ID_CACHE Archive_JCL_ID_CACHE
+
+typedef struct ArchiveJniIDCache
+{
+ jfieldID FID_java_util_zip_ZipFile_descriptor;
+ jfieldID FID_java_util_zip_ZipFile_nextEntryPointer;
+ jfieldID FID_java_util_zip_Deflater_inRead;
+ jfieldID FID_java_util_zip_Deflater_finished;
+ jfieldID FID_java_util_zip_Inflater_inRead;
+ jfieldID FID_java_util_zip_Inflater_finished;
+ jfieldID FID_java_util_zip_Inflater_needsDictionary;
+ jmethodID MID_java_util_zip_ZipEntry_init;
+
+ jclass CLS_java_util_zip_ZipEntry;
+ JCLZipFileLink *zipfile_handles;
+} ArchiveJniIDCache;
+
+#define JniIDCache ArchiveJniIDCache
+
+/* Now that the module-specific defines are in place, include the shared file */
+#include "libglob.h"
+
+#endif /* jclglob_h */
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/makefile
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/makefile?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/makefile (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/makefile Wed Nov 30 21:29:27 2005
@@ -0,0 +1,70 @@
+# 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.
+
+#
+# Makefile for module 'archive'
+#
+
+include ../makefile.include
+
+DLLFILENAME=libhyarchive.so# declaration
+
+DLLNAME=../libhyarchive.so# declaration
+
+LIBNAME=hyarchive# declaration
+
+LIBPATH=../lib/# declaration
+
+CFLAGS= -fpic -DLINUX -D_REENTRANT -O1 -march=pentium3 -DIPv6_FUNCTION_SUPPORT -DHYX86 -I../include -I../archive -I../common -I../zlib -I../zip -I../fdlibm $(VMDEBUG)
+
+
+.SUFFIXES:.cpp
+.cpp.o:
+ $(CXX) -fpic -DLINUX -D_REENTRANT -O1 -march=pentium3 -fno-exceptions -fno-rtti -DIPv6_FUNCTION_SUPPORT -DHYX86 -I../include -I../archive -I../common -I../zlib -I../zip -I../fdlibm $(VMDEBUG) -c $<
+
+ASFLAGS= -o $@
+
+.SUFFIXES:.asm
+.asm.o:
+ perl ../masm2gas/masm2gas.pl -I../include -I../archive -I../common -I../zlib -I../zip -I../fdlibm $*.asm
+ $(AS) $(ASFLAGS) -o $*.o $*.s
+ -rm $*.s
+
+BUILDFILES1 = archive_copyright.o jclcrc32.o zip.o adler32.o inflater.o
+BUILDFILES2 = jarfile.o deflater.o archiveglob.o
+
+MDLLIBFILES1 = ../libhysig.so ../lib/libhyzip.a ../libhyzlib.so ../lib/libhycommon.a
+MDLLIBFILES2 = ../lib/libhypool.a ../lib/libhyfdlibm.a ../libhythr.so ../libvmi.so
+
+all: \
+ $(DLLNAME)
+
+BUILDLIB: $(DLLNAME)
+
+$(DLLNAME):\
+ $(BUILDFILES1) $(BUILDFILES2) $(MDLLIBFILES1) $(MDLLIBFILES2)
+ $(DLL_LD) -shared -Wl,--version-script,$(LIBNAME).exp -Wl,-soname=$(DLLFILENAME) $(VMLINK) -L. -L../lib -L.. -o $(DLLNAME) \
+ $(BUILDFILES1) $(BUILDFILES2) -Xlinker --start-group \
+ -lhysig \
+ -lhyzip \
+ -lhyzlib \
+ -lhycommon \
+ -lhypool \
+ -lhyfdlibm \
+ -lhythr \
+ -lvmi -Xlinker --end-group -lc -lm -ldl
+
+clean:
+ -rm -f *.o
+ -rm -f ../libhyarchive.so
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/zip.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/zip.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/zip.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/zip.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,461 @@
+/* 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"
+#include "jclprots.h"
+
+#include "zip.h"
+
+void zfree PROTOTYPE ((void *opaque, void *address));
+void *zalloc PROTOTYPE ((void *opaque, U_32 items, U_32 size));
+
+void throwNewOutOfMemoryError (JNIEnv * env, char *message);
+
+/**
+ * Throw java.lang.InternalError
+ */
+void
+throwNewInternalError (JNIEnv * env, char *message)
+{
+ jclass exceptionClass = (*env)->FindClass (env, "java/lang/InternalError");
+ if (0 == exceptionClass)
+ {
+ /* Just return if we can't load the exception class. */
+ return;
+ }
+ (*env)->ThrowNew (env, exceptionClass, message);
+}
+
+/**
+ * Throw java.util.zip.ZipException with the message provided
+ */
+void
+throwJavaZIOException (JNIEnv * env, char *message)
+{
+ jclass exceptionClass =
+ (*env)->FindClass (env, "java/util/zip/ZipException");
+ if (0 == exceptionClass)
+ {
+ /* Just return if we can't load the exception class. */
+ return;
+ }
+ (*env)->ThrowNew (env, exceptionClass, "thrown from C code");
+}
+
+jint JNICALL
+Java_java_util_zip_ZipFile_openZipImpl (JNIEnv * env, jobject recv,
+ jbyteArray zipName)
+{
+ VMI_ACCESS_FROM_ENV (env);
+ PORT_ACCESS_FROM_ENV (env);
+
+ I_32 retval;
+ JCLZipFile *jclZipFile;
+ JCLZipFileLink *zipfileHandles;
+ jsize length;
+ char pathCopy[HyMaxPath];
+ HyZipCachePool *zipCachePool;
+
+ jclZipFile = jclmem_allocate_memory (env, sizeof (*jclZipFile));
+ if (!jclZipFile)
+ return 3;
+
+ length = (*env)->GetArrayLength (env, zipName);
+ length = length < HyMaxPath - 1 ? length : HyMaxPath - 1;
+ ((*env)->GetByteArrayRegion (env, zipName, 0, length, pathCopy));
+ pathCopy[length++] = '\0';
+ ioh_convertToPlatform (pathCopy);
+
+ /* Open the zip file (caching will be managed automatically by zipsup) */
+ zipCachePool = (*VMI)->GetZipCachePool (VMI);
+ retval =
+ zip_openZipFile (privatePortLibrary, pathCopy, &(jclZipFile->hyZipFile),
+ zipCachePool);
+
+ if (retval)
+ {
+ jclmem_free_memory (env, jclZipFile); /* free on fail */
+
+ if (retval == ZIP_ERR_FILE_OPEN_ERROR)
+ return 1;
+ else
+ return 2;
+ }
+
+ /* Add the zipFile we just allocated to the list of zip files -- we will
+ * free this on UnLoad if its not already free'd.
+ */
+ zipfileHandles = JCL_CACHE_GET (env, zipfile_handles);
+ jclZipFile->last = (JCLZipFile *) zipfileHandles;
+ jclZipFile->next = zipfileHandles->next;
+ if (zipfileHandles->next != NULL)
+ zipfileHandles->next->last = jclZipFile;
+ zipfileHandles->next = jclZipFile;
+
+ (*env)->SetLongField (env, recv,
+ JCL_CACHE_GET (env,
+ FID_java_util_zip_ZipFile_descriptor),
+ ((IDATA) jclZipFile));
+ return 0;
+}
+
+jobject JNICALL
+Java_java_util_zip_ZipFile_getEntryImpl (JNIEnv * env, jobject recv,
+ jlong zipPointer, jstring entryName)
+{
+ PORT_ACCESS_FROM_ENV (env);
+
+ I_32 retval;
+ HyZipFile *zipFile;
+ HyZipEntry zipEntry;
+ jobject java_ZipEntry, extra;
+ jclass entryClass;
+ jmethodID mid;
+ const char *entryCopy;
+ JCLZipFile *jclZipFile = (JCLZipFile *) (IDATA) zipPointer;
+
+ if (jclZipFile == (void *) -1)
+ {
+ throwNewIllegalStateException (env, "");
+ return NULL;
+ }
+ zipFile = &(jclZipFile->hyZipFile);
+ entryCopy = (*env)->GetStringUTFChars (env, entryName, NULL);
+ if (entryCopy == NULL)
+ return (jobject) NULL;
+
+ zip_initZipEntry (PORTLIB, &zipEntry);
+ retval = zip_getZipEntry (PORTLIB, zipFile, &zipEntry, entryCopy, TRUE);
+ (*env)->ReleaseStringUTFChars (env, entryName, entryCopy);
+ if (retval)
+ {
+ zip_freeZipEntry (PORTLIB, &zipEntry);
+ return (jobject) NULL;
+ }
+
+ extra = NULL;
+ if (zipEntry.extraFieldLength > 0)
+ {
+ zip_getZipEntryExtraField (PORTLIB, zipFile, &zipEntry, NULL,
+ zipEntry.extraFieldLength);
+ if (zipEntry.extraField == NULL)
+ {
+ zip_freeZipEntry (PORTLIB, &zipEntry);
+ return (jobject) NULL;
+ }
+ extra = ((*env)->NewByteArray (env, zipEntry.extraFieldLength));
+ if (((*env)->ExceptionCheck (env)))
+ {
+ zip_freeZipEntry (PORTLIB, &zipEntry);
+ return (jobject) NULL;
+ }
+ ((*env)->
+ SetByteArrayRegion (env, extra, 0, zipEntry.extraFieldLength,
+ zipEntry.extraField));
+ }
+
+ entryClass = JCL_CACHE_GET (env, CLS_java_util_zip_ZipEntry);
+ mid = JCL_CACHE_GET (env, MID_java_util_zip_ZipEntry_init);
+ /* Build a new ZipEntry from the C struct */
+ java_ZipEntry = ((*env)->NewObject (env, entryClass, mid, entryName, NULL, /* comment */
+ extra,
+ (jlong) zipEntry.lastModTime,
+ (jlong) zipEntry.uncompressedSize,
+ (jlong) zipEntry.compressedSize,
+ (jlong) zipEntry.crc32,
+ zipEntry.compressionMethod,
+ (jlong) zipEntry.lastModDate,
+ (jlong) zipEntry.dataPointer));
+ zip_freeZipEntry (PORTLIB, &zipEntry);
+ return java_ZipEntry;
+}
+
+void JNICALL
+Java_java_util_zip_ZipFile_closeZipImpl (JNIEnv * env, jobject recv)
+{
+ PORT_ACCESS_FROM_ENV (env);
+
+ I_32 retval = 0;
+ JCLZipFile *jclZipFile;
+ jfieldID descriptorFID =
+ JCL_CACHE_GET (env, FID_java_util_zip_ZipFile_descriptor);
+
+ jclZipFile =
+ (JCLZipFile *) (IDATA) (*env)->GetLongField (env, recv, descriptorFID);
+ if (jclZipFile != (void *) -1)
+ {
+ retval =
+ zip_closeZipFile (privatePortLibrary, &(jclZipFile->hyZipFile));
+ (*env)->SetLongField (env, recv, descriptorFID, -1);
+
+ /* Free the zip struct */
+ if (jclZipFile->last != NULL)
+ jclZipFile->last->next = jclZipFile->next;
+ if (jclZipFile->next != NULL)
+ jclZipFile->next->last = jclZipFile->last;
+
+ jclmem_free_memory (env, jclZipFile);
+ if (retval)
+ {
+ throwJavaZIOException (env, "");
+ return;
+ }
+ }
+}
+
+/**
+ * Throw java.lang.IllegalStateException
+ */
+void
+throwNewIllegalStateException (JNIEnv * env, char *message)
+{
+ jclass exceptionClass =
+ (*env)->FindClass (env, "java/lang/IllegalStateException");
+ if (0 == exceptionClass)
+ {
+ /* Just return if we can't load the exception class. */
+ return;
+ }
+ (*env)->ThrowNew (env, exceptionClass, message);
+}
+
+/**
+ * Throw java.lang.IllegalArgumentException
+ */
+void
+throwNewIllegalArgumentException (JNIEnv * env, char *message)
+{
+ jclass exceptionClass =
+ (*env)->FindClass (env, "java/lang/IllegalArgumentException");
+ if (0 == exceptionClass)
+ {
+ /* Just return if we can't load the exception class. */
+ return;
+ }
+ (*env)->ThrowNew (env, exceptionClass, message);
+}
+
+void JNICALL
+Java_java_util_zip_ZipFile_ntvinit (JNIEnv * env, jclass cls)
+{
+ PORT_ACCESS_FROM_ENV (env);
+ jmethodID mid;
+ jfieldID descriptorFID;
+ jclass javaClass;
+ JCLZipFileLink *zipfileHandles;
+
+ javaClass = (*env)->FindClass (env, "java/util/zip/ZipEntry");
+ javaClass = (*env)->NewWeakGlobalRef (env, javaClass);
+ if (!javaClass)
+ return;
+ mid =
+ ((*env)->
+ GetMethodID (env, javaClass, "<init>",
+ "(Ljava/lang/String;Ljava/lang/String;[BJJJJIJJ)V"));
+ if (!mid)
+ return;
+ JCL_CACHE_SET (env, CLS_java_util_zip_ZipEntry, javaClass);
+ JCL_CACHE_SET (env, MID_java_util_zip_ZipEntry_init, mid);
+
+ descriptorFID = (*env)->GetFieldID (env, cls, "descriptor", "J");
+ if (!descriptorFID)
+ return;
+ JCL_CACHE_SET (env, FID_java_util_zip_ZipFile_descriptor, descriptorFID);
+
+ javaClass = (*env)->FindClass (env, "java/util/zip/ZipFile$ZFEnum");
+ if (!javaClass)
+ return;
+ descriptorFID =
+ (*env)->GetFieldID (env, javaClass, "nextEntryPointer", "J");
+ if (!descriptorFID)
+ return;
+ JCL_CACHE_SET (env, FID_java_util_zip_ZipFile_nextEntryPointer,
+ descriptorFID);
+
+ zipfileHandles = jclmem_allocate_memory (env, sizeof (JCLZipFileLink));
+ if (!zipfileHandles)
+ return;
+ zipfileHandles->last = NULL;
+ zipfileHandles->next = NULL;
+ JCL_CACHE_SET (env, zipfile_handles, zipfileHandles);
+}
+
+jlong JNICALL
+Java_java_util_zip_ZipFile_00024ZFEnum_resetZip (JNIEnv * env, jobject recv,
+ jlong descriptor)
+{
+ PORT_ACCESS_FROM_ENV (env);
+
+ IDATA nextEntryPointer;
+ JCLZipFile *jclZipFile = (JCLZipFile *) (IDATA) descriptor;
+
+ if (jclZipFile == (void *) -1)
+ {
+ throwNewIllegalStateException (env, "");
+ return 0;
+ }
+ zip_resetZipFile (privatePortLibrary,
+ &(jclZipFile->hyZipFile), &nextEntryPointer);
+ return nextEntryPointer;
+}
+
+jobject JNICALL
+Java_java_util_zip_ZipFile_00024ZFEnum_getNextEntry (JNIEnv * env,
+ jobject recv,
+ jlong descriptor,
+ jlong nextEntry)
+{
+ PORT_ACCESS_FROM_ENV (env);
+
+ I_32 retval;
+ HyZipFile *zipFile;
+ HyZipEntry zipEntry;
+ jobject java_ZipEntry, extra;
+ jclass javaClass;
+ jmethodID mid;
+ jstring entryName = NULL;
+ IDATA nextEntryPointer;
+ JCLZipFile *jclZipFile = (JCLZipFile *) (IDATA) descriptor;
+
+ if (jclZipFile == (void *) -1)
+ {
+ throwNewIllegalStateException (env, "");
+ return NULL;
+ }
+ zipFile = &(jclZipFile->hyZipFile);
+ zip_initZipEntry (PORTLIB, &zipEntry);
+
+ nextEntryPointer = (IDATA) nextEntry;
+ retval =
+ zip_getNextZipEntry (PORTLIB, zipFile, &zipEntry, &nextEntryPointer);
+ if (retval)
+ {
+ if (retval != ZIP_ERR_NO_MORE_ENTRIES)
+ {
+ char buf[40];
+ sprintf (buf, "Error %d getting next zip entry", retval);
+ /* Cannot throw IOException (or subclasses) */
+ throwNewInternalError (env, buf);
+ }
+ return (jobject) NULL;
+ }
+
+ /* Build a new ZipEntry from the C struct */
+ entryName = ((*env)->NewStringUTF (env, zipEntry.filename));
+
+ if (((*env)->ExceptionCheck (env)))
+ return NULL;
+
+ extra = NULL;
+ if (zipEntry.extraFieldLength > 0)
+ {
+ zip_getZipEntryExtraField (PORTLIB, zipFile, &zipEntry, NULL,
+ zipEntry.extraFieldLength);
+ extra = ((*env)->NewByteArray (env, zipEntry.extraFieldLength));
+ if (((*env)->ExceptionCheck (env)))
+ {
+ /* free the extraField entry */
+ zip_freeZipEntry (PORTLIB, &zipEntry);
+ return NULL;
+ }
+ ((*env)->
+ SetByteArrayRegion (env, extra, 0, zipEntry.extraFieldLength,
+ zipEntry.extraField));
+ jclmem_free_memory (env, zipEntry.extraField);
+ zipEntry.extraField = NULL;
+ }
+
+ javaClass = JCL_CACHE_GET (env, CLS_java_util_zip_ZipEntry);
+ mid = JCL_CACHE_GET (env, MID_java_util_zip_ZipEntry_init);
+ java_ZipEntry = ((*env)->NewObject (env, javaClass, mid, entryName, NULL, /* comment */
+ extra,
+ (jlong) zipEntry.lastModTime,
+ (jlong) zipEntry.uncompressedSize,
+ (jlong) zipEntry.compressedSize,
+ (jlong) zipEntry.crc32,
+ zipEntry.compressionMethod,
+ (jlong) zipEntry.lastModDate,
+ (jlong) zipEntry.dataPointer));
+ zip_freeZipEntry (PORTLIB, &zipEntry);
+ (*env)->SetLongField (env, recv,
+ JCL_CACHE_GET (env,
+ FID_java_util_zip_ZipFile_nextEntryPointer),
+ nextEntryPointer);
+ return java_ZipEntry;
+}
+
+jbyteArray JNICALL
+Java_java_util_zip_ZipFile_inflateEntryImpl2 (JNIEnv * env, jobject recv,
+ jlong descriptor,
+ jstring entryName)
+{
+
+ PORT_ACCESS_FROM_ENV (env);
+
+ I_32 retval;
+ HyZipFile *zipFile;
+ HyZipEntry zipEntry;
+ const char *entryCopy;
+ jbyteArray buf;
+ JCLZipFile *jclZipFile = (JCLZipFile *) (IDATA) descriptor;
+
+ /* Build the zipFile */
+ if (jclZipFile == (void *) -1)
+ {
+ throwNewIllegalStateException (env, "");
+ return NULL;
+ }
+ zipFile = &(jclZipFile->hyZipFile);
+ entryCopy = (*env)->GetStringUTFChars (env, entryName, NULL);
+ if (entryCopy == NULL)
+ return NULL;
+
+ zip_initZipEntry (privatePortLibrary, &zipEntry);
+ retval =
+ zip_getZipEntry (privatePortLibrary, zipFile, &zipEntry, entryCopy, TRUE);
+ (*env)->ReleaseStringUTFChars (env, entryName, entryCopy);
+ if (retval)
+ {
+ zip_freeZipEntry (privatePortLibrary, &zipEntry);
+ if (retval == ZIP_ERR_OUT_OF_MEMORY)
+ throwNewOutOfMemoryError (env, "");
+ return NULL;
+ }
+
+ buf = (*env)->NewByteArray (env, zipEntry.uncompressedSize);
+ if (!buf)
+ {
+ throwNewOutOfMemoryError (env, "");
+ return NULL;
+ }
+
+ retval =
+ zip_getZipEntryData (privatePortLibrary, zipFile, &zipEntry, NULL,
+ zipEntry.uncompressedSize);
+ if (retval == 0)
+ (*env)->SetByteArrayRegion (env, buf, 0, zipEntry.uncompressedSize,
+ zipEntry.data);
+ zip_freeZipEntry (privatePortLibrary, &zipEntry);
+ if (!retval)
+ return buf;
+
+ if (retval == ZIP_ERR_OUT_OF_MEMORY)
+ throwNewOutOfMemoryError (env, "");
+ else
+ throwJavaZIOException (env, "");
+
+ return NULL;
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/zip.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/zip.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/zip.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/archive/zip.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,35 @@
+/* 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(zip_h)
+#define zip_h
+
+#include "zipsup.h"
+
+typedef struct JCLZipFile
+{
+ struct JCLZipFile *last;
+ struct JCLZipFile *next;
+ HyZipFile hyZipFile;
+} JCLZipFile;
+
+/* Fake JCLZipFile entry. last, next must be in the same position as JCLZipFile */
+typedef struct JCLZipFileLink
+{
+ JCLZipFile *last;
+ JCLZipFile *next;
+} JCLZipFileLink;
+
+#endif /* zip_h */
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/iohelp.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/iohelp.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/iohelp.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/iohelp.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,524 @@
+/* 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"
+
+jfieldID getJavaIoFileDescriptorDescriptorFID (JNIEnv * env);
+
+/**
+ * Throw java.io.IOException with the message provided
+ */
+void
+throwJavaIoIOException (JNIEnv * env, char *message)
+{
+ jclass exceptionClass = (*env)->FindClass(env, "java/io/IOException");
+ if (0 == exceptionClass) {
+ /* Just return if we can't load the exception class. */
+ return;
+ }
+ (*env)->ThrowNew(env, exceptionClass, message);
+}
+
+/**
+ * This will convert all separators to the proper platform separator
+ * and remove duplicates on non POSIX platforms.
+ */
+void
+ioh_convertToPlatform (char *path)
+{
+ char *pathIndex;
+ int length = strlen (path);
+
+ /* Convert all separators to the same type */
+ pathIndex = path;
+ while (*pathIndex != '\0')
+ {
+ if ((*pathIndex == '\\' || *pathIndex == '/')
+ && (*pathIndex != jclSeparator))
+ *pathIndex = jclSeparator;
+ pathIndex++;
+ }
+
+ /* Remove duplicate separators */
+ if (jclSeparator == '/')
+ return; /* Do not do POSIX platforms */
+
+ /* Remove duplicate initial separators */
+ pathIndex = path;
+ while ((*pathIndex != '\0') && (*pathIndex == jclSeparator))
+ {
+ pathIndex++;
+ }
+ if ((pathIndex > path) && (length > (pathIndex - path))
+ && (*(pathIndex + 1) == ':'))
+ {
+ /* For Example '////c:/*' */
+ int newlen = length - (pathIndex - path);
+ memmove (path, pathIndex, newlen);
+ path[newlen] = '\0';
+ }
+ else
+ {
+ if ((pathIndex - path > 3) && (length > (pathIndex - path)))
+ {
+ /* For Example '////serverName/*' */
+ int newlen = length - (pathIndex - path) + 2;
+ memmove (path, pathIndex - 2, newlen);
+ path[newlen] = '\0';
+ }
+ }
+ /* This will have to handle extra \'s but currently doesn't */
+
+}
+
+/**
+ * Throw java.io.IOException with the "File closed" message
+ * Consolidate all through here so message is consistent.
+ */
+void
+throwJavaIoIOExceptionClosed (JNIEnv * env)
+{
+ throwJavaIoIOException (env, "File closed");
+}
+
+/**
+ * Throw java.lang.IndexOutOfBoundsException
+ */
+void
+throwIndexOutOfBoundsException (JNIEnv * env)
+{
+ jclass exceptionClass = (*env)->FindClass(env, "java/lang/IndexOutOfBoundsException");
+ if (0 == exceptionClass) {
+ /* Just return if we can't load the exception class. */
+ return;
+ }
+ (*env)->ThrowNew(env, exceptionClass, "");
+}
+
+/**
+ * This will write count bytes from buffer starting at offset
+ */
+void
+ioh_writebytesImpl (JNIEnv * env, jobject recv, jbyteArray buffer,
+ jint offset, jint count, IDATA descriptor)
+{
+ I_32 result = 0;
+ jbyte *buf;
+ PORT_ACCESS_FROM_ENV (env);
+ jsize len;
+ char *errorMessage;
+
+/* TODO: ARRAY PINNING */
+#define INTERNAL_MAX 512
+ U_8 internalBuffer[INTERNAL_MAX];
+
+ if (buffer == NULL)
+ {
+ throwNPException (env, "buffer is null");
+ return;
+ }
+
+ len = (*env)->GetArrayLength (env, buffer);
+
+ /**
+ * If offset is negative, or count is negative, or offset+count is greater
+ * than the length of the array b, then an IndexOutOfBoundsException is thrown.
+ * Must test offset > len, or len - offset < count to avoid int overflow caused
+ * by offset + count
+ */
+ if (offset < 0 || count < 0 || offset > len || (len - offset) < count)
+ {
+ throwIndexOutOfBoundsException (env);
+ return;
+ }
+
+ /* If len or count is zero, just return 0 */
+ if (len == 0 || count == 0)
+ return;
+
+ if (descriptor == -1)
+ {
+ throwJavaIoIOExceptionClosed (env);
+ return;
+ }
+ if (count > INTERNAL_MAX)
+ {
+ buf = jclmem_allocate_memory (env, count);
+ }
+ else
+ {
+ buf = internalBuffer;
+ }
+
+ if (buf == NULL)
+ {
+ throwNewOutOfMemoryError (env, "");
+ return;
+ }
+ ((*env)->GetByteArrayRegion (env, buffer, offset, count, buf));
+
+ result = hyfile_write (descriptor, buf, count);
+
+ /**
+ * if there is an error, find the error message before calling free in case
+ * hymem_free_memory changes the error code
+ */
+ if (result < 0)
+ errorMessage = ioLookupErrorString (env, result);
+
+ if (buf != (jbyte*)internalBuffer)
+ {
+ jclmem_free_memory (env, buf);
+ }
+#undef INTERNAL_MAX
+
+ if (result < 0)
+ throwJavaIoIOException (env, errorMessage);
+}
+
+/**
+ * This will write one byte
+ */
+void
+ioh_writecharImpl (JNIEnv * env, jobject recv, jint c, IDATA descriptor)
+{
+ I_32 result = 0;
+ char buf[1];
+ PORT_ACCESS_FROM_ENV (env);
+
+ if (descriptor == -1)
+ {
+ throwJavaIoIOExceptionClosed (env);
+ return;
+ }
+
+ buf[0] = (char) c;
+
+ result = hyfile_write (descriptor, buf, 1);
+
+ if (result < 0)
+ throwJavaIoIOException (env, ioLookupErrorString (env, result));
+}
+
+/**
+ * This will read a single character from the descriptor
+ */
+jint
+ioh_readcharImpl (JNIEnv * env, jobject recv, IDATA descriptor)
+{
+ I_32 result;
+ char buf[1];
+ PORT_ACCESS_FROM_ENV (env);
+
+ if (descriptor == -1)
+ {
+ throwJavaIoIOExceptionClosed (env);
+ return 0;
+ }
+
+ if (descriptor == 0)
+ {
+ result = hytty_get_chars (buf, 1);
+ }
+ else
+ {
+ result = hyfile_read (descriptor, buf, 1);
+ }
+
+ if (result <= 0)
+ return -1;
+
+ return (jint) buf[0] & 0xFF;
+}
+
+/**
+ * This will read a up to count bytes into buffer starting at offset
+ */
+jint
+ioh_readbytesImpl (JNIEnv * env, jobject recv, jbyteArray buffer, jint offset,
+ jint count, IDATA descriptor)
+{
+ I_32 result;
+ jsize len;
+ jbyte *buf;
+
+/* TODO: ARRAY PINNING */
+#define INTERNAL_MAX 2048
+ U_8 internalBuffer[INTERNAL_MAX];
+
+ PORT_ACCESS_FROM_ENV (env);
+
+ if (buffer == NULL)
+ {
+ throwNPException (env, "buffer is null");
+ return 0;
+ }
+
+ len = (*env)->GetArrayLength (env, buffer);
+ /**
+ * Throw IndexOutOfBoundsException according to spec.
+ * Must test offset > len, or len - offset < count to avoid
+ * int overflow caused by offset + count
+ */
+ if (offset < 0 || count < 0 || offset > len || (len - offset) < count)
+ {
+ throwIndexOutOfBoundsException (env);
+ return 0;
+ }
+ /* If len is 0, simply return 0 (even if it is closed) */
+ if (len == 0 || count == 0)
+ return 0;
+
+ if (descriptor == -1)
+ {
+ throwJavaIoIOExceptionClosed (env);
+ return 0;
+ }
+ if (len >= INTERNAL_MAX)
+ {
+ buf = jclmem_allocate_memory (env, len);
+ }
+ else
+ {
+ buf = internalBuffer;
+ }
+
+ if (buf == NULL)
+ {
+ throwNewOutOfMemoryError (env, "");
+ return 0;
+ }
+ /* Must FREE buffer before returning */
+
+ if (descriptor == 0)
+ {
+ /* hytty_get_chars() returns zero on EOF */
+ if ((result = hytty_get_chars (buf, count)) == 0)
+ result = -1;
+ }
+ else
+ {
+ result = hyfile_read (descriptor, buf, count);
+ }
+ if (result > 0)
+ (*env)->SetByteArrayRegion (env, buffer, offset, result, buf);
+
+ if (buf != (jbyte*)internalBuffer)
+ {
+ jclmem_free_memory (env, buf);
+ }
+#undef INTERNAL_MAX
+
+ return result;
+}
+
+/**
+ * Throw java.lang.NullPointerException with the message provided
+ * Note: This is not names throwNullPointerException because is conflicts
+ * with a VM function of that same name and this causes problems on
+ * some platforms.
+ */
+void
+throwNPException (JNIEnv * env, char *message)
+{
+ jclass exceptionClass = (*env)->FindClass(env, "java/lang/NullPointerException");
+ if (0 == exceptionClass) {
+ /* Just return if we can't load the exception class. */
+ return;
+ }
+ (*env)->ThrowNew(env, exceptionClass, message);
+}
+
+/**
+ * This will return the number of chars left in the file
+ */
+jint
+new_ioh_available (JNIEnv * env, jobject recv, jfieldID fdFID)
+{
+ jobject fd;
+ I_64 currentPosition, endOfFile;
+ IDATA descriptor;
+ PORT_ACCESS_FROM_ENV (env);
+
+ /* fetch the fd field from the object */
+ fd = (*env)->GetObjectField (env, recv, fdFID);
+
+ /* dereference the C pointer from the wrapper object */
+ descriptor = (IDATA) getJavaIoFileDescriptorContentsAsPointer (env, fd);
+ if (descriptor == -1)
+ {
+ throwJavaIoIOExceptionClosed (env);
+ return -1;
+ }
+ /**
+ * If the descriptor represents StdIn, call the hytty port library.
+ */
+ if (descriptor == 0)
+ {
+ return hytty_available ();
+ }
+ currentPosition = hyfile_seek (descriptor, 0, HySeekCur);
+ endOfFile = hyfile_seek (descriptor, 0, HySeekEnd);
+ hyfile_seek (descriptor, currentPosition, HySeekSet);
+ return (jint) (endOfFile - currentPosition);
+}
+
+/**
+ * This will close a file descriptor
+ */
+void
+new_ioh_close (JNIEnv * env, jobject recv, jfieldID fdFID)
+{
+ jobject fd;
+ jfieldID descriptorFID;
+ IDATA descriptor;
+ PORT_ACCESS_FROM_ENV (env);
+
+ descriptorFID = getJavaIoFileDescriptorDescriptorFID (env);
+ if (NULL == descriptorFID)
+ {
+ return;
+ }
+
+ /* fetch the fd field from the object */
+ fd = (*env)->GetObjectField (env, recv, fdFID);
+
+ /* dereference the C pointer from the wrapper object */
+ descriptor = (IDATA) getJavaIoFileDescriptorContentsAsPointer (env, fd);
+
+ /* Check for closed file, in, out, and err */
+ if (descriptor >= -1 && descriptor <= 2)
+ return;
+
+ hyfile_close (descriptor);
+ setJavaIoFileDescriptorContentsAsPointer (env, fd, (void *) -1);
+ return;
+}
+
+/**
+ * This will retrieve the 'descriptor' field value from a java.io.FileDescriptor
+ */
+void *
+getJavaIoFileDescriptorContentsAsPointer (JNIEnv * env, jobject fd)
+{
+ jfieldID descriptorFID = getJavaIoFileDescriptorDescriptorFID (env);
+ if (NULL == descriptorFID)
+ {
+ return (void *) -1;
+ }
+ return (void *)(IDATA) ((*env)->GetLongField (env, fd, descriptorFID));
+}
+
+/**
+ * This will set the 'descriptor' field value in the java.io.FileDescriptor
+ * @fd to the value @desc
+ */
+void
+setJavaIoFileDescriptorContentsAsPointer (JNIEnv * env, jobject fd,
+ void *value)
+{
+ jfieldID fid = getJavaIoFileDescriptorDescriptorFID (env);
+ if (NULL != fid)
+ {
+ (*env)->SetLongField (env, fd, fid, (IDATA)value);
+ }
+}
+
+/**
+ * Throw java.lang.OutOfMemoryError
+ */
+void
+throwNewOutOfMemoryError (JNIEnv * env, char *message)
+{
+ jclass exceptionClass = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
+ if (0 == exceptionClass) {
+ /* Just return if we can't load the exception class. */
+ return;
+ }
+ (*env)->ThrowNew(env, exceptionClass, message);
+}
+
+/**
+ * Answer the errorString corresponding to the errorNumber, if available.
+ * This function will answer a default error string, if the errorNumber is not
+ * recognized.
+ *
+ * This function will have to be reworked to handle internationalization properly, removing
+ * the explicit strings.
+ *
+ * @param anErrorNum the error code to resolve to a human readable string
+ *
+ * @return a human readable error string
+ */
+
+char *
+ioLookupErrorString (JNIEnv * env, I_32 anErrorNum)
+{
+ PORT_ACCESS_FROM_ENV (env);
+ switch (anErrorNum)
+ {
+ case HYPORT_ERROR_FILE_NOTFOUND:
+ return "File not found";
+ case HYPORT_ERROR_FILE_NOPERMISSION:
+ return "Lacking proper permissions to perform the operation";
+ case HYPORT_ERROR_FILE_DISKFULL:
+ return "Disk is full";
+ case HYPORT_ERROR_FILE_NOENT:
+ return "A component of the path name does not exist";
+ case HYPORT_ERROR_FILE_NOTDIR:
+ return "A component of the path name is not a directory";
+ case HYPORT_ERROR_FILE_BADF:
+ return "File descriptor invalid";
+ case HYPORT_ERROR_FILE_EXIST:
+ return "File already exists";
+ case HYPORT_ERROR_FILE_INVAL:
+ return "a parameter is invalid";
+ case HYPORT_ERROR_FILE_LOOP:
+ return "Followed too many symbolic links, possibly stuck in loop";
+ case HYPORT_ERROR_FILE_NAMETOOLONG:
+ return "Filename exceeds maximum length";
+ default:
+ return (char *) hyfile_error_message ();
+ }
+}
+
+/**
+ * This will retrieve the 'descriptor' field value from a java.io.FileDescriptor
+ */
+jfieldID
+getJavaIoFileDescriptorDescriptorFID (JNIEnv * env)
+{
+ jclass descriptorCLS;
+ jfieldID descriptorFID;
+
+ descriptorFID = JCL_CACHE_GET (env, FID_java_io_FileDescriptor_descriptor);
+ if (NULL != descriptorFID)
+ {
+ return descriptorFID;
+ }
+ descriptorCLS = (*env)->FindClass (env, "java/io/FileDescriptor");
+ if (NULL == descriptorCLS)
+ {
+ return NULL;
+ }
+ descriptorFID = (*env)->GetFieldID (env, descriptorCLS, "descriptor", "J");
+ if (NULL == descriptorFID)
+ {
+ return NULL;
+ }
+ JCL_CACHE_SET (env, FID_java_io_FileDescriptor_descriptor, descriptorFID);
+ return descriptorFID;
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/iohelp.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/iohelp.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/iohelp.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/iohelp.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,40 @@
+/* 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(iohelp_h)
+#define iohelp_h
+#include <string.h>
+#include "jcl.h"
+/* DIR_SEPARATOR is defined in hycomp.h */
+#define jclSeparator DIR_SEPARATOR
+void *getJavaIoFileDescriptorContentsAsPointer (JNIEnv * env, jobject fd);
+void throwNewOutOfMemoryError (JNIEnv * env, char *message);
+jint ioh_readcharImpl (JNIEnv * env, jobject recv, IDATA descriptor);
+void throwJavaIoIOException (JNIEnv * env, char *message);
+void throwJavaIoIOExceptionClosed (JNIEnv * env);
+void ioh_convertToPlatform (char *path);
+jint new_ioh_available (JNIEnv * env, jobject recv, jfieldID fdFID);
+void throwNPException (JNIEnv * env, char *message);
+void setJavaIoFileDescriptorContentsAsPointer (JNIEnv * env, jobject fd,
+ void *value);
+void ioh_writebytesImpl (JNIEnv * env, jobject recv, jbyteArray buffer,
+ jint offset, jint count, IDATA descriptor);
+char *ioLookupErrorString (JNIEnv * env, I_32 anErrorNum);
+void ioh_writecharImpl (JNIEnv * env, jobject recv, jint c, IDATA descriptor);
+jint ioh_readbytesImpl (JNIEnv * env, jobject recv, jbyteArray buffer,
+ jint offset, jint count, IDATA descriptor);
+void new_ioh_close (JNIEnv * env, jobject recv, jfieldID fdFID);
+void throwIndexOutOfBoundsException (JNIEnv * env);
+#endif /* iohelp_h */
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/jcl.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/jcl.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/jcl.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/jcl.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,20 @@
+/* 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.
+ */
+
+#if !defined(jcl_h)
+#define jcl_h
+#define USING_VMI
+#include "vmi.h"
+#endif /* jcl_h */
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/jclglob.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/jclglob.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/jclglob.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/jclglob.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,30 @@
+/* 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.
+ */
+
+#if !defined(jclglob_h)
+#define jclglob_h
+#include "jcl.h"
+extern void *Lib_JCL_ID_CACHE;
+#define JCL_ID_CACHE Lib_JCL_ID_CACHE
+typedef struct LibJniIDCache
+{
+
+ jfieldID FID_java_io_FileDescriptor_descriptor;
+ int attachCount;
+} LibJniIDCache;
+#define JniIDCache LibJniIDCache
+/* Now that the module-specific defines are in place, include the shared file */
+#include "libglob.h"
+#endif /* jclglob_h */
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/libglob.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/libglob.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/libglob.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/libglob.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,114 @@
+/* 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.
+ */
+
+/* HarmonyDoxygen */
+/**
+ * @file
+ * @ingroup HarmonyNatives
+ * @brief Harmony Common helpers initialization API.
+ */
+
+#include "jcl.h"
+#include "jclglob.h"
+
+static UDATA keyInitCount = 0;
+
+void *JCL_ID_CACHE = NULL;
+
+static void freeReferences (JNIEnv * env);
+
+/**
+ * A DLL is attaching to the common code, do any initialization required.
+ * This may be called more than once.
+ */
+jint JNICALL
+ClearLibAttach (JNIEnv * env)
+{
+ void *keyInitCountPtr = GLOBAL_DATA (keyInitCount);
+ void **jclIdCache = GLOBAL_DATA (JCL_ID_CACHE);
+ JniIDCache *idCache;
+
+ PORT_ACCESS_FROM_ENV (env);
+
+ if (HY_VMLS_FNTBL (env)->
+ HYVMLSAllocKeys (env, keyInitCountPtr, jclIdCache, NULL))
+ {
+ goto fail;
+ }
+
+ idCache = (JniIDCache *) HY_VMLS_GET (env, *jclIdCache);
+ if (idCache == NULL)
+ {
+
+ /* This allocate must actually be done by hymem_allocate_memory. */
+ idCache = (JniIDCache *) hymem_allocate_memory (sizeof (JniIDCache));
+ if (!idCache)
+ goto fail2;
+
+ memset (idCache, 0, sizeof (JniIDCache));
+ HY_VMLS_SET (env, *jclIdCache, idCache);
+ }
+
+ /* Increment the reference count. */
+ idCache->attachCount++;
+
+ return JNI_OK;
+
+fail2:
+ HY_VMLS_FNTBL (env)->HYVMLSFreeKeys (env, keyInitCountPtr, jclIdCache, NULL);
+fail:
+ return JNI_ERR;
+}
+
+/**
+ * A DLL is detaching from the common code, do any clean up required.
+ * This may be called more than once!!
+ */
+void JNICALL
+ClearLibDetach (JNIEnv * env)
+{
+ void *keyInitCountPtr = GLOBAL_DATA (keyInitCount);
+ void **jclIdCache = GLOBAL_DATA (JCL_ID_CACHE);
+ JniIDCache *idCache;
+
+ PORT_ACCESS_FROM_ENV (env);
+
+ idCache = (JniIDCache *) HY_VMLS_GET (env, *jclIdCache);
+ if (idCache)
+ {
+
+ /* Decrement the reference count and free if necessary. */
+ if (--idCache->attachCount < 1)
+ {
+
+ /* Had to move some of the code out of this function to get the IBM C compiler to generate a valid DLL */
+ freeReferences (env);
+
+ /* Free VMLS keys */
+ idCache = (JniIDCache *) HY_VMLS_GET (env, *jclIdCache);
+ HY_VMLS_FNTBL (env)->HYVMLSFreeKeys (env, keyInitCountPtr,
+ jclIdCache, NULL);
+ hymem_free_memory (idCache);
+ }
+ }
+}
+
+/**
+ * @internal
+ */
+static void
+freeReferences (JNIEnv * env)
+{
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/libglob.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/libglob.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/libglob.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/libglob.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,30 @@
+/* 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.
+ */
+
+#if !defined(libglob_h)
+#define libglob_h
+#include "jcl.h"
+#include "hyvmls.h"
+#define JCL_CACHE_GET(env,x) \
+ (((JniIDCache*) HY_VMLS_GET((env), JCL_ID_CACHE))->x)
+#define JCL_CACHE_SET(env,x,v) \
+ (((JniIDCache*) HY_VMLS_GET((env), JCL_ID_CACHE))->x = (v))
+#define jclmem_allocate_memory(env, byteAmount) \
+ hymem_allocate_memory(byteAmount)
+#define jclmem_free_memory(env, buf) \
+ hymem_free_memory(buf)
+jint JNICALL ClearLibAttach (JNIEnv * env);
+void JNICALL ClearLibDetach (JNIEnv * env);
+#endif /* libglob_h */
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/makefile
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/makefile?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/makefile (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/makefile Wed Nov 30 21:29:27 2005
@@ -0,0 +1,56 @@
+# 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.
+
+#
+# Makefile for module 'common'
+#
+
+include ../makefile.include
+
+LIBNAME=libhycommon.a# declaration
+
+LIBPATH=../lib/# declaration
+
+BUILDFILES1 = libglob.o iohelp.o utf8encode.o utf8decode.o
+
+MDLLIBFILES1 = ../libjsig.so ../lib/libhyzip.a ../libhyzlib23.so ../lib/libhycommon.a ../lib/libhypool.a
+MDLLIBFILES2 = ../lib/libhyfdlibm.a ../libhythr23.so ../libvmi.so
+
+CFLAGS= -DLINUX -D_REENTRANT -O1 -march=pentium3 -DIPv6_FUNCTION_SUPPORT -DHYX86 -I../include -I../common -I../zlib -I../zip -I../fdlibm $(VMDEBUG)
+
+.SUFFIXES:.cpp
+.cpp.o:
+ $(CXX) -DLINUX -D_REENTRANT -O1 -march=pentium3 -fno-exceptions -fno-rtti -DIPv6_FUNCTION_SUPPORT -DHYX86 -I../include -I../common -I../zlib -I../zip -I../fdlibm $(VMDEBUG) -c $<
+
+ASFLAGS= -o $@
+
+.SUFFIXES:.asm
+.asm.o:
+ perl ../masm2gas/masm2gas.pl -I../include -I../common -I../zlib -I../zip -I../fdlibm $*.asm
+ $(AS) $(ASFLAGS) -o $*.o $*.s
+ -rm $*.s
+
+all: $(LIBPATH)$(LIBNAME)
+
+$(LIBPATH)$(LIBNAME):\
+ $(BUILDFILES1)
+ $(AR) rcv $(LIBPATH)$(LIBNAME) \
+ $(BUILDFILES1)
+
+quick:
+ $(MAKE)
+
+clean:
+ -rm -f *.o
+ -rm -f ../lib/libhycommon.a
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/utf8decode.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/utf8decode.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/utf8decode.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/utf8decode.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,132 @@
+/* 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 "hycomp.h"
+
+/**
+ * Decode the UTF8 character.
+ *
+ * Decode the input UTF8 character and stores it into result.
+ *
+ * @param[in] input The UTF8 character
+ * @param[in,out] result buffer for unicode characters
+ * @param[in] bytesRemaining number of bytes remaining in input
+ *
+ * @return The number of UTF8 characters consumed (1,2,3) on success, 0 on failure
+ * @note Don't read more than bytesRemaining characters.
+ * @note If morecharacters are required to fully decode the character, return failure
+ */
+U_32
+decodeUTF8CharN (const U_8 * input, U_16 * result, U_32 bytesRemaining)
+{
+ U_8 c;
+ const U_8 *cursor = input;
+
+ if (bytesRemaining < 1)
+ {
+ return 0;
+ }
+
+ c = *cursor++;
+ if (c == 0x00)
+ {
+ /* illegal NUL encoding */
+
+ return 0;
+
+ }
+ else if ((c & 0x80) == 0x00)
+ {
+ /* one byte encoding */
+
+ *result = (U_16) c;
+ return 1;
+
+ }
+ else if ((c & 0xE0) == 0xC0)
+ {
+ /* two byte encoding */
+ U_16 unicodeC;
+
+ if (bytesRemaining < 2)
+ {
+ return 0;
+ }
+ unicodeC = ((U_16) c & 0x1F) << 6;
+
+ c = *cursor++;
+ unicodeC += (U_16) c & 0x3F;
+ if ((c & 0xC0) != 0x80)
+ {
+ return 0;
+ }
+
+ *result = unicodeC;
+ return 2;
+
+ }
+ else if ((c & 0xF0) == 0xE0)
+ {
+ /* three byte encoding */
+ U_16 unicodeC;
+
+ if (bytesRemaining < 3)
+ {
+ return 0;
+ }
+ unicodeC = ((U_16) c & 0x0F) << 12;
+
+ c = *cursor++;
+ unicodeC += ((U_16) c & 0x3F) << 6;
+ if ((c & 0xC0) != 0x80)
+ {
+ return 0;
+ }
+
+ c = *cursor++;
+ unicodeC += (U_16) c & 0x3F;
+ if ((c & 0xC0) != 0x80)
+ {
+ return 0;
+ }
+
+ *result = unicodeC;
+ return 3;
+ }
+ else
+ {
+ /* illegal encoding (i.e. would decode to a char > 0xFFFF) */
+
+ return 0;
+ }
+}
+
+/**
+ * Decode the UTF8 character.
+ *
+ * Decode the input UTF8 character and stores it into result.
+ *
+ * @param[in] input The UTF8 character
+ * @param[in,out] result buffer for unicode characters
+ *
+ * @return The number of UTF8 characters consumed (1,2,3) on success, 0 on failure
+ */
+U_32
+decodeUTF8Char (const U_8 * input, U_16 * result)
+{
+ /* a UTF8 character can't require more than 3 bytes */
+ return decodeUTF8CharN (input, result, 3);
+}
+
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/utf8encode.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/utf8encode.c?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/utf8encode.c (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/common/utf8encode.c Wed Nov 30 21:29:27 2005
@@ -0,0 +1,98 @@
+/* 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 "hycomp.h"
+
+/**
+ * Encode the Unicode character.
+ *
+ * Encodes the input Unicode character and stores it into result.
+ *
+ * @param[in] unicode The unicode character
+ * @param[in,out] result buffer for UTF8 character
+ * @param[in] bytesRemaining available space in result buffer
+ *
+ * @return Size of encoding (1,2,3) on success, 0 on failure
+ *
+ * @note Don't write more than bytesRemaining characters
+ * @note If result is NULL then bytesRemaining is ignored and the number
+ * of characters required to encode the unicode character is returned.
+ */
+U_32
+encodeUTF8CharN (UDATA unicode, U_8 * result, U_32 bytesRemaining)
+{
+ if (unicode >= 0x01 && unicode <= 0x7f)
+ {
+ if (result)
+ {
+ if (bytesRemaining < 1)
+ {
+ return 0;
+ }
+ *result = (U_8) unicode;
+ }
+ return 1;
+ }
+ else if (unicode == 0 || (unicode >= 0x80 && unicode <= 0x7ff))
+ {
+ if (result)
+ {
+ if (bytesRemaining < 2)
+ {
+ return 0;
+ }
+ *result++ = (U_8) (((unicode >> 6) & 0x1f) | 0xc0);
+ *result = (U_8) ((unicode & 0x3f) | 0x80);
+ }
+ return 2;
+ }
+ else if (unicode >= 0x800 && unicode <= 0xffff)
+ {
+ if (result)
+ {
+ if (bytesRemaining < 3)
+ {
+ return 0;
+ }
+ *result++ = (U_8) (((unicode >> 12) & 0x0f) | 0xe0);
+ *result++ = (U_8) (((unicode >> 6) & 0x3f) | 0x80);
+ *result = (U_8) ((unicode & 0x3f) | 0x80);
+ }
+ return 3;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+/**
+ * Encode the Unicode character.
+ *
+ * Encodes the input Unicode character and stores it into result.
+ *
+ * @param[in] unicode The unicode character
+ * @param[in,out] result buffer for UTF8 character
+ *
+ * @return Size of encoding (1,2,3) on success, 0 on failure
+ *
+ * @note If result is NULL then the number of characters required to
+ * encode the character is returned.
+ */
+U_32
+encodeUTF8Char (UDATA unicode, U_8 * result)
+{
+ return encodeUTF8CharN (unicode, result, 3);
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/fdlibm/fdlibm.h
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/fdlibm/fdlibm.h?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/fdlibm/fdlibm.h (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/native-src/linux.IA32/fdlibm/fdlibm.h Wed Nov 30 21:29:27 2005
@@ -0,0 +1,228 @@
+
+/* @(#)fdlibm.h 1.5 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+#include "hymagic.h"
+
+#ifdef __NEWVALID /* special setup for Sun test regime */
+#if defined(i386) || defined(i486) || \
+ defined(intel) || defined(x86) || defined(i86pc)
+#define HY_FDLIBM_LITTLE_ENDIAN
+#endif
+#endif
+
+#ifdef HY_FDLIBM_LITTLE_ENDIAN
+#define __HI(x) *(1+(int*)&x)
+#define __LO(x) *(int*)&x
+#define __HIp(x) *(1+(int*)x)
+#define __LOp(x) *(int*)x
+#else
+#define __HI(x) *(int*)&x
+#define __LO(x) *(1+(int*)&x)
+#define __HIp(x) *(int*)x
+#define __LOp(x) *(1+(int*)x)
+#endif
+
+#if defined(__STDC__) || defined(OS2)
+#define __P(p) p
+#else
+#define __P(p) ()
+#endif
+
+/*
+ * ANSI/POSIX
+ */
+
+extern int signgam;
+
+#define MAXFLOAT ((float)3.40282346638528860e+38)
+
+enum fdversion {fdlibm_ieee = -1, fdlibm_svid, fdlibm_xopen, fdlibm_posix};
+
+/* Local Change -- insist that only the IEEE version is built. See also s_lib_version.c */
+#ifndef HY_FIXED_VERSION
+
+#define _LIB_VERSION_TYPE enum fdversion
+#define _LIB_VERSION _fdlib_version
+
+/* if global variable _LIB_VERSION is not desirable, one may
+ * change the following to be a constant by:
+ * #define _LIB_VERSION_TYPE const enum version
+ * In that case, after one initializes the value _LIB_VERSION (see
+ * s_lib_version.c) during compile time, it cannot be modified
+ * in the middle of a program
+ */
+extern _LIB_VERSION_TYPE _LIB_VERSION;
+
+#else
+#define _LIB_VERSION HY_FIXED_VERSION
+#endif /* HY_FIXED_VERSION */
+
+#define _IEEE_ fdlibm_ieee
+#define _SVID_ fdlibm_svid
+#define _XOPEN_ fdlibm_xopen
+#define _POSIX_ fdlibm_posix
+
+struct exception {
+ int type;
+ char *name;
+ double arg1;
+ double arg2;
+ double retval;
+};
+
+#define HUGE MAXFLOAT
+
+/*
+ * set X_TLOSS = pi*2**52, which is possibly defined in <values.h>
+ * (one may replace the following line by "#include <values.h>")
+ */
+
+#define X_TLOSS 1.41484755040568800000e+16
+
+#define DOMAIN 1
+#define SING 2
+#define OVERFLOW 3
+#define UNDERFLOW 4
+#define TLOSS 5
+#define PLOSS 6
+
+/*
+ * ANSI/POSIX
+ */
+extern double acos __P((double));
+extern double asin __P((double));
+extern double atan __P((double));
+extern double atan2 __P((double, double));
+extern double cos __P((double));
+extern double sin __P((double));
+extern double tan __P((double));
+
+extern double cosh __P((double));
+extern double sinh __P((double));
+extern double tanh __P((double));
+
+extern double exp __P((double));
+extern double frexp __P((double, int *));
+extern double ldexp __P((double, int));
+extern double log __P((double));
+extern double log10 __P((double));
+extern double modf __P((double, double *));
+
+extern double pow __P((double, double));
+extern double sqrt __P((double));
+
+extern double ceil __P((double));
+extern double fabs __P((double));
+extern double floor __P((double));
+extern double fmod __P((double, double));
+
+extern double erf __P((double));
+extern double erfc __P((double));
+extern double gamma __P((double));
+extern double hypot __P((double, double));
+extern int isnan __P((double));
+extern int finite __P((double));
+extern double j0 __P((double));
+extern double j1 __P((double));
+extern double jn __P((int, double));
+extern double lgamma __P((double));
+extern double y0 __P((double));
+extern double y1 __P((double));
+extern double yn __P((int, double));
+
+extern double acosh __P((double));
+extern double asinh __P((double));
+extern double atanh __P((double));
+extern double cbrt __P((double));
+extern double logb __P((double));
+extern double nextafter __P((double, double));
+extern double remainder __P((double, double));
+#ifdef _SCALB_INT
+extern double scalb __P((double, int));
+#else
+extern double scalb __P((double, double));
+#endif
+
+extern int matherr __P((struct exception *));
+
+/*
+ * IEEE Test Vector
+ */
+extern double significand __P((double));
+
+/*
+ * Functions callable from C, intended to support IEEE arithmetic.
+ */
+extern double copysign __P((double, double));
+extern int ilogb __P((double));
+extern double rint __P((double));
+extern double scalbn __P((double, int));
+
+/*
+ * BSD math library entry points
+ */
+extern double expm1 __P((double));
+extern double log1p __P((double));
+
+/*
+ * Reentrant version of gamma & lgamma; passes signgam back by reference
+ * as the second argument; user must allocate space for signgam.
+ */
+#ifdef _REENTRANT
+extern double gamma_r __P((double, int *));
+extern double lgamma_r __P((double, int *));
+#endif /* _REENTRANT */
+
+/* ieee style elementary functions */
+extern double __ieee754_sqrt __P((double));
+extern double __ieee754_acos __P((double));
+extern double __ieee754_acosh __P((double));
+extern double __ieee754_log __P((double));
+extern double __ieee754_atanh __P((double));
+extern double __ieee754_asin __P((double));
+extern double __ieee754_atan2 __P((double,double));
+extern double __ieee754_exp __P((double));
+extern double __ieee754_cosh __P((double));
+extern double __ieee754_fmod __P((double,double));
+extern double __ieee754_pow __P((double,double));
+extern double __ieee754_lgamma_r __P((double,int *));
+extern double __ieee754_gamma_r __P((double,int *));
+extern double __ieee754_lgamma __P((double));
+extern double __ieee754_gamma __P((double));
+extern double __ieee754_log10 __P((double));
+extern double __ieee754_sinh __P((double));
+extern double __ieee754_hypot __P((double,double));
+extern double __ieee754_j0 __P((double));
+extern double __ieee754_j1 __P((double));
+extern double __ieee754_y0 __P((double));
+extern double __ieee754_y1 __P((double));
+extern double __ieee754_jn __P((int,double));
+extern double __ieee754_yn __P((int,double));
+extern double __ieee754_remainder __P((double,double));
+extern int __ieee754_rem_pio2 __P((double,double*));
+#ifdef _SCALB_INT
+extern double __ieee754_scalb __P((double,int));
+#else
+extern double __ieee754_scalb __P((double,double));
+#endif
+
+/* fdlibm kernel function */
+extern double __kernel_standard __P((double,double,int));
+extern double __kernel_sin __P((double,double,int));
+extern double __kernel_cos __P((double,double));
+extern double __kernel_tan __P((double,double,int));
+#ifdef OS2
+extern int __kernel_rem_pio2 __P((double*,double*,int,int,int,int*));
+#else
+extern int __kernel_rem_pio2 __P((double*,double*,int,int,int,const int*));
+#endif