Merge "Clean up the zlib-related native code." into dalvik-dev
diff --git a/luni/src/main/native/NativeConverter.cpp b/luni/src/main/native/NativeConverter.cpp
index 8b3952e..9e962ad 100644
--- a/luni/src/main/native/NativeConverter.cpp
+++ b/luni/src/main/native/NativeConverter.cpp
@@ -504,10 +504,10 @@
                          sourceLimit,NULL, TRUE,&errorCode);
 
         if(U_SUCCESS(errorCode)) {
-            return (jboolean)TRUE;
+            return JNI_TRUE;
         }
     }
-    return (jboolean)FALSE;
+    return JNI_FALSE;
 }
 
 /*
diff --git a/luni/src/main/native/Register.cpp b/luni/src/main/native/Register.cpp
index 8980cc5..5167f6c 100644
--- a/luni/src/main/native/Register.cpp
+++ b/luni/src/main/native/Register.cpp
@@ -43,10 +43,10 @@
 extern int register_java_lang_System(JNIEnv* env);
 extern int register_java_net_InetAddress(JNIEnv* env);
 extern int register_java_net_NetworkInterface(JNIEnv* env);
-extern "C" int register_java_util_zip_Adler32(JNIEnv* env);
-extern "C" int register_java_util_zip_CRC32(JNIEnv* env);
-extern "C" int register_java_util_zip_Deflater(JNIEnv* env);
-extern "C" int register_java_util_zip_Inflater(JNIEnv* env);
+extern int register_java_util_zip_Adler32(JNIEnv* env);
+extern int register_java_util_zip_CRC32(JNIEnv* env);
+extern int register_java_util_zip_Deflater(JNIEnv* env);
+extern int register_java_util_zip_Inflater(JNIEnv* env);
 extern "C" int register_org_apache_harmony_dalvik_NativeTestTarget(JNIEnv* env);
 extern int register_org_apache_harmony_luni_platform_OSFileSystem(JNIEnv* env);
 extern int register_org_apache_harmony_luni_platform_OSMemory(JNIEnv* env);
diff --git a/luni/src/main/native/UCharacter.cpp b/luni/src/main/native/UCharacter.cpp
index abad16a..136f58c 100644
--- a/luni/src/main/native/UCharacter.cpp
+++ b/luni/src/main/native/UCharacter.cpp
@@ -81,7 +81,7 @@
 }
 
 static jboolean isIdentifierIgnorableImpl(JNIEnv*, jclass, jint codePoint) {
-    // Java also returns TRUE for U+0085 Next Line (it omits U+0085 from whitespace ISO controls)
+    // Java also returns true for U+0085 Next Line (it omits U+0085 from whitespace ISO controls).
     if(codePoint == 0x0085) {
         return JNI_TRUE;
     }
diff --git a/luni/src/main/native/cbigint.h b/luni/src/main/native/cbigint.h
index 220aba8..b149053 100644
--- a/luni/src/main/native/cbigint.h
+++ b/luni/src/main/native/cbigint.h
@@ -17,8 +17,11 @@
 
 #if !defined(cbigint_h)
 #define cbigint_h
+
+#include "hycomp.h"
 #include "fltconst.h"
 #include "JNIHelp.h"
+
 #define LOW_U32_FROM_VAR(u64)     LOW_U32_FROM_LONG64(u64)
 #define LOW_U32_FROM_PTR(u64ptr)  LOW_U32_FROM_LONG64_PTR(u64ptr)
 #define HIGH_U32_FROM_VAR(u64)    HIGH_U32_FROM_LONG64(u64)
diff --git a/luni/src/main/native/fltconst.h b/luni/src/main/native/fltconst.h
index 940d5fc..d96c5bb 100644
--- a/luni/src/main/native/fltconst.h
+++ b/luni/src/main/native/fltconst.h
@@ -31,9 +31,9 @@
     positive           ==    sign bit clear
     negative           ==    sign bit set
 */
-#define MAX_U32_DOUBLE (ESDOUBLE) (4294967296.0)    /* 2^32 */
-#define MAX_U32_SINGLE (ESSINGLE) (4294967296.0)    /* 2^32 */
-#define HY_POS_PI      (ESDOUBLE) (3.141592653589793)
+#define MAX_U32_DOUBLE (double) (4294967296.0)    /* 2^32 */
+#define MAX_U32_SINGLE (float) (4294967296.0)    /* 2^32 */
+#define HY_POS_PI      (double) (3.141592653589793)
 
 #ifdef HY_LITTLE_ENDIAN
 #ifdef HY_PLATFORM_DOUBLE_ORDER
diff --git a/luni/src/main/native/hy2sie.h b/luni/src/main/native/hy2sie.h
deleted file mode 100644
index d40d0e8..0000000
--- a/luni/src/main/native/hy2sie.h
+++ /dev/null
@@ -1,114 +0,0 @@
-#if !defined(hy2sie_h)
-#define hy2sie_h
-
-
-#include "JNIHelp.h"
-#include "jni.h"
-#include "sieb.h"
-
-
-typedef int BOOLEAN;
-#define TRUE 1
-#define FALSE 0
-
-
-// mc: Stuff adopted from hyport.h:
-
-/** HyMaxPath was chosen from unix MAXPATHLEN.  Override in platform
-  * specific hyfile implementations if needed.
-  */
-#define HyMaxPath   1024
-
-
-
-// Following definitions from hycomp.h:
-
-/**
- * Define common types:
- * <ul>
- * <li><code>U_32 / I_32</code>  - unsigned/signed 32 bits</li>
- * <li><code>U_16 / I_16</code>  - unsigned/signed 16 bits</li>
- * <li><code>U_8 / I_8</code>    - unsigned/signed 8 bits (bytes -- not to be
- *                                 confused with char)</li>
- * </ul>
- */
-
-typedef int I_32;
-typedef short I_16;
-typedef signed char I_8; /* chars can be unsigned */
-typedef unsigned int U_32;
-typedef unsigned short U_16;
-typedef unsigned char U_8;
-
-typedef long long I_64;
-typedef unsigned long long U_64;
-
-/**
- * Define platform specific types:
- * <ul>
- * <li><code>UDATA</code>        - unsigned data, can be used as an integer or
- *                                 pointer storage</li>
- * <li><code>IDATA</code>        - signed data, can be used as an integer or
- *                                 pointer storage</li>
- * </ul>
- */
-/* FIXME: POINTER64 */
-
-typedef I_32 IDATA;
-typedef U_32 UDATA;
-
-
-// Further required definitions from Harmony:
-
-#define HYCONST64(x) x##L
-
-
-#define HY_CFUNC
-#define HY_CDATA
-#define PROTOTYPE(x) x
-#define VMCALL
-#define PVMCALL *
-#define NORETURN
-
-#define GLOBAL_DATA(symbol) ((void*)&(symbol))
-
-
-// Following definitions substitute the HyPortLibrary simply with the JNIEnv
-
-typedef JNIEnv HyPortLibrary;
-
-#define PORT_ACCESS_FROM_ENV(env) HyPortLibrary *privatePortLibrary = env
-#define PORT_ACCESS_FROM_PORT(portLibrary) HyPortLibrary *privatePortLibrary = portLibrary
-#define PORTLIB privatePortLibrary
-
-
-// Following defintion is used to avoide quite a few signedness warnings:
-#define mcSignednessBull void *
-
-
-// Following the substitution of hyfile:
-
-#include <fcntl.h>
-
-#define HyOpenRead    O_RDONLY
-#define hyfile_open(a, b, c) open(a, b, c)
-
-#define HySeekEnd SEEK_END
-#define HySeekSet SEEK_SET
-#define HySeekCur SEEK_CUR
-#define hyfile_seek(a, b, c) lseek(a, b, c)
-
-#define hyfile_read(a, b, c) read(a, b, c)
-
-#define hyfile_close(a) close(a)
-
-
-// And further substitutions:
-
-#define hymem_allocate_memory(byteCount) sieb_malloc(privatePortLibrary, byteCount)
-#define hymem_free_memory(pointer) sieb_free(privatePortLibrary, pointer)
-
-#define ioh_convertToPlatform(path) sieb_convertToPlatform (path)
-
-
-#endif /* hy2sie_h */
diff --git a/luni/src/main/native/hycomp.h b/luni/src/main/native/hycomp.h
index cd8ce73..9670f8f 100644
--- a/luni/src/main/native/hycomp.h
+++ b/luni/src/main/native/hycomp.h
@@ -23,43 +23,10 @@
 #endif
 
 /**
- * USE_PROTOTYPES:         Use full ANSI prototypes.
- *
- * CLOCK_PRIMS:            We want the timer/clock prims to be used
- *
  * LITTLE_ENDIAN:          This is for the intel machines or other
  *                         little endian processors. Defaults to big endian.
  *
- * NO_LVALUE_CASTING:      This is for compilers that don't like the left side
- *                         of assigns to be cast.  It hacks around to do the
- *                         right thing.
- *
  * ATOMIC_FLOAT_ACCESS:    So that float operations will work.
- *
- * LINKED_USER_PRIMITIVES: Indicates that user primitives are statically linked
- *                         with the VM executeable.
- *
- * OLD_SPACE_SIZE_DIFF:    The 68k uses a different amount of old space.
- *                         This "legitimizes" the change.
- *
- * SIMPLE_SIGNAL:          For machines that don't use real signals in C.
- *                         (eg: PC, 68k)
- *
- * OS_NAME_LOOKUP:         Use nlist to lookup user primitive addresses.
- *
- * VMCALL:                 Tag for all functions called by the VM.
- *
- * VMAPICALL:              Tag for all functions called via the PlatformFunction
- *                         callWith: mechanism.
- *
- * SYS_FLOAT:              For some math functions where extended types (80 or 96 bits) are returned
- *                         Most platforms return as a double
- *
- * FLOAT_EXTENDED:         If defined, the type name for extended precision floats.
- *
- * PLATFORM_IS_ASCII:      Must be defined if the platform is ASCII
- *
- * EXE_EXTENSION_CHAR:     the executable has a delimiter that we want to stop at as part of argv[0].
  */
 
  /**
@@ -72,18 +39,11 @@
  * Define common types:
  * <ul>
  * <li><code>U_32 / I_32</code>  - unsigned/signed 32 bits</li>
- * <li><code>U_16 / I_16</code>  - unsigned/signed 16 bits</li>
- * <li><code>U_8  / I_8</code>   - unsigned/signed 8 bits (bytes -- not to be
- *                                 confused with char)</li>
  * </ul>
  */
 
 typedef          int   I_32;
-typedef          short I_16;
-typedef signed   char  I_8; /* chars can be unsigned */
 typedef unsigned int   U_32;
-typedef unsigned short U_16;
-typedef unsigned char  U_8;
 
 /**
  * Define platform specific types:
@@ -96,357 +56,25 @@
 
 #define DATA_TYPES_DEFINED
 
-/* NOTE: Linux supports different processors -- do not assume 386 */
-    #if defined(HYX86_64) || defined(HYIA64) || defined(HYPPC64) || defined(HYS390X)
-
-        typedef unsigned long int U_64;         /* 64bits */
-        typedef          long int I_64;
-        #define TOC_UNWRAP_ADDRESS(wrappedPointer) ((void *) (wrappedPointer)[0])
-        #define TOC_STORE_TOC(dest,wrappedPointer) (dest = ((UDATA*)wrappedPointer)[1])
-
-        #define HY_WORD64
-
-    #else
-
         typedef unsigned long long U_64;
         typedef          long long I_64;
 
-    #endif
-
-    #if defined(HYS390X) || defined(HYS390) || defined(HYPPC64) || defined(HYPPC32)
-        #define HY_BIG_ENDIAN
-    #else
-        #define HY_LITTLE_ENDIAN
-    #endif
-
-    #if defined(HYPPC32)
-        #define VA_PTR(valist) (&valist[0])
-    #endif
-
-    typedef double SYS_FLOAT;
-    #define HYCONST64(x) x##LL
-    #define NO_LVALUE_CASTING
-    #define FLOAT_EXTENDED  long double
-    #define PLATFORM_IS_ASCII
-    #define PLATFORM_LINE_DELIMITER "\012"
-    #define DIR_SEPARATOR '/'
-    #define DIR_SEPARATOR_STR "/"
-
-/**
- * No priorities on Linux
- */
-
-    #define HY_PRIORITY_MAP {0,0,0,0,0,0,0,0,0,0,0,0}
-
-    typedef U_32 BOOLEAN;
-
 #endif
 
-/* Win32 - Windows 3.1 & NT using Win32 */
-#if defined(WIN32)
-
-    #define HY_LITTLE_ENDIAN
-
-/* Define 64-bit integers for Windows */
-    typedef __int64 I_64;
-    typedef unsigned __int64 U_64;
-
-    typedef double SYS_FLOAT;
-    #define NO_LVALUE_CASTING
-    #define VMAPICALL _stdcall
-    #define VMCALL _cdecl
-    #define EXE_EXTENSION_CHAR  '.'
-
-    #define DIR_SEPARATOR '\\'
-    #define DIR_SEPARATOR_STR "\\"
-
-/* Modifications for the Alpha running WIN-NT */
-    #if defined(_ALPHA_)
-        #undef small                    /* defined as char in rpcndr.h */
-        typedef double FLOAT_EXTENDED;
-    #endif
-
-    #define HY_PRIORITY_MAP { \
-      THREAD_PRIORITY_IDLE,             /* 0 */\
-      THREAD_PRIORITY_LOWEST,           /* 1 */\
-      THREAD_PRIORITY_BELOW_NORMAL,     /* 2 */\
-      THREAD_PRIORITY_BELOW_NORMAL,     /* 3 */\
-      THREAD_PRIORITY_BELOW_NORMAL,     /* 4 */\
-      THREAD_PRIORITY_NORMAL,           /* 5 */\
-      THREAD_PRIORITY_ABOVE_NORMAL,     /* 6 */\
-      THREAD_PRIORITY_ABOVE_NORMAL,     /* 7 */\
-      THREAD_PRIORITY_ABOVE_NORMAL,     /* 8 */\
-      THREAD_PRIORITY_ABOVE_NORMAL,     /* 9 */\
-      THREAD_PRIORITY_HIGHEST,          /*10 */\
-      THREAD_PRIORITY_TIME_CRITICAL     /*11 */}
-
-#endif /* defined(WIN32) */
-
-#if !defined(VMCALL)
-    #define VMCALL
-    #define VMAPICALL
-#endif
-#define PVMCALL VMCALL *
-
-#define GLOBAL_DATA(symbol) ((void*)&(symbol))
-#define GLOBAL_TABLE(symbol) GLOBAL_DATA(symbol)
-
-/**
- * Define platform specific types:
- * <ul>
- * <li><code>UDATA</code>        - unsigned data, can be used as an integer or
- *                                 pointer storage</li>
- * <li><code>IDATA</code>        - signed data, can be used as an integer or
- *                                 pointer storage</li>
- * </ul>
- */
-/* FIXME: POINTER64 */
-#if defined(HYX86_64) || defined(HYIA64) || defined(HYPPC64) || defined(HYS390X) || defined(POINTER64)
-
-typedef I_64 IDATA;
-typedef U_64 UDATA;
-
-#else /* this is default for non-64bit systems */
-
 typedef I_32 IDATA;
 typedef U_32 UDATA;
 
-#endif /* defined(HYX86_64) */
-
 #if !defined(DATA_TYPES_DEFINED)
 /* no generic U_64 or I_64 */
 
-/* don't typedef BOOLEAN since it's already def'ed on Win32 */
-#define BOOLEAN UDATA
-
 #ifndef HY_BIG_ENDIAN
 #define HY_LITTLE_ENDIAN
 #endif
 
 #endif
 
-#if !defined(HYCONST64)
-#define HYCONST64(x) x##L
-#endif
-
-#if !defined(HY_DEFAULT_SCHED)
-
-/**
- * By default, pthreads platforms use the <code>SCHED_OTHER</code> thread
- * scheduling policy.
- */
-
-#define HY_DEFAULT_SCHED SCHED_OTHER
-#endif
-
-#if !defined(HY_PRIORITY_MAP)
-
-/**
- * If no priority map if provided, priorities will be determined
- * algorithmically.
- */
-
-#endif
-
-#if !defined(FALSE)
-#define FALSE   ((BOOLEAN) 0)
-#if !defined(TRUE)
-#define TRUE    ((BOOLEAN) (!FALSE))
-#endif
-#endif
-
-#if !defined(NULL)
-#if defined(__cplusplus)
-#define NULL    (0)
-#else
-#define NULL    ((void *)0)
-#endif
-#endif
-#define USE_PROTOTYPES
-#if defined(USE_PROTOTYPES)
-#define PROTOTYPE(x)  x
-#define VARARGS   , ...
-#else
-#define PROTOTYPE(x)  ()
-#define VARARGS
-#endif
-
-/**
- * Assign the default line delimiter, if it was not set.
- */
-
-#if !defined(PLATFORM_LINE_DELIMITER)
-#define PLATFORM_LINE_DELIMITER "\015\012"
-#endif
-
-/**
- * Set the max path length, if it was not set.
- */
-
-#if !defined(MAX_IMAGE_PATH_LENGTH)
-#define MAX_IMAGE_PATH_LENGTH (2048)
-#endif
-typedef double ESDOUBLE;
-typedef float ESSINGLE;
-
-/**
- * Helpers for U_64s.
- */
-
-#define CLEAR_U64(u64)  (u64 = (U_64)0)
-#define LOW_LONG(l) (*((U_32 *) &(l)))
-#define HIGH_LONG(l)  (*(((U_32 *) &(l)) + 1))
-#define I8(x)       ((I_8) (x))
-#define I8P(x)      ((I_8 *) (x))
-#define U16(x)      ((U_16) (x))
-#define I16(x)      ((I_16) (x))
-#define I16P(x)     ((I_16 *) (x))
 #define U32(x)      ((U_32) (x))
 #define I32(x)      ((I_32) (x))
-#define I32P(x)     ((I_32 *) (x))
-#define U16P(x)     ((U_16 *) (x))
 #define U32P(x)     ((U_32 *) (x))
-#define OBJP(x)     ((HyObject *) (x))
-#define OBJPP(x)    ((HyObject **) (x))
-#define OBJPPP(x)   ((HyObject ***) (x))
-#define CLASSP(x)   ((Class *) (x))
-#define CLASSPP(x)  ((Class **) (x))
-#define BYTEP(x)    ((BYTE *) (x))
-
-/**
- * Test - was conflicting with OS2.h
- */
-
-#define ESCHAR(x)   ((CHARACTER) (x))
-#define FLT(x)      ((FLOAT) x)
-#define FLTP(x)     ((FLOAT *) (x))
-#if defined(NO_LVALUE_CASTING)
-#define LI8(x)      (*((I_8 *) &(x)))
-#define LI8P(x)     (*((I_8 **) &(x)))
-#define LU16(x)     (*((U_16 *) &(x)))
-#define LI16(x)     (*((I_16 *) &(x)))
-#define LU32(x)     (*((U_32 *) &(x)))
-#define LI32(x)     (*((I_32 *) &(x)))
-#define LI32P(x)    (*((I_32 **) &(x)))
-#define LU16P(x)    (*((U_16 **) &(x)))
-#define LU32P(x)    (*((U_32 **) &(x)))
-#define LOBJP(x)    (*((HyObject **) &(x)))
-#define LOBJPP(x)   (*((HyObject ***) &(x)))
-#define LOBJPPP(x)  (*((HyObject ****) &(x))
-#define LCLASSP(x)  (*((Class **) &(x)))
-#define LBYTEP(x)   (*((BYTE **) &(x)))
-#define LCHAR(x)    (*((CHARACTER) &(x)))
-#define LFLT(x)     (*((FLOAT) &x))
-#define LFLTP(x)    (*((FLOAT *) &(x)))
-#else
-#define LI8(x)      I8((x))
-#define LI8P(x)     I8P((x))
-#define LU16(x)     U16((x))
-#define LI16(x)     I16((x))
-#define LU32(x)     U32((x))
-#define LI32(x)     I32((x))
-#define LI32P(x)    I32P((x))
-#define LU16P(x)    U16P((x))
-#define LU32P(x)    U32P((x))
-#define LOBJP(x)    OBJP((x))
-#define LOBJPP(x)   OBJPP((x))
-#define LOBJPPP(x)  OBJPPP((x))
-#define LIOBJP(x)   IOBJP((x))
-#define LCLASSP(x)  CLASSP((x))
-#define LBYTEP(x)   BYTEP((x))
-#define LCHAR(x)    CHAR((x))
-#define LFLT(x)     FLT((x))
-#define LFLTP(x)    FLTP((x))
-#endif
-
-/**
- * Macros for converting between words and longs and accessing bits.
- */
-
-#define HIGH_WORD(x)  U16(U32((x)) >> 16)
-#define LOW_WORD(x)   U16(U32((x)) & 0xFFFF)
-#define LOW_BIT(o)    (U32((o)) & 1)
-#define LOW_2_BITS(o) (U32((o)) & 3)
-#define LOW_3_BITS(o) (U32((o)) & 7)
-#define LOW_4_BITS(o) (U32((o)) & 15)
-#define MAKE_32(h, l) ((U32((h)) << 16) | U32((l)))
-#define MAKE_64(h, l) ((((I_64)(h)) << 32) | (l))
-#if defined(__cplusplus)
-#define HY_CFUNC "C"
-#define HY_CDATA "C"
-#else
-#define HY_CFUNC
-#define HY_CDATA
-#endif
-
-/**
- * Macros for tagging functions which read/write the vm thread.
- */
-
-#define READSVMTHREAD
-#define WRITESVMTHREAD
-#define REQUIRESSTACKFRAME
-
-/**
- * Macro for tagging functions, which never return.
- */
-
-#if defined(__GNUC__)
-
-/**
- * On GCC, we can actually pass this information on to the compiler.
- */
-
-#define NORETURN __attribute__((noreturn))
-#else
-#define NORETURN
-#endif
-
-/**
- * On some systems va_list is an array type.  This is probably in
- * violation of the ANSI C spec, but it's not entirely clear.  Because of
- * this, we end up with an undesired extra level of indirection if we take
- * the address of a va_list argument. 
- *
- * To get it right, always use the VA_PTR macro
- */
-
-#if !defined(VA_PTR)
-#define VA_PTR(valist) (&valist)
-#endif
-#if !defined(TOC_UNWRAP_ADDRESS)
-#define TOC_UNWRAP_ADDRESS(wrappedPointer) (wrappedPointer)
-#endif
-
-#if !defined(TOC_STORE_TOC)
-#define TOC_STORE_TOC(dest,wrappedPointer)
-#endif
-/**
- * Macros for accessing I_64 values.
- */
-
-#if defined(ATOMIC_LONG_ACCESS)
-#define PTR_LONG_STORE(dstPtr, aLongPtr) ((*U32P(dstPtr) = *U32P(aLongPtr)), (*(U32P(dstPtr)+1) = *(U32P(aLongPtr)+1)))
-#define PTR_LONG_VALUE(dstPtr, aLongPtr) ((*U32P(aLongPtr) = *U32P(dstPtr)), (*(U32P(aLongPtr)+1) = *(U32P(dstPtr)+1)))
-#else
-#define PTR_LONG_STORE(dstPtr, aLongPtr) (*(dstPtr) = *(aLongPtr))
-#define PTR_LONG_VALUE(dstPtr, aLongPtr) (*(aLongPtr) = *(dstPtr))
-#endif
-
-/**
- * Macro used when declaring tables which require relocations.
- */
-
-#if !defined(HYCONST_TABLE)
-#define HYCONST_TABLE const
-#endif
-
-/**
- * ANSI qsort is not always available.
- */
-
-#if !defined(HY_SORT)
-#define HY_SORT(base, nmemb, size, compare) qsort((base), (nmemb), (size), (compare))
-#endif
 
 #endif /* hycomp_h */
diff --git a/luni/src/main/native/hymutex.h b/luni/src/main/native/hymutex.h
deleted file mode 100644
index 5c98ebd..0000000
--- a/luni/src/main/native/hymutex.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You 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(hymutex_h)
-#define hymutex_h
-
-#include <pthread.h>
-#include <stdlib.h>
-
-typedef pthread_mutex_t MUTEX;
-
-/* MUTEX_INIT */
-#define MUTEX_INIT(mutex) (pthread_mutex_init(&(mutex), NULL) == 0)
-
-/* MUTEX_DESTROY */
-#define MUTEX_DESTROY(mutex) pthread_mutex_destroy(&(mutex))
-
-/* MUTEX_ENTER */
-#define MUTEX_ENTER(mutex) pthread_mutex_lock(&(mutex))
-
-/*
- *  MUTEX_TRY_ENTER 
- *  returns 0 on success
- */
-#define MUTEX_TRY_ENTER(mutex) pthread_mutex_trylock(&(mutex))
-
-/* MUTEX_EXIT */
-#define MUTEX_EXIT(mutex) pthread_mutex_unlock(&(mutex))
-
-#endif     /* hymutex_h */
diff --git a/luni/src/main/native/hyport.h b/luni/src/main/native/hyport.h
deleted file mode 100644
index 029d4fe..0000000
--- a/luni/src/main/native/hyport.h
+++ /dev/null
@@ -1 +0,0 @@
-#include "hy2sie.h"
diff --git a/luni/src/main/native/java_lang_StrictMath.c b/luni/src/main/native/java_lang_StrictMath.c
index 651e2dd..2c52f36 100644
--- a/luni/src/main/native/java_lang_StrictMath.c
+++ b/luni/src/main/native/java_lang_StrictMath.c
@@ -11,8 +11,6 @@
  * into the android environment.
  */
 
-/* #include "fltconst.h" */
-
 #if defined(__P)
 #undef __P
 #endif /* defined(__P) */
diff --git a/luni/src/main/native/java_util_zip_Adler32.c b/luni/src/main/native/java_util_zip_Adler32.c
deleted file mode 100644
index 4410e5b..0000000
--- a/luni/src/main/native/java_util_zip_Adler32.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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"
-#include "hy2sie.h"
-#include "zlib.h"
-#include "sieb.h"
-
-JNIEXPORT jlong JNICALL
-Java_java_util_zip_Adler32_updateImpl (JNIEnv * env, jobject recv,
-                                       jbyteArray buf, int off, int len,
-                                       jlong crc)
-{
-  jbyte* b = (*env)->GetPrimitiveArrayCritical (env, buf, NULL);
-  if (b == NULL) {
-    return 0;
-  }
-  jlong result = (jlong) adler32 ((uLong) crc, (Bytef *) (b + off), (uInt) len);
-  (*env)->ReleasePrimitiveArrayCritical (env, buf, b, JNI_ABORT);
-
-  return result;
-}
-
-JNIEXPORT jlong JNICALL
-Java_java_util_zip_Adler32_updateByteImpl (JNIEnv * env, jobject recv,
-                                           jint val, jlong crc)
-{
-  Bytef bytefVal = val;
-  return adler32 ((uLong) crc, (Bytef *) (&bytefVal), 1);
-}
-
-static JNINativeMethod gMethods[] = {
-    { "updateImpl", "([BIIJ)J",     Java_java_util_zip_Adler32_updateImpl },
-    { "updateByteImpl", "(IJ)J",     Java_java_util_zip_Adler32_updateByteImpl },
-};
-int register_java_util_zip_Adler32(JNIEnv* env) {
-    return jniRegisterNativeMethods(env, "java/util/zip/Adler32", gMethods, NELEM(gMethods));
-}
diff --git a/luni/src/main/native/java_util_zip_Adler32.cpp b/luni/src/main/native/java_util_zip_Adler32.cpp
new file mode 100644
index 0000000..254a3fd
--- /dev/null
+++ b/luni/src/main/native/java_util_zip_Adler32.cpp
@@ -0,0 +1,44 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 "JNIHelp.h"
+#include "jni.h"
+#include "zlib.h"
+
+static jlong Adler32_updateImpl(JNIEnv* env, jobject, jbyteArray buf, int off, int len, jlong crc) {
+    jbyte* b = (jbyte*) env->GetPrimitiveArrayCritical(buf, NULL);
+    if (b == NULL) {
+        jniThrowNullPointerException(env, NULL);
+        return 0;
+    }
+    jlong result = (jlong) adler32((uLong) crc, (Bytef *) (b + off), (uInt) len);
+    env->ReleasePrimitiveArrayCritical(buf, b, JNI_ABORT);
+    return result;
+}
+
+static jlong Adler32_updateByteImpl(JNIEnv* env, jobject, jint val, jlong crc) {
+    Bytef bytefVal = val;
+    return adler32((uLong) crc, (Bytef *) (&bytefVal), 1);
+}
+
+static JNINativeMethod gMethods[] = {
+    { "updateImpl", "([BIIJ)J", (void*) Adler32_updateImpl },
+    { "updateByteImpl", "(IJ)J", (void*) Adler32_updateByteImpl },
+};
+int register_java_util_zip_Adler32(JNIEnv* env) {
+    return jniRegisterNativeMethods(env, "java/util/zip/Adler32", gMethods, NELEM(gMethods));
+}
diff --git a/luni/src/main/native/java_util_zip_CRC32.c b/luni/src/main/native/java_util_zip_CRC32.c
deleted file mode 100644
index 95369a2..0000000
--- a/luni/src/main/native/java_util_zip_CRC32.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 "hy2sie.h"
-#include "sieb.h"
-
-#include "zlib.h"
-
-JNIEXPORT jlong JNICALL
-Java_java_util_zip_CRC32_updateImpl (JNIEnv * env, jobject recv,
-                                     jbyteArray buf, int off, int len,
-                                     jlong crc)
-{
-  jbyte* b = ((*env)->GetPrimitiveArrayCritical (env, buf, 0));
-  if (b == NULL) {
-    return -1;
-  }
-  jlong result = crc32 ((uLong) crc, (Bytef *) (b + off), (uInt) len);
-  ((*env)->ReleasePrimitiveArrayCritical (env, buf, b, JNI_ABORT));
-  return result;
-}
-
-JNIEXPORT jlong JNICALL
-Java_java_util_zip_CRC32_updateByteImpl (JNIEnv * env, jobject recv,
-                                         jbyte val, jlong crc)
-{
-  return crc32 ((uLong) crc, (Bytef *) (&val), 1);
-}
-
-static JNINativeMethod gMethods[] = {
-    { "updateImpl", "([BIIJ)J",     Java_java_util_zip_CRC32_updateImpl },
-    { "updateByteImpl", "(BJ)J",     Java_java_util_zip_CRC32_updateByteImpl },
-};
-int register_java_util_zip_CRC32(JNIEnv* env) {
-    return jniRegisterNativeMethods(env, "java/util/zip/CRC32", gMethods, NELEM(gMethods));
-}
diff --git a/luni/src/main/native/java_util_zip_CRC32.cpp b/luni/src/main/native/java_util_zip_CRC32.cpp
new file mode 100644
index 0000000..c9c604b
--- /dev/null
+++ b/luni/src/main/native/java_util_zip_CRC32.cpp
@@ -0,0 +1,43 @@
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 "JNIHelp.h"
+#include "jni.h"
+#include "zlib.h"
+
+static jlong CRC32_updateImpl(JNIEnv* env, jobject, jbyteArray buf, int off, int len, jlong crc) {
+    jbyte* b = (jbyte*) env->GetPrimitiveArrayCritical(buf, NULL);
+    if (b == NULL) {
+        jniThrowNullPointerException(env, NULL);
+        return 0;
+    }
+    jlong result = crc32((uLong) crc, (Bytef *) (b + off), (uInt) len);
+    env->ReleasePrimitiveArrayCritical(buf, b, JNI_ABORT);
+    return result;
+}
+
+static jlong CRC32_updateByteImpl(JNIEnv* env, jobject recv, jbyte val, jlong crc) {
+    return crc32((uLong) crc, (Bytef *) (&val), 1);
+}
+
+static JNINativeMethod gMethods[] = {
+    { "updateImpl", "([BIIJ)J", (void*) CRC32_updateImpl },
+    { "updateByteImpl", "(BJ)J", (void*) CRC32_updateByteImpl },
+};
+int register_java_util_zip_CRC32(JNIEnv* env) {
+    return jniRegisterNativeMethods(env, "java/util/zip/CRC32", gMethods, NELEM(gMethods));
+}
diff --git a/luni/src/main/native/java_util_zip_Deflater.c b/luni/src/main/native/java_util_zip_Deflater.c
deleted file mode 100644
index 59c7433..0000000
--- a/luni/src/main/native/java_util_zip_Deflater.c
+++ /dev/null
@@ -1,304 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 "hy2sie.h"
-
-#include "zlib.h"
-#include "zip.h"
-#include "jni.h"
-
-#ifndef HY_ZIP_API
-void zfree PROTOTYPE ((void *opaque, void *address));
-void *zalloc PROTOTYPE ((void *opaque, U_32 items, U_32 size));
-#endif
-
-
-static struct {
-    jfieldID inRead;
-    jfieldID finished;
-} gCachedFields;
-
-
-JNIEXPORT void JNICALL
-Java_java_util_zip_Deflater_setDictionaryImpl (JNIEnv * env, jobject recv,
-					       jbyteArray dict, int off,
-					       int len, jlong handle)
-{
-  PORT_ACCESS_FROM_ENV (env);
-  int err = 0;
-  unsigned char *dBytes;
-  JCLZipStream *stream = (JCLZipStream *) ((IDATA) handle);
-
-  dBytes = jclmem_allocate_memory (env, len);
-  if (dBytes == NULL)
-    {
-      throwNewOutOfMemoryError (env, "");
-      return;
-    }
-  (*env)->GetByteArrayRegion (env, dict, off, len, (mcSignednessBull)dBytes);
-  err = deflateSetDictionary (stream->stream, (Bytef *) dBytes, len);
-  if (err != Z_OK)
-    {
-      jclmem_free_memory (env, dBytes);
-      THROW_ZIP_EXCEPTION(env, err, IllegalArgumentException);
-      return;
-    }
-  stream->dict = (U_8*) dBytes;
-}
-
-JNIEXPORT jlong JNICALL
-Java_java_util_zip_Deflater_getTotalInImpl (JNIEnv * env, jobject recv,
-					    jlong handle)
-{
-  JCLZipStream *stream;
-
-  stream = (JCLZipStream *) ((IDATA) handle);
-  return stream->stream->total_in;
-}
-
-JNIEXPORT jlong JNICALL
-Java_java_util_zip_Deflater_getTotalOutImpl (JNIEnv * env, jobject recv,
-					     jlong handle)
-{
-  JCLZipStream *stream;
-
-  stream = (JCLZipStream *) ((IDATA) handle);
-  return stream->stream->total_out;
-}
-
-JNIEXPORT jint JNICALL
-Java_java_util_zip_Deflater_getAdlerImpl (JNIEnv * env, jobject recv,
-					  jlong handle)
-{
-  JCLZipStream *stream;
-
-  stream = (JCLZipStream *) ((IDATA) handle);
-
-  return stream->stream->adler;
-}
-
-/* Create a new stream . This stream cannot be used until it has been properly initialized. */
-JNIEXPORT jlong JNICALL
-Java_java_util_zip_Deflater_createStream (JNIEnv * env, jobject recv,
-					  jint level, jint strategy,
-					  jboolean noHeader)
-{
-  PORT_ACCESS_FROM_ENV (env);
-  JCLZipStream *jstream;
-  z_stream *stream;
-  int err = 0;
-  // BEGIN android-changed
-  int wbits = 12; // Was 15, made it 12 to reduce memory consumption. Use MAX
-                  // for fastest.
-  int mlevel = 5; // Was 9, made it 5 to reduce memory consumption. Might result
-                  // in out-of-memory problems according to some web pages. The
-                  // ZLIB docs are a bit vague, unfortunately. The default
-                  // results in 2 x 128K being allocated per Deflater, which is
-                  // not acceptable.
-  // END android-changed
-#ifdef HY_ZIP_API
-  VMI_ACCESS_FROM_ENV (env);
-  VMIZipFunctionTable *zipFuncs;
-  zipFuncs = (*VMI)->GetZipFunctions(VMI);
-#endif
-
-  /*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;
-  jstream->stream = stream;
-  jstream->dict = NULL;
-  jstream->inaddr = NULL;
-
-  /*Unable to find official doc that this is the way to avoid zlib header use. However doc in zipsup.c claims it is so */
-  if (noHeader)
-    wbits = wbits / -1;
-  err = deflateInit2 (stream, level, Z_DEFLATED,	/*Only supported ZLIB method */
-		      wbits,	/*Window bits to use. 15 is fastest but consumes the most memory */
-		      // BEGIN android-changed
-		      mlevel,	/*Memory allocation for internal compression state. 9 uses the most. */
-		      // END android-changed
-		      strategy);
-  if (err != Z_OK) {
-    THROW_ZIP_EXCEPTION(env, err, IllegalArgumentException);
-    return -1;
-  }
-
-  return (jlong) ((IDATA) jstream);
-}
-
-JNIEXPORT void JNICALL
-Java_java_util_zip_Deflater_setInputImpl (JNIEnv * env, jobject recv,
-					  jbyteArray buf, jint off, jint len,
-					  jlong handle)
-{
-  PORT_ACCESS_FROM_ENV (env);
-
-  JCLZipStream* stream = (JCLZipStream *) ((IDATA) handle);
-  if (stream->inaddr != NULL) {
-    /* Input has already been provided, free the old buffer. */
-    jclmem_free_memory (env, stream->inaddr);
-  }
-  stream->inaddr = jclmem_allocate_memory (env, len);
-  if (stream->inaddr == NULL) {
-    throwNewOutOfMemoryError (env, "");
-    return;
-  }
-  (*env)->GetByteArrayRegion(env, buf, off, len, (jbyte*) stream->inaddr);
-  stream->stream->next_in = (Bytef *) stream->inaddr;
-  stream->stream->avail_in = len;
-}
-
-JNIEXPORT jint JNICALL
-Java_java_util_zip_Deflater_deflateImpl (JNIEnv * env, jobject recv,
-					 jbyteArray buf, int off, int len,
-					 jlong handle, int flushParm)
-{
-  jbyte *out;
-  JCLZipStream *stream;
-  jint err = 0;
-  jint sin, sout, inBytes = 0;
-
-  /* We need to get the number of bytes already read */
-  inBytes =
-    ((*env)->
-     GetIntField (env, recv,
-		  gCachedFields.inRead));
-
-  stream = (JCLZipStream *) ((IDATA) handle);
-  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 = deflate (stream->stream, flushParm);
-  ((*env)->ReleasePrimitiveArrayCritical (env, buf, out, 0));
-  if (err != Z_OK) {
-    if (err == Z_MEM_ERROR) {
-      throwNewOutOfMemoryError(env, "");
-      return 0;
-    }
-    if (err == Z_STREAM_END)
-      {
-        ((*env)->
-         SetBooleanField (env, recv,
-                          gCachedFields.finished,
-                          JNI_TRUE));
-        return stream->stream->total_out - sout;
-      }
-  }
-  if (flushParm != Z_FINISH)
-    {
-      /* Need to update the number of input bytes read. */
-      ((*env)->
-       SetIntField (env, recv,
-                    gCachedFields.inRead,
-                    (jint) stream->stream->total_in - sin + inBytes));
-    }
-  return stream->stream->total_out - sout;
-}
-
-JNIEXPORT void JNICALL
-Java_java_util_zip_Deflater_endImpl (JNIEnv * env, jobject recv, jlong handle)
-{
-  PORT_ACCESS_FROM_ENV (env);
-  JCLZipStream *stream;
-
-  stream = (JCLZipStream *) ((IDATA) handle);
-
-  deflateEnd (stream->stream);
-  if (stream->inaddr != NULL)
-    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);
-}
-
-JNIEXPORT void JNICALL
-Java_java_util_zip_Deflater_resetImpl (JNIEnv * env, jobject recv,
-				       jlong handle)
-{
-  JCLZipStream *stream;
-
-  stream = (JCLZipStream *) ((IDATA) handle);
-  deflateReset (stream->stream);
-}
-
-JNIEXPORT void JNICALL
-Java_java_util_zip_Deflater_setLevelsImpl (JNIEnv * env, jobject recv,
-					   int level, int strategy,
-					   jlong handle)
-{
-  JCLZipStream *stream;
-  jbyte b = 0;
-  int err = 0;
-
-  if (handle == -1)
-    {
-      throwNewIllegalStateException (env, "");
-      return;
-    }
-  stream = (JCLZipStream *) ((IDATA) handle);
-  stream->stream->next_out = (Bytef *) & b;
-  err = deflateParams (stream->stream, level, strategy);
-  if (err != Z_OK) {
-    THROW_ZIP_EXCEPTION(env, err, IllegalStateException);
-  }
-}
-
-JNIEXPORT void JNICALL
-Java_java_util_zip_Deflater_oneTimeInitialization (JNIEnv * env, jclass clazz)
-{
-    memset(&gCachedFields, 0, sizeof(gCachedFields));
-    gCachedFields.inRead = (*env)->GetFieldID (env, clazz, "inRead", "I");
-    gCachedFields.finished = (*env)->GetFieldID (env, clazz, "finished", "Z");
-}
-
-static JNINativeMethod gMethods[] = {
-    { "setDictionaryImpl", "([BIIJ)V",     Java_java_util_zip_Deflater_setDictionaryImpl },
-    { "getTotalInImpl", "(J)J",     Java_java_util_zip_Deflater_getTotalInImpl },
-    { "getTotalOutImpl", "(J)J",     Java_java_util_zip_Deflater_getTotalOutImpl },
-    { "getAdlerImpl", "(J)I",     Java_java_util_zip_Deflater_getAdlerImpl },
-    { "createStream", "(IIZ)J",     Java_java_util_zip_Deflater_createStream },
-    { "setInputImpl", "([BIIJ)V",     Java_java_util_zip_Deflater_setInputImpl },
-    { "deflateImpl", "([BIIJI)I",     Java_java_util_zip_Deflater_deflateImpl },
-    { "endImpl", "(J)V",     Java_java_util_zip_Deflater_endImpl },
-    { "resetImpl", "(J)V",     Java_java_util_zip_Deflater_resetImpl },
-    { "setLevelsImpl", "(IIJ)V",     Java_java_util_zip_Deflater_setLevelsImpl },
-    { "oneTimeInitialization", "()V",     Java_java_util_zip_Deflater_oneTimeInitialization },
-};
-int register_java_util_zip_Deflater(JNIEnv* env) {
-    return jniRegisterNativeMethods(env, "java/util/zip/Deflater", gMethods, NELEM(gMethods));
-}
diff --git a/luni/src/main/native/java_util_zip_Deflater.cpp b/luni/src/main/native/java_util_zip_Deflater.cpp
new file mode 100644
index 0000000..46ae001
--- /dev/null
+++ b/luni/src/main/native/java_util_zip_Deflater.cpp
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 "zip.h"
+
+static struct {
+    jfieldID inRead;
+    jfieldID finished;
+} gCachedFields;
+
+static void Deflater_setDictionaryImpl(JNIEnv* env, jobject, jbyteArray dict, int off, int len, jlong handle) {
+    toNativeZipStream(handle)->setDictionary(env, dict, off, len, false);
+}
+
+static jlong Deflater_getTotalInImpl(JNIEnv* env, jobject, jlong handle) {
+    return toNativeZipStream(handle)->stream.total_in;
+}
+
+static jlong Deflater_getTotalOutImpl(JNIEnv* env, jobject, jlong handle) {
+    return toNativeZipStream(handle)->stream.total_out;
+}
+
+static jint Deflater_getAdlerImpl(JNIEnv* env, jobject, jlong handle) {
+    return toNativeZipStream(handle)->stream.adler;
+}
+
+/* Create a new stream . This stream cannot be used until it has been properly initialized. */
+static jlong Deflater_createStream(JNIEnv * env, jobject, jint level, jint strategy, jboolean noHeader) {
+    UniquePtr<NativeZipStream> jstream(new NativeZipStream);
+    if (jstream.get() == NULL) {
+        jniThrowOutOfMemoryError(env, NULL);
+        return -1;
+    }
+
+    int wbits = 12; // Was 15, made it 12 to reduce memory consumption. Use MAX for fastest.
+    int mlevel = 5; // Was 9, made it 5 to reduce memory consumption. Might result
+                  // in out-of-memory problems according to some web pages. The
+                  // ZLIB docs are a bit vague, unfortunately. The default
+                  // results in 2 x 128K being allocated per Deflater, which is
+                  // not acceptable.
+    /*Unable to find official doc that this is the way to avoid zlib header use. However doc in zipsup.c claims it is so */
+    if (noHeader) {
+        wbits = wbits / -1;
+    }
+    int err = deflateInit2(&jstream->stream, level, Z_DEFLATED, wbits, mlevel, strategy);
+    if (err != Z_OK) {
+        throwExceptionForZlibError(env, "java/lang/IllegalArgumentException", err);
+        return -1;
+    }
+    return reinterpret_cast<uintptr_t>(jstream.release());
+}
+
+static void Deflater_setInputImpl(JNIEnv* env, jobject, jbyteArray buf, jint off, jint len, jlong handle) {
+    toNativeZipStream(handle)->setInput(env, buf, off, len);
+}
+
+static jint Deflater_deflateImpl(JNIEnv* env, jobject recv, jbyteArray buf, int off, int len, jlong handle, int flushParm) {
+    /* We need to get the number of bytes already read */
+    jint inBytes = env->GetIntField(recv, gCachedFields.inRead);
+
+    NativeZipStream* stream = toNativeZipStream(handle);
+    stream->stream.avail_out = len;
+    jint sin = stream->stream.total_in;
+    jint sout = stream->stream.total_out;
+    jbyte* out = (jbyte*) env->GetPrimitiveArrayCritical(buf, NULL);
+    if (out == NULL) {
+        return -1;
+    }
+    stream->stream.next_out = (Bytef *) out + off;
+    int err = deflate(&stream->stream, flushParm);
+    env->ReleasePrimitiveArrayCritical(buf, out, 0);
+    if (err != Z_OK) {
+        if (err == Z_MEM_ERROR) {
+            jniThrowOutOfMemoryError(env, NULL);
+            return 0;
+        }
+        if (err == Z_STREAM_END) {
+            env->SetBooleanField(recv, gCachedFields.finished, JNI_TRUE);
+            return stream->stream.total_out - sout;
+        }
+    }
+    if (flushParm != Z_FINISH) {
+        /* Need to update the number of input bytes read. */
+        env->SetIntField(recv, gCachedFields.inRead, (jint) stream->stream.total_in - sin + inBytes);
+    }
+    return stream->stream.total_out - sout;
+}
+
+static void Deflater_endImpl(JNIEnv* env, jobject, jlong handle) {
+    NativeZipStream* stream = toNativeZipStream(handle);
+    deflateEnd(&stream->stream);
+    delete stream;
+}
+
+static void Deflater_resetImpl(JNIEnv* env, jobject, jlong handle) {
+    NativeZipStream* stream = toNativeZipStream(handle);
+    int err = deflateReset(&stream->stream);
+    if (err != Z_OK) {
+        throwExceptionForZlibError(env, "java/lang/IllegalArgumentException", err);
+    }
+}
+
+static void Deflater_setLevelsImpl(JNIEnv* env, jobject, int level, int strategy, jlong handle) {
+    if (handle == -1) {
+        jniThrowException(env, "java/lang/IllegalStateException", NULL);
+        return;
+    }
+    NativeZipStream* stream = toNativeZipStream(handle);
+    jbyte b = 0;
+    stream->stream.next_out = (Bytef*) &b;
+    int err = deflateParams(&stream->stream, level, strategy);
+    if (err != Z_OK) {
+        throwExceptionForZlibError(env, "java/lang/IllegalStateException", err);
+    }
+}
+
+static void Deflater_oneTimeInitialization(JNIEnv* env, jclass clazz) {
+    memset(&gCachedFields, 0, sizeof(gCachedFields));
+    gCachedFields.inRead = env->GetFieldID(clazz, "inRead", "I");
+    gCachedFields.finished = env->GetFieldID(clazz, "finished", "Z");
+}
+
+static JNINativeMethod gMethods[] = {
+    { "setDictionaryImpl", "([BIIJ)V", (void*) Deflater_setDictionaryImpl },
+    { "getTotalInImpl", "(J)J", (void*) Deflater_getTotalInImpl },
+    { "getTotalOutImpl", "(J)J", (void*) Deflater_getTotalOutImpl },
+    { "getAdlerImpl", "(J)I", (void*) Deflater_getAdlerImpl },
+    { "createStream", "(IIZ)J", (void*) Deflater_createStream },
+    { "setInputImpl", "([BIIJ)V", (void*) Deflater_setInputImpl },
+    { "deflateImpl", "([BIIJI)I", (void*) Deflater_deflateImpl },
+    { "endImpl", "(J)V", (void*) Deflater_endImpl },
+    { "resetImpl", "(J)V", (void*) Deflater_resetImpl },
+    { "setLevelsImpl", "(IIJ)V", (void*) Deflater_setLevelsImpl },
+    { "oneTimeInitialization", "()V", (void*) Deflater_oneTimeInitialization },
+};
+int register_java_util_zip_Deflater(JNIEnv* env) {
+    return jniRegisterNativeMethods(env, "java/util/zip/Deflater", gMethods, NELEM(gMethods));
+}
diff --git a/luni/src/main/native/java_util_zip_Inflater.c b/luni/src/main/native/java_util_zip_Inflater.c
deleted file mode 100644
index 6281081..0000000
--- a/luni/src/main/native/java_util_zip_Inflater.c
+++ /dev/null
@@ -1,340 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 "hy2sie.h"
-#include "zip.h"
-
-#include "zlib.h"
-#include <memory.h>
-#define jclmem_allocate_memory(env, byteCount) sieb_malloc(env, byteCount)
-#define jclmem_free_memory(env, pointer) sieb_free(env, pointer)
-
-#include <fcntl.h>
-
-void throwNewDataFormatException (JNIEnv * env, const char *message);
-
-void zfree PROTOTYPE ((void *opaque, void *address));
-void *zalloc PROTOTYPE ((void *opaque, U_32 items, U_32 size));
-
-
-static struct {
-    jfieldID inRead;
-    jfieldID finished;
-    jfieldID needsDictionary;
-} gCachedFields;
-
-
-
-/* Create a new stream . This stream cannot be used until it has been properly initialized. */
-JNIEXPORT 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 */
-#ifdef HY_ZIP_API
-  VMI_ACCESS_FROM_ENV (env);
-  VMIZipFunctionTable *zipFuncs;
-  zipFuncs = (*VMI)->GetZipFunctions(VMI);
-#endif
-
-  /*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;
-  stream->adler = 1;
-  jstream->stream = stream;
-  jstream->dict = NULL;
-  jstream->inaddr = NULL;
-  jstream->inCap = 0;
-
-  /*
-   * In the range 8..15 for checked, or -8..-15 for unchecked inflate. Unchecked
-   * is appropriate for formats like zip that do their own validity checking.
-   */
-  if (noHeader)
-    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);
-      THROW_ZIP_EXCEPTION(env, err, IllegalArgumentException);
-      return -1;
-    }
-
-  return (jlong) ((IDATA) jstream);
-}
-
-JNIEXPORT 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);
-
-  JCLZipStream *stream = (JCLZipStream *) ((IDATA) handle);
-  if (stream->inaddr != NULL) {
-    /* Input has already been provided, free the old buffer. */
-    jclmem_free_memory (env, stream->inaddr);
-  }
-  U_8* 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;
-  (*env)->GetByteArrayRegion(env, buf, off, len, (jbyte*) baseAddr);
-}
-
-JNIEXPORT jint JNICALL
-Java_java_util_zip_Inflater_setFileInputImpl (JNIEnv * env, jobject recv,
-        jobject javaFileDescriptor, jlong off, jint len, jlong handle)
-{
-    PORT_ACCESS_FROM_ENV (env);
-
-    U_8 * baseAddr;
-    JCLZipStream * stream = (JCLZipStream *) ((IDATA) handle);
-
-    if (stream->inCap < len) {
-        // No input buffer as yet (or one that is too small).
-        jclmem_free_memory(env, stream->inaddr);
-        baseAddr = jclmem_allocate_memory(env, len);
-        if (baseAddr == NULL)
-        {
-            throwNewOutOfMemoryError(env, "");
-            return -1;
-        }
-        stream->inaddr = baseAddr;
-    }
-    stream->stream->next_in = (Bytef *) stream->inaddr;
-    stream->stream->avail_in = len;
-
-    int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor);
-    lseek(fd, off, SEEK_SET);
-    int cnt = read(fd, stream->inaddr, len);
-
-    return cnt;
-}
-
-JNIEXPORT jint JNICALL
-Java_java_util_zip_Inflater_inflateImpl (JNIEnv * env, jobject recv,
-                                         jbyteArray buf, int off, int len,
-                                         jlong handle)
-{
-  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 = gCachedFields.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) {
-    throwNewOutOfMemoryError(env, "");
-    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_ERROR) {
-          return 0;
-      }
-      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 = gCachedFields.finished;
-          else
-            fid2 = gCachedFields.needsDictionary;
-
-          ((*env)->SetBooleanField (env, recv, fid2, JNI_TRUE));
-          return stream->stream->total_out - sout;
-        }
-      else
-        {
-          THROW_ZIP_EXCEPTION(env, err, DataFormatException);
-          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;
-}
-
-JNIEXPORT jint JNICALL
-Java_java_util_zip_Inflater_getAdlerImpl (JNIEnv * env, jobject recv,
-                                          jlong handle)
-{
-  JCLZipStream *stream;
-
-  stream = (JCLZipStream *) ((IDATA) handle);
-
-  return stream->stream->adler;
-}
-
-JNIEXPORT 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);
-}
-
-JNIEXPORT 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, (mcSignednessBull)dBytes);
-  err = inflateSetDictionary (stream->stream, (Bytef *) dBytes, len);
-  if (err != Z_OK)
-    {
-      jclmem_free_memory (env, dBytes);
-      THROW_ZIP_EXCEPTION(env, err, IllegalArgumentException);
-      return;
-    }
-  stream->dict = dBytes;
-}
-
-JNIEXPORT 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)
-    {
-      THROW_ZIP_EXCEPTION(env, err, IllegalArgumentException);
-      return;
-    }
-}
-
-/**
-  * Throw java.util.zip.DataFormatException
-  */
-void
-throwNewDataFormatException (JNIEnv * env, const char *message)
-{
-  jniThrowException(env, "java/util/zip/DataFormatException", message);
-}
-
-JNIEXPORT jlong JNICALL
-Java_java_util_zip_Inflater_getTotalOutImpl (JNIEnv * env, jobject recv,
-                                             jlong handle)
-{
-  JCLZipStream *stream;
-
-  stream = (JCLZipStream *) ((IDATA) handle);
-  return stream->stream->total_out;
-
-}
-
-JNIEXPORT jlong JNICALL
-Java_java_util_zip_Inflater_getTotalInImpl (JNIEnv * env, jobject recv,
-                                            jlong handle)
-{
-  JCLZipStream *stream;
-
-  stream = (JCLZipStream *) ((IDATA) handle);
-  return stream->stream->total_in;
-}
-
-JNIEXPORT void JNICALL
-Java_java_util_zip_Inflater_oneTimeInitialization (JNIEnv * env, jclass clazz)
-{
-    memset(&gCachedFields, 0, sizeof(gCachedFields));
-    gCachedFields.inRead = (*env)->GetFieldID (env, clazz, "inRead", "I");
-    gCachedFields.finished = (*env)->GetFieldID (env, clazz, "finished", "Z");
-    gCachedFields.needsDictionary = (*env)->GetFieldID (env, clazz, "needsDictionary", "Z");
-}
-
-static JNINativeMethod gMethods[] = {
-    { "createStream", "(Z)J",     Java_java_util_zip_Inflater_createStream },
-    { "setInputImpl", "([BIIJ)V",     Java_java_util_zip_Inflater_setInputImpl },
-    { "setFileInputImpl", "(Ljava/io/FileDescriptor;JIJ)I",     Java_java_util_zip_Inflater_setFileInputImpl },
-    { "inflateImpl", "([BIIJ)I",     Java_java_util_zip_Inflater_inflateImpl },
-    { "getAdlerImpl", "(J)I",     Java_java_util_zip_Inflater_getAdlerImpl },
-    { "endImpl", "(J)V",     Java_java_util_zip_Inflater_endImpl },
-    { "setDictionaryImpl", "([BIIJ)V",     Java_java_util_zip_Inflater_setDictionaryImpl },
-    { "resetImpl", "(J)V",     Java_java_util_zip_Inflater_resetImpl },
-    { "getTotalOutImpl", "(J)J",     Java_java_util_zip_Inflater_getTotalOutImpl },
-    { "getTotalInImpl", "(J)J",     Java_java_util_zip_Inflater_getTotalInImpl },
-    { "oneTimeInitialization", "()V",     Java_java_util_zip_Inflater_oneTimeInitialization },
-};
-int register_java_util_zip_Inflater(JNIEnv* env) {
-    return jniRegisterNativeMethods(env, "java/util/zip/Inflater", gMethods, NELEM(gMethods));
-}
diff --git a/luni/src/main/native/java_util_zip_Inflater.cpp b/luni/src/main/native/java_util_zip_Inflater.cpp
new file mode 100644
index 0000000..77e9aa3
--- /dev/null
+++ b/luni/src/main/native/java_util_zip_Inflater.cpp
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 "zip.h"
+
+static struct {
+    jfieldID inRead;
+    jfieldID finished;
+    jfieldID needsDictionary;
+} gCachedFields;
+
+/* Create a new stream . This stream cannot be used until it has been properly initialized. */
+static jlong Inflater_createStream(JNIEnv* env, jobject, jboolean noHeader) {
+    UniquePtr<NativeZipStream> jstream(new NativeZipStream);
+    if (jstream.get() == NULL) {
+        jniThrowOutOfMemoryError(env, NULL);
+        return -1;
+    }
+    jstream->stream.adler = 1;
+
+    /*
+     * In the range 8..15 for checked, or -8..-15 for unchecked inflate. Unchecked
+     * is appropriate for formats like zip that do their own validity checking.
+     */
+    /* Window bits to use. 15 is fastest but consumes the most memory */
+    int wbits = 15;               /*Use MAX for fastest */
+    if (noHeader) {
+        wbits = wbits / -1;
+    }
+    int err = inflateInit2(&jstream->stream, wbits);
+    if (err != Z_OK) {
+        throwExceptionForZlibError(env, "java/lang/IllegalArgumentException", err);
+        return -1;
+    }
+    return reinterpret_cast<uintptr_t>(jstream.release());
+}
+
+static void Inflater_setInputImpl(JNIEnv* env, jobject, jbyteArray buf, jint off, jint len, jlong handle) {
+    toNativeZipStream(handle)->setInput(env, buf, off, len);
+}
+
+static jint Inflater_setFileInputImpl(JNIEnv* env, jobject, jobject javaFileDescriptor, jlong off, jint len, jlong handle) {
+    NativeZipStream* stream = toNativeZipStream(handle);
+    if (stream->inCap < len) {
+        stream->setInput(env, NULL, 0, len);
+    }
+    // TODO: is it okay to be this sloppy about errors?
+    int fd = jniGetFDFromFileDescriptor(env, javaFileDescriptor);
+    lseek(fd, off, SEEK_SET);
+    return read(fd, &stream->input[0], len);
+}
+
+static jint Inflater_inflateImpl(JNIEnv* env, jobject recv, jbyteArray buf, int off, int len, jlong handle) {
+    jfieldID fid2 = 0;
+
+    /* We need to get the number of bytes already read */
+    jfieldID fid = gCachedFields.inRead;
+    jint inBytes = env->GetIntField(recv, fid);
+
+    NativeZipStream* stream = toNativeZipStream(handle);
+    stream->stream.avail_out = len;
+    jint sin = stream->stream.total_in;
+    jint sout = stream->stream.total_out;
+    jbyte* out = (jbyte*) env->GetPrimitiveArrayCritical(buf, 0);
+    if (out == NULL) {
+        jniThrowOutOfMemoryError(env, NULL);
+        return -1;
+    }
+    stream->stream.next_out = (Bytef *) out + off;
+    int err = inflate(&stream->stream, Z_SYNC_FLUSH);
+    env->ReleasePrimitiveArrayCritical(buf, out, 0);
+
+    if (err != Z_OK) {
+        if (err == Z_STREAM_ERROR) {
+            return 0;
+        }
+        if (err == Z_STREAM_END || err == Z_NEED_DICT) {
+            env->SetIntField(recv, fid, (jint) stream->stream.total_in - sin + inBytes);
+            if (err == Z_STREAM_END) {
+                fid2 = gCachedFields.finished;
+            } else {
+                fid2 = gCachedFields.needsDictionary;
+            }
+            env->SetBooleanField(recv, fid2, JNI_TRUE);
+            return stream->stream.total_out - sout;
+        } else {
+            throwExceptionForZlibError(env, "java/util/zip/DataFormatException", err);
+            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(recv, fid, (jint) stream->stream.total_in - sin + inBytes);
+    return stream->stream.total_out - sout;
+}
+
+static jint Inflater_getAdlerImpl(JNIEnv* env, jobject, jlong handle) {
+    return toNativeZipStream(handle)->stream.adler;
+}
+
+static void Inflater_endImpl(JNIEnv* env, jobject, jlong handle) {
+    NativeZipStream* stream = toNativeZipStream(handle);
+    inflateEnd(&stream->stream);
+    delete stream;
+}
+
+static void Inflater_setDictionaryImpl(JNIEnv* env, jobject, jbyteArray dict, int off, int len, jlong handle) {
+    toNativeZipStream(handle)->setDictionary(env, dict, off, len, true);
+}
+
+static void Inflater_resetImpl(JNIEnv* env, jobject, jlong handle) {
+    int err = inflateReset(&toNativeZipStream(handle)->stream);
+    if (err != Z_OK) {
+        throwExceptionForZlibError(env, "java/lang/IllegalArgumentException", err);
+    }
+}
+
+static jlong Inflater_getTotalOutImpl(JNIEnv* env, jobject, jlong handle) {
+    return toNativeZipStream(handle)->stream.total_out;
+}
+
+static jlong Inflater_getTotalInImpl(JNIEnv* env, jobject, jlong handle) {
+    return toNativeZipStream(handle)->stream.total_in;
+}
+
+static void Inflater_oneTimeInitialization(JNIEnv * env, jclass clazz) {
+    memset(&gCachedFields, 0, sizeof(gCachedFields));
+    gCachedFields.inRead = env->GetFieldID(clazz, "inRead", "I");
+    gCachedFields.finished = env->GetFieldID(clazz, "finished", "Z");
+    gCachedFields.needsDictionary = env->GetFieldID(clazz, "needsDictionary", "Z");
+}
+
+static JNINativeMethod gMethods[] = {
+    { "createStream", "(Z)J", (void*) Inflater_createStream },
+    { "setInputImpl", "([BIIJ)V", (void*) Inflater_setInputImpl },
+    { "setFileInputImpl", "(Ljava/io/FileDescriptor;JIJ)I", (void*) Inflater_setFileInputImpl },
+    { "inflateImpl", "([BIIJ)I", (void*) Inflater_inflateImpl },
+    { "getAdlerImpl", "(J)I", (void*) Inflater_getAdlerImpl },
+    { "endImpl", "(J)V", (void*) Inflater_endImpl },
+    { "setDictionaryImpl", "([BIIJ)V", (void*) Inflater_setDictionaryImpl },
+    { "resetImpl", "(J)V", (void*) Inflater_resetImpl },
+    { "getTotalOutImpl", "(J)J", (void*) Inflater_getTotalOutImpl },
+    { "getTotalInImpl", "(J)J", (void*) Inflater_getTotalInImpl },
+    { "oneTimeInitialization", "()V", (void*) Inflater_oneTimeInitialization },
+};
+int register_java_util_zip_Inflater(JNIEnv* env) {
+    return jniRegisterNativeMethods(env, "java/util/zip/Inflater", gMethods, NELEM(gMethods));
+}
diff --git a/luni/src/main/native/sieb.c b/luni/src/main/native/sieb.c
deleted file mode 100644
index 4529307..0000000
--- a/luni/src/main/native/sieb.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * 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 "sieb.h"
-#include "JNIHelp.h"
-#include "jni.h"
-
-#include <stdlib.h>
-
-// Throw java.lang.OutOfMemoryError
-void throwNewOutOfMemoryError(JNIEnv *env, const char *message) {
-    jniThrowException(env, "java/lang/OutOfMemoryError", message);
-}
-
-void *sieb_malloc(JNIEnv *env, size_t byteCnt) {
-    void *adr = malloc(byteCnt);
-    if (adr == 0) {
-        if (byteCnt == 0) {
-            throwNewOutOfMemoryError(env, "sieb_malloc(0) NOT ALLOWED");
-        } else {
-            throwNewOutOfMemoryError(env, "sieb_malloc");
-        }
-    }
-    return adr;
-}
-
-void sieb_free(JNIEnv *env, void *adr) {
-    free(adr);
-}
-
-void sieb_convertToPlatform(char *path) {
-    char *pathIndex;
-
-    pathIndex = path;
-    while (*pathIndex != '\0') {
-        if (*pathIndex == '\\') {
-            *pathIndex = '/';
-        }
-        pathIndex++;
-    }
-}
diff --git a/luni/src/main/native/sieb.h b/luni/src/main/native/sieb.h
deleted file mode 100644
index c32da04..0000000
--- a/luni/src/main/native/sieb.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * 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(sieb_h)
-#define sieb_h
-
-#include "JNIHelp.h"
-#include "jni.h"
-
-void throwNewOutOfMemoryError(JNIEnv *env, const char *message);
-void *sieb_malloc(JNIEnv *env, size_t byteCnt);
-void sieb_free(JNIEnv *env, void *adr);
-void sieb_convertToPlatform(char *path);
-
-#endif /* sieb_h */
diff --git a/luni/src/main/native/sub.mk b/luni/src/main/native/sub.mk
index cf71bcf..513171c 100644
--- a/luni/src/main/native/sub.mk
+++ b/luni/src/main/native/sub.mk
@@ -3,6 +3,20 @@
 # or BUILD_*_LIBRARY.
 
 LOCAL_SRC_FILES := \
+	BidiWrapper.cpp \
+	ErrorCode.cpp \
+	ICU.cpp \
+	NativeBreakIterator.cpp \
+	NativeCollation.cpp \
+	NativeConverter.cpp \
+	NativeDecimalFormat.cpp \
+	NativeIDN.cpp \
+	NativeNormalizer.cpp \
+	NativeRegEx.cpp \
+	Register.cpp \
+	UCharacter.cpp \
+	cbigint.c \
+	commonDblParce.c \
 	java_io_Console.cpp \
 	java_io_File.cpp \
 	java_io_FileDescriptor.c \
@@ -12,45 +26,28 @@
 	java_lang_Double.c \
 	java_lang_Float.c \
 	java_lang_Math.c \
-        java_lang_ProcessManager.cpp \
+	java_lang_ProcessManager.cpp \
 	java_lang_StrictMath.c \
-        java_lang_System.cpp \
+	java_lang_System.cpp \
 	java_net_InetAddress.cpp \
 	java_net_NetworkInterface.cpp \
-	java_util_zip_Adler32.c \
-	java_util_zip_CRC32.c \
-	java_util_zip_Deflater.c \
-	java_util_zip_Inflater.c \
-	cbigint.c \
-	commonDblParce.c \
-	org_apache_harmony_luni_util_fltparse.c \
-	org_apache_harmony_luni_util_NumberConvert.c \
-	org_apache_harmony_luni_platform_OSNetworkSystem.cpp \
+	java_util_zip_Adler32.cpp \
+	java_util_zip_CRC32.cpp \
+	java_util_zip_Deflater.cpp \
+	java_util_zip_Inflater.cpp \
 	org_apache_harmony_luni_platform_OSFileSystem.cpp \
 	org_apache_harmony_luni_platform_OSMemory.cpp \
+	org_apache_harmony_luni_platform_OSNetworkSystem.cpp \
+	org_apache_harmony_luni_util_NumberConvert.c \
+	org_apache_harmony_luni_util_fltparse.c \
 	org_apache_harmony_xml_ExpatParser.cpp \
-	org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp \
-	zip.c \
-	zipalloc.c \
-	sieb.c \
-        BidiWrapper.cpp \
-        ErrorCode.cpp \
-        ICU.cpp \
-        NativeBreakIterator.cpp \
-        NativeCollation.cpp \
-        NativeConverter.cpp \
-        NativeDecimalFormat.cpp \
-        NativeIDN.cpp \
-        NativeNormalizer.cpp \
-        NativeRegEx.cpp \
-        Register.cpp \
-        UCharacter.cpp
+	org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp
 
 
 LOCAL_C_INCLUDES += \
 	external/expat/lib \
-        external/icu4c/common \
-        external/icu4c/i18n \
+	external/icu4c/common \
+	external/icu4c/i18n \
 	external/openssl/include \
 	external/zlib
 
@@ -61,11 +58,11 @@
 LOCAL_SHARED_LIBRARIES += \
 	libcrypto \
 	libcutils \
-        libexpat \
-        libicudata \
-        libicuuc \
-        libicui18n \
-        libssl \
+	libexpat \
+	libicudata \
+	libicuuc \
+	libicui18n \
+	libssl \
 	libutils \
 	libz
 
diff --git a/luni/src/main/native/zip.c b/luni/src/main/native/zip.c
deleted file mode 100644
index 3d15d2a..0000000
--- a/luni/src/main/native/zip.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 "zip.h"
-#include "jni.h"
-
-/**
-  * Throw java.lang.IllegalStateException
-  */
-void
-throwNewIllegalStateException (JNIEnv * env, const char *message)
-{
-  jniThrowException(env, "java/lang/IllegalStateException", message);
-}
-
-/**
-  * Throw java.lang.IllegalArgumentException
-  */
-void
-throwNewIllegalArgumentException (JNIEnv * env, const char *message)
-{
-  jniThrowException(env, "java/lang/IllegalArgumentException", message);
-}
diff --git a/luni/src/main/native/zip.h b/luni/src/main/native/zip.h
index 1452073..6a4c201 100644
--- a/luni/src/main/native/zip.h
+++ b/luni/src/main/native/zip.h
@@ -1,13 +1,13 @@
-/* 
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You 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.
@@ -18,53 +18,85 @@
 #if !defined(zip_h)
 #define zip_h
 
-#ifndef HY_ZIP_API
-#include "zipsup.h"
-#else /* HY_ZIP_API */
-#include "vmizip.h"
-#endif /* HY_ZIP_API */
+#include "JNIHelp.h"
+#include "UniquePtr.h"
+#include "jni.h"
+#include "zlib.h"
 
-#include "hymutex.h"
+// FIXME: move to JNIHelp.h
+static void jniThrowOutOfMemoryError(JNIEnv* env, const char* message) {
+    jniThrowException(env, "java/lang/OutOfMemoryError", message);
+}
 
-typedef struct JCLZipFile
-{
-  struct JCLZipFile *last;
-  struct JCLZipFile *next;
-#ifndef HY_ZIP_API
-  HyZipFile hyZipFile;
-#else
-  VMIZipFile hyZipFile;
-#endif
-} JCLZipFile;
+static void throwExceptionForZlibError(JNIEnv* env, const char* exceptionClassName, int error) {
+    if (error == Z_MEM_ERROR) {
+        jniThrowOutOfMemoryError(env, NULL);
+    } else {
+        jniThrowException(env, exceptionClassName, zError(error));
+    }
+}
 
-/* Fake JCLZipFile entry. last, next must be in the same position as JCLZipFile */
-typedef struct JCLZipFileLink
-{
-  JCLZipFile *last;
-  JCLZipFile *next;
-  MUTEX mutex;
-} JCLZipFileLink;
+class NativeZipStream {
+public:
+    UniquePtr<jbyte[]> input;
+    int inCap;
+    z_stream stream;
 
-// Contents from Harmony's inflater.h was put here:
-//
-typedef struct JCLZipStream
-{
-  U_8 *inaddr;
-  int inCap;
-  U_8 *dict;
-  z_stream *stream;
-} JCLZipStream;
+    NativeZipStream() : input(NULL), inCap(0), mDict(NULL) {
+        // Let zlib use its default allocator.
+        stream.opaque = Z_NULL;
+        stream.zalloc = Z_NULL;
+        stream.zfree = Z_NULL;
+    }
 
-#define THROW_ZIP_EXCEPTION(env, err, type)            \
-  if (err == Z_MEM_ERROR) {                            \
-    throwNewOutOfMemoryError(env, "");                 \
-  } else {                                             \
-    throwNew##type(env, (const char*) zError(err));    \
-  }
+    ~NativeZipStream() {
+    }
 
-void throwNewIllegalStateException PROTOTYPE((JNIEnv* env,
-                                              const char* message));
-void throwNewIllegalArgumentException PROTOTYPE((JNIEnv* env,
-                                                 const char* message));
+    void setDictionary(JNIEnv* env, jbyteArray dict, int off, int len, bool inflate) {
+        UniquePtr<jbyte[]> dBytes(new jbyte[len]);
+        if (dBytes.get() == NULL) {
+            jniThrowOutOfMemoryError(env, NULL);
+            return;
+        }
+        env->GetByteArrayRegion(dict, off, len, &dBytes[0]);
+        int err;
+        if (inflate) {
+            err = inflateSetDictionary(&stream, (Bytef *) &dBytes[0], len);
+        } else {
+            err = deflateSetDictionary(&stream, (Bytef *) &dBytes[0], len);
+        }
+        if (err != Z_OK) {
+            throwExceptionForZlibError(env, "java/lang/IllegalArgumentException", err);
+            return;
+        }
+        mDict.reset(dBytes.release());
+    }
+
+    void setInput(JNIEnv* env, jbyteArray buf, jint off, jint len) {
+        input.reset(new jbyte[len]);
+        if (input.get() == NULL) {
+            inCap = 0;
+            jniThrowOutOfMemoryError(env, NULL);
+            return;
+        }
+        inCap = len;
+        if (buf != NULL) {
+            env->GetByteArrayRegion(buf, off, len, &input[0]);
+        }
+        stream.next_in = (Bytef *) &input[0];
+        stream.avail_in = len;
+    }
+
+private:
+    UniquePtr<jbyte[]> mDict;
+
+    // Disallow copy and assignment.
+    NativeZipStream(const NativeZipStream&);
+    void operator=(const NativeZipStream&);
+};
+
+static NativeZipStream* toNativeZipStream(jlong address) {
+    return reinterpret_cast<NativeZipStream*>(static_cast<uintptr_t>(address));
+}
 
 #endif /* zip_h */
diff --git a/luni/src/main/native/zipalloc.c b/luni/src/main/native/zipalloc.c
deleted file mode 100644
index 2b4966b..0000000
--- a/luni/src/main/native/zipalloc.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 "hyport.h"
-
-#include "zlib.h"
-
-#define CDEV_CURRENT_FUNCTION _prototypes_private
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION _prototypes_public
-void *zalloc PROTOTYPE ((void *opaque, U_32 items, U_32 size));
-void zfree PROTOTYPE ((void *opaque, void *address));
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zalloc
-
-/*
-	ZLib interface to hymem_allocate_memory.
-*/
-void *
-zalloc (void *opaque, U_32 items, U_32 size)
-{
-  PORT_ACCESS_FROM_PORT (((HyPortLibrary *) opaque));
-
-  return hymem_allocate_memory (items * size);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zfree
-
-/*
-	ZLib interface to hymem_free_memory.
-*/
-void
-zfree (void *opaque, void *address)
-{
-  PORT_ACCESS_FROM_PORT ((HyPortLibrary *) opaque);
-
-  hymem_free_memory (address);
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION
-
-#undef CDEV_CURRENT_FUNCTION
diff --git a/luni/src/main/native/zipsup.c b/luni/src/main/native/zipsup.c
deleted file mode 100644
index d6d07da..0000000
--- a/luni/src/main/native/zipsup.c
+++ /dev/null
@@ -1,2319 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * @file
- * @ingroup ZipSupport
- * @brief Zip Support for Java VM
-*/
-
-#include <string.h>
-#include <sys/stat.h>
-
-#include "hy2sie.h"
-#include "zipsup.h"
-
-#include "zlib.h"
-
-// zlib is statically linked for Android:
-#define checkZipLibrary(dummy) 0
-#ifdef checkZipLibrary
-#define inflateInit2Func(a, b, c, d) inflateInit2_ (a, b, c, d)
-#define inflateFunc(a, b) inflate (a, b)
-#define inflateEndFunc(a) inflateEnd (a)
-#else
-/* Globals for the zip library */
-UDATA zipDLLDescriptor = 0;
-int (*inflateInit2Func) (void *, int, const char *, int);
-int (*inflateFunc) (void *, int);
-int (*inflateEndFunc) (void *);
-#endif
-
-#define ZIP_NEXT_U8(value, index) (value = *(index++))
-#define ZIP_NEXT_U16(value, index) ((value = (index[1] << 8) | index[0]), index += 2, value)
-#define ZIP_NEXT_U32(value, index) ((value = ((U_32)index[3] << 24) | ((U_32)index[2] << 16) | ((U_32)index[1] << 8) | (U_32)index[0]), index += 4, value)
-
-#define WORK_BUFFER_SIZE 64000
-
-#define SCAN_CHUNK_SIZE 1024
-
-struct workBuffer
-{
-  HyPortLibrary *portLib;
-  UDATA *bufferStart;
-  UDATA *bufferEnd;
-  UDATA *currentAlloc;
-  UDATA cntr;
-};
-
-#define CDEV_CURRENT_FUNCTION _prototypes_private
-I_32 zip_populateCache
-PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile));
-
-static I_32 inflateData
-PROTOTYPE ((struct workBuffer * workBuf, U_8 * inputBuffer,
-            U_32 inputBufferSize, U_8 * outputBuffer, U_32 outputBufferSize));
-
-I_32 checkZipLibrary PROTOTYPE ((HyPortLibrary * portLib));
-
-I_32 scanForDataDescriptor
-PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile,
-            HyZipEntry * zipEntry));
-void zdatafree PROTOTYPE ((void *opaque, void *address));
-static I_32 readZipEntry
-PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile,
-            HyZipEntry * zipEntry, const char *filename,
-            IDATA * enumerationPointer, IDATA * entryStart,
-            BOOLEAN findDirectory));
-I_32 scanForCentralEnd
-PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile,
-            HyZipCentralEnd * endEntry));
-void *zdataalloc PROTOTYPE ((void *opaque, U_32 items, U_32 size));
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION _prototypes_public
-I_32 zip_getZipEntryData
-PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile, HyZipEntry * entry,
-            U_8 * buffer, U_32 bufferSize));
-I_32 zip_getZipEntryFromOffset
-PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile, HyZipEntry * entry,
-            IDATA offset));
-I_32 zip_establishCache
-PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile));
-void zip_resetZipFile
-PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile,
-            IDATA * nextEntryPointer));
-I_32 zip_getNextZipEntry
-PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile,
-            HyZipEntry * zipEntry, IDATA * nextEntryPointer));
-I_32 zip_getZipEntry
-PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile, HyZipEntry * entry,
-            const char *filename, BOOLEAN findDirectory));
-I_32 zip_getZipEntryExtraField
-PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile, HyZipEntry * entry,
-            U_8 * buffer, U_32 bufferSize));
-void zip_initZipEntry
-PROTOTYPE ((HyPortLibrary * portLib, HyZipEntry * entry));
-I_32 zip_openZipFile
-PROTOTYPE ((HyPortLibrary * portLib, char *filename, HyZipFile * zipFile,
-            HyZipCachePool * cachePool));
-void zip_freeZipEntry
-PROTOTYPE ((HyPortLibrary * portLib, HyZipEntry * entry));
-I_32 VMCALL zip_closeZipFile
-PROTOTYPE ((HyPortLibrary * portLib, struct HyZipFile * zipFile));
-I_32 zip_getZipEntryComment
-PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile, HyZipEntry * entry,
-            U_8 * buffer, U_32 bufferSize));
-
-#undef CDEV_CURRENT_FUNCTION
-
-//#include "hythread.h"
-//#define ENTER() hythread_monitor_enter(hythread_global_monitor())
-//#define EXIT() hythread_monitor_exit(hythread_global_monitor())
-
-#include "hymutex.h"
-MUTEX zip_globalMutex;
-static int initialized = 0;
-
-#define ENTER() \
-  if (!initialized) { MUTEX_INIT(zip_globalMutex); initialized = 1; } \
-  MUTEX_ENTER(zip_globalMutex);
-
-#define EXIT() MUTEX_EXIT(zip_globalMutex);
-
-
-HyZipCachePool *
-zipsup_GetZipCachePool(JNIEnv * env)
-{
-  static HyZipCachePool *pool = 0;
-
-  if (pool == 0) {
-    pool = zipCachePool_new(env);
-  }
-  return pool;
-}
-
-
-#ifndef checkZipLibrary
-#define CDEV_CURRENT_FUNCTION checkZipLibrary
-
-/*
-	Ensure that the zip library is loaded.
-	Return 0 on success, -1 on failure.
-*/
-I_32
-checkZipLibrary (HyPortLibrary * portLib)
-{
-  PORT_ACCESS_FROM_PORT (portLib);
-
-  /* if the library has already been loaded return success/failure */
-  if (zipDLLDescriptor > 1)
-    return 0;
-  if (zipDLLDescriptor == 1)
-    return -1;
-
-  /* open up the zip library by name */
-
-  if (hysl_open_shared_library (HY_ZIP_DLL_NAME, &zipDLLDescriptor, TRUE))
-    goto openFailed;
-
-  /* look up the functions */
-  if (hysl_lookup_name
-      (zipDLLDescriptor, "inflateInit2_", (void *) &inflateInit2Func,
-       "ILILI"))
-    goto loadFailed;
-  if (hysl_lookup_name
-      (zipDLLDescriptor, "inflate", (void *) &inflateFunc, "IPI"))
-    goto loadFailed;
-  if (hysl_lookup_name
-      (zipDLLDescriptor, "inflateEnd", (void *) &inflateEndFunc, "IP"))
-    goto loadFailed;
-
-  /* good to go */
-  return 0;
-
-loadFailed:
-  hysl_close_shared_library (zipDLLDescriptor);
-
-  /* mark the descriptor as a failed load. only report the error once */
-  zipDLLDescriptor = 1;
-
-  /* Unable to open %s (Missing export) */
-  hynls_printf (PORTLIB, HYNLS_WARNING, HYNLS_ZIP_MISSING_EXPORT,
-                HY_ZIP_DLL_NAME);
-
-  return -1;
-
-openFailed:
-  /* mark the descriptor as a failed load. only report the error once */
-  zipDLLDescriptor = 1;
-
-  /* Unable to open %s (%s) */
-  hynls_printf (PORTLIB, HYNLS_WARNING, HYNLS_ZIP_UNABLE_TO_OPEN_ZIP_DLL,
-                HY_ZIP_DLL_NAME, hyerror_last_error_message ());
-  return -1;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-#endif
-
-#define CDEV_CURRENT_FUNCTION inflateData
-
-/*
-	Returns 0 on success or one of the following:
-			ZIP_ERR_UNSUPPORTED_FILE_TYPE
-			ZIP_ERR_FILE_CORRUPT
-			ZIP_ERR_OUT_OF_MEMORY
-			ZIP_ERR_INTERNAL_ERROR
-*/
-static I_32
-inflateData (struct workBuffer *workBuf, U_8 * inputBuffer,
-             U_32 inputBufferSize, U_8 * outputBuffer, U_32 outputBufferSize)
-{
-  PORT_ACCESS_FROM_PORT (workBuf->portLib);
-
-  z_stream stream;
-  I_32 err;
-
-  stream.next_in = inputBuffer;
-  stream.avail_in = inputBufferSize;
-  stream.next_out = outputBuffer;
-  stream.avail_out = outputBufferSize;
-
-  stream.opaque = workBuf;
-  stream.zalloc = zdataalloc;
-  stream.zfree = zdatafree;
-
-  /* Initialize stream. Pass "-15" as max number of window bits, negated
-     to indicate that no zlib header is present in the data. */
-  err = inflateInit2Func (&stream, -15, ZLIB_VERSION, sizeof (z_stream));
-  if (err != Z_OK)
-    return -1;
-
-  /* Inflate the data. */
-  err = inflateFunc (&stream, Z_SYNC_FLUSH);
-
-  /* Clean up the stream. */
-  inflateEndFunc (&stream);
-
-  /* Check the return code. Did we complete the inflate? */
-  if ((err == Z_STREAM_END) || (err == Z_OK))
-    {
-      if (stream.total_out == outputBufferSize)
-        {
-          return 0;
-        }
-    }
-
-  switch (err)
-    {
-    case Z_OK:                 /* an error if file is incomplete */
-    case Z_STREAM_END:         /* an error if file is incomplete */
-    case Z_ERRNO:              /* a random error */
-    case Z_STREAM_ERROR:       /* stream inconsistent */
-    case Z_DATA_ERROR:         /* corrupted zip */
-      return ZIP_ERR_FILE_CORRUPT;
-
-    case Z_VERSION_ERROR:      /* wrong zlib version */
-    case Z_NEED_DICT:          /* needs a preset dictionary that we can't provide */
-      return ZIP_ERR_UNSUPPORTED_FILE_TYPE;
-
-    case Z_MEM_ERROR:          /* out of memory */
-      return ZIP_ERR_OUT_OF_MEMORY;
-
-    case Z_BUF_ERROR:          /* no progress / out of output buffer */
-    default:                   /* jic */
-      return ZIP_ERR_INTERNAL_ERROR;
-    }
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION scanForCentralEnd
-/*
-	Scan backward from end of file for a central end header. Read from zipFile and update the HyZipCentralEnd provided.
-
-	Returns 0 on success or one of the following:
-			ZIP_ERR_FILE_READ_ERROR
-			ZIP_ERR_FILE_CORRUPT
-*/
-I_32
-scanForCentralEnd (HyPortLibrary * portLib, HyZipFile * zipFile,
-                   HyZipCentralEnd * endEntry)
-{
-  U_8 *current;
-  U_8 buffer[SCAN_CHUNK_SIZE];
-  I_32 i, size, state;
-  U_32 dataSize = 0;
-  I_64 seekResult;
-  I_32 fileSize;
-  I_32 bytesAlreadyRead = 0;
-
-  PORT_ACCESS_FROM_PORT (portLib);
-
-  /* Haven't seen anything yet. */
-  state = 0;
-
-  seekResult = hyfile_seek (zipFile->fd, 0, HySeekEnd);
-  if ((seekResult < 0) || (seekResult > HYCONST64 (0x7FFFFFFF)))
-    {
-      zipFile->pointer = -1;
-      return ZIP_ERR_FILE_READ_ERROR;
-    }
-  fileSize = (I_32) seekResult;
-  zipFile->pointer = fileSize;
-
-  while (TRUE)
-    {
-      /* Fill the buffer. */
-      if (bytesAlreadyRead == fileSize)
-        {
-          zipFile->pointer = -1;
-          return ZIP_ERR_FILE_CORRUPT;
-        }
-
-      size = SCAN_CHUNK_SIZE;
-      if (size > fileSize - bytesAlreadyRead)
-        size = fileSize - bytesAlreadyRead;
-      bytesAlreadyRead += size;
-      seekResult =
-        hyfile_seek (zipFile->fd, fileSize - bytesAlreadyRead, HySeekSet);
-      if ((seekResult < 0) || (seekResult > HYCONST64 (0x7FFFFFFF)))
-        {
-          zipFile->pointer = -1;
-          return ZIP_ERR_FILE_READ_ERROR;
-        }
-      zipFile->pointer = (I_32) seekResult;
-
-      if (hyfile_read (zipFile->fd, buffer, size) != size)
-        {
-          zipFile->pointer = -1;
-          return ZIP_ERR_FILE_READ_ERROR;
-        }
-      zipFile->pointer += size;
-
-      /* Scan the buffer (backwards) for CentralEnd signature = PK^E^F. */
-      for (i = size; i--; dataSize++)
-        {
-          switch (state)
-            {
-            case 0:
-              /* Nothing yet. */
-              if (buffer[i] == 6)
-                state = 1;
-              break;
-
-            case 1:
-              /* Seen ^F */
-              if (buffer[i] == 5)
-                state = 2;
-              else
-                state = 0;
-              break;
-
-            case 2:
-              /* Seen ^E^F */
-              if (buffer[i] == 'K')
-                state = 3;
-              else
-                state = 0;
-              break;
-
-            case 3:
-              /* Seen K^E^F */
-              if (buffer[i] == 'P' && dataSize >= 21)
-                {
-                  /* Found it.  Read the data from the end-of-central-dir record. */
-                  current = buffer + i + 4;
-                  (void) ZIP_NEXT_U16 (endEntry->diskNumber, current);
-                  (void) ZIP_NEXT_U16 (endEntry->dirStartDisk, current);
-                  (void) ZIP_NEXT_U16 (endEntry->thisDiskEntries, current);
-                  (void) ZIP_NEXT_U16 (endEntry->totalEntries, current);
-                  (void) ZIP_NEXT_U32 (endEntry->dirSize, current);
-                  (void) ZIP_NEXT_U32 (endEntry->dirOffset, current);
-                  (void) ZIP_NEXT_U16 (endEntry->commentLength, current);
-
-                  /* Quick test to ensure that the header isn't invalid. 
-                     Current dataSize is the number of bytes of data scanned, up to the ^H in the stream. */
-                  if (dataSize >= (U_32) (21 + endEntry->commentLength))
-                    return 0;
-
-                  /* Header looked invalid. Pretend we didn't see it and keep scanning.. */
-                }
-              state = 0;
-              break;
-            }
-        }
-    }
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION scanForDataDescriptor
-/*
-	Scan ahead for a data descriptor. Read from zipFile and update the HyZipLocalHeader provided.
-
-	Returns 0 on success or one of the following:
-			ZIP_ERR_FILE_READ_ERROR
-			ZIP_ERR_FILE_CORRUPT
-*/
-I_32
-scanForDataDescriptor (HyPortLibrary * portLib, HyZipFile * zipFile,
-                       HyZipEntry * zipEntry)
-{
-  U_8 *current;
-  U_8 buffer[SCAN_CHUNK_SIZE], descriptor[16];
-  I_32 i, size, state;
-  U_32 dataSize, blockPointer;
-  I_64 seekResult;
-
-  PORT_ACCESS_FROM_PORT (portLib);
-
-  /* Skip ahead and read the data descriptor. The compressed size should be 0. */
-  if (zipFile->pointer !=
-      (IDATA) (zipEntry->dataPointer + zipEntry->compressedSize))
-    {
-      seekResult =
-        hyfile_seek (zipFile->fd,
-                     zipEntry->dataPointer + zipEntry->compressedSize,
-                     HySeekSet);
-      if ((seekResult < 0) || (seekResult > HYCONST64 (0x7FFFFFFF)))
-        {
-          zipFile->pointer = -1;
-          return ZIP_ERR_FILE_READ_ERROR;
-        }
-      zipFile->pointer = (I_32) seekResult;
-    }
-
-  /* Haven't seen anything yet. */
-  blockPointer = dataSize = zipEntry->compressedSize;
-  state = 0;
-
-  /* Scan until we find PK^G^H (otherwise it's an error). */
-  while (1)
-    {
-      /* Fill the buffer. */
-      size = hyfile_read (zipFile->fd, buffer, SCAN_CHUNK_SIZE);
-      if (size == 0)
-        {
-          return ZIP_ERR_FILE_CORRUPT;
-        }
-      else if (size < 0)
-        {
-          zipFile->pointer = -1;
-          return ZIP_ERR_FILE_READ_ERROR;
-        }
-      zipFile->pointer += size;
-      blockPointer += size;
-
-      /* Scan the buffer. */
-      for (i = 0; i < size; i++, dataSize++)
-        {
-          switch (state)
-            {
-            case 0:
-              /* Nothing yet. */
-              if (buffer[i] == 'P')
-                {
-                  state = 1;
-                }
-              break;
-
-            case 1:
-              /* Seen P */
-              if (buffer[i] == 'K')
-                {
-                  state = 2;
-                }
-              else
-                state = 0;
-              break;
-
-            case 2:
-              /* Seen PK */
-              if (buffer[i] == 7)
-                {
-                  state = 3;
-                }
-              else
-                {
-                  state = 0;
-                }
-              break;
-
-            case 3:
-              /* Seen PK^G */
-              if (buffer[i] == 8)
-                {
-                  /* Found it! Read the descriptor */
-                  if (i + 12 < size)
-                    {
-                      current = &buffer[i + 1];
-                    }
-                  else
-                    {
-                      seekResult =
-                        hyfile_seek (zipFile->fd,
-                                     zipEntry->dataPointer + dataSize + 1,
-                                     HySeekSet);
-                      if ((seekResult < 0)
-                          || (seekResult > HYCONST64 (0x7FFFFFFF)))
-                        {
-                          zipFile->pointer = -1;
-                          return ZIP_ERR_FILE_READ_ERROR;
-                        }
-                      zipFile->pointer = (I_32) seekResult;
-                      if (hyfile_read (zipFile->fd, descriptor, 12) != 12)
-                        {
-                          zipFile->pointer = -1;
-                          return ZIP_ERR_FILE_READ_ERROR;
-                        }
-                      zipFile->pointer += 12;
-                      current = descriptor;
-                    }
-
-                  /* Read the data from the descriptor. */
-                  (void) ZIP_NEXT_U32 (zipEntry->crc32, current);
-                  (void) ZIP_NEXT_U32 (zipEntry->compressedSize, current);
-                  (void) ZIP_NEXT_U32 (zipEntry->uncompressedSize, current);
-
-                  /* Quick test to ensure that the header isn't invalid. 
-                     Current dataSize is the number of bytes of data scanned, up to the ^H in the stream. */
-                  if (dataSize - 3 == zipEntry->compressedSize)
-                    {
-                      return 0;
-                    }
-
-                  /* Header looked invalid. Reset the pointer and continue scanning. */
-                  seekResult =
-                    hyfile_seek (zipFile->fd,
-                                 zipEntry->dataPointer + blockPointer,
-                                 HySeekSet);
-                  if ((seekResult < 0)
-                      || (seekResult > HYCONST64 (0x7FFFFFFF)))
-                    {
-                      zipFile->pointer = -1;
-                      return ZIP_ERR_FILE_READ_ERROR;
-                    }
-                  zipFile->pointer = (I_32) seekResult;
-                }
-              else
-                state = 0;
-              break;
-            }
-        }
-    }
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zip_populateCache
-/*
-	Fill in the cache of a given zip file.  This should only be called once during zip_openZipFile!
-
-	Returns 0 on success or one of the following:
-			ZIP_ERR_FILE_READ_ERROR
-			ZIP_ERR_FILE_OPEN_ERROR
-			ZIP_ERR_UNKNOWN_FILE_TYPE
-			ZIP_ERR_UNSUPPORTED_FILE_TYPE
-			ZIP_ERR_OUT_OF_MEMORY
-			ZIP_ERR_INTERNAL_ERROR
-*/
-I_32
-zip_populateCache (HyPortLibrary * portLib, HyZipFile * zipFile)
-{
-  PORT_ACCESS_FROM_PORT (portLib);
-
-  I_32 result = 0;
-  IDATA bufferSize = 65536;
-  IDATA unreadSize = 0;
-  IDATA bufferedSize = 0;
-  IDATA bytesToRead = 0;
-  IDATA filenameCopied;
-  HyZipEntry entry;
-  HyZipCentralEnd endEntry;
-  U_8 *buffer = NULL;
-  U_8 *filename = NULL;
-  IDATA filenameSize = 256;     /* Should be sufficient for most filenames */
-  U_8 *current;
-  U_32 sig;
-  U_32 localHeaderOffset;
-  IDATA startCentralDir;
-  I_64 seekResult;
-
-  if (!zipFile->cache)
-    return ZIP_ERR_INTERNAL_ERROR;
-
-  /* Find and read the end-of-central-dir record. */
-  result = scanForCentralEnd (portLib, zipFile, &endEntry);
-  if (result != 0)
-    return result;
-
-  unreadSize = endEntry.dirSize + 4 /* slop */ ;
-  zipFile->cache->startCentralDir = startCentralDir =
-    (IDATA) ((UDATA) endEntry.dirOffset);
-
-  if (zipFile->pointer != startCentralDir)
-    {
-      seekResult = hyfile_seek (zipFile->fd, startCentralDir, HySeekSet);
-      if ((seekResult < 0) || (seekResult > HYCONST64 (0x7FFFFFFF)))
-        {
-          zipFile->pointer = -1;
-          result = ZIP_ERR_FILE_READ_ERROR;
-          goto finished;
-        }
-
-      zipFile->pointer = (I_32) seekResult;
-      if (zipFile->pointer != startCentralDir)
-        {
-          result = ZIP_ERR_FILE_READ_ERROR;
-          zipFile->pointer = -1;
-          goto finished;
-        }
-    }
-
-  /* No point in allocating more than we'll actually need.. */
-  if (bufferSize > unreadSize)
-    bufferSize = unreadSize;
-
-  filename = hymem_allocate_memory (filenameSize);
-  if (!filename)
-    {
-      result = ZIP_ERR_OUT_OF_MEMORY;
-      goto finished;
-    }
-
-  /* Allocate some space to hold central directory goo as we eat through it */
-  buffer = hymem_allocate_memory (bufferSize);
-  if (!buffer && (bufferSize > 4096))
-    {
-      /* Not enough memory, fall back to a smaller buffer! */
-      bufferSize = 4096;
-      buffer = hymem_allocate_memory (bufferSize);
-    }
-  if (!buffer)
-    {
-      result = ZIP_ERR_OUT_OF_MEMORY;
-      goto finished;
-    }
-
-  while (unreadSize)
-    {
-
-      /* Read as much as needed into buffer. */
-      bytesToRead = bufferSize - bufferedSize;
-      if (bytesToRead > unreadSize)
-        bytesToRead = unreadSize;
-      result = hyfile_read (zipFile->fd, buffer + bufferedSize, bytesToRead);
-      if (result < 0)
-        {
-          result = ZIP_ERR_FILE_READ_ERROR;
-          zipFile->pointer = -1;
-          goto finished;
-        }
-      zipFile->pointer += result;
-      unreadSize -= result;
-      bufferedSize += result;
-      current = buffer;
-
-      /* consume entries until we run out. */
-      while (current + 46 < buffer + bufferedSize)
-        {
-          IDATA entryPointer;
-
-          entryPointer =
-            zipFile->pointer + (current - (buffer + bufferedSize));
-
-          sig = 0;
-          (void) ZIP_NEXT_U32 (sig, current);
-          if (sig == ZIP_CentralEnd)
-            {
-              /* We're done here. */
-              result = 0;
-              goto finished;
-            }
-          if (sig != ZIP_CentralHeader)
-            {
-              /* Umm...What the Hell? */
-              result = ZIP_ERR_FILE_CORRUPT;
-              goto finished;
-            }
-
-          /* Read ZIP_CentralHeader entry */
-          (void) ZIP_NEXT_U16 (entry.versionCreated, current);
-          (void) ZIP_NEXT_U16 (entry.versionNeeded, current);
-          (void) ZIP_NEXT_U16 (entry.flags, current);
-          (void) ZIP_NEXT_U16 (entry.compressionMethod, current);
-          (void) ZIP_NEXT_U16 (entry.lastModTime, current);
-          (void) ZIP_NEXT_U16 (entry.lastModDate, current);
-          (void) ZIP_NEXT_U32 (entry.crc32, current);
-          (void) ZIP_NEXT_U32 (entry.compressedSize, current);
-          (void) ZIP_NEXT_U32 (entry.uncompressedSize, current);
-          (void) ZIP_NEXT_U16 (entry.filenameLength, current);
-          (void) ZIP_NEXT_U16 (entry.extraFieldLength, current);
-          (void) ZIP_NEXT_U16 (entry.fileCommentLength, current);
-          current += sizeof (U_16);     /* skip disk number field */
-          (void) ZIP_NEXT_U16 (entry.internalAttributes, current);
-          current += sizeof (U_32);     /* skip external attributes field */
-          (void) ZIP_NEXT_U32 (localHeaderOffset, current);
-
-          /* Increase filename buffer size if necessary. */
-          if (filenameSize < entry.filenameLength + 1)
-            {
-              hymem_free_memory (filename);
-              filenameSize = entry.filenameLength + 1;
-              filename = hymem_allocate_memory (filenameSize);
-              if (!filename)
-                {
-                  result = ZIP_ERR_OUT_OF_MEMORY;
-                  goto finished;
-                }
-            }
-
-          filenameCopied = 0;
-          while (filenameCopied < entry.filenameLength)
-            {
-              IDATA size;
-              /* Copy as much of the filename as we can see in the buffer (probably the whole thing). */
-
-              size = entry.filenameLength - filenameCopied;
-              if (size > bufferedSize - (current - buffer))
-                {
-                  size = bufferedSize - (current - buffer);
-                }
-              memcpy (filename + filenameCopied, current, size);
-              filenameCopied += size;
-              current += size;
-              if (filenameCopied >= entry.filenameLength)
-                break;          /* done */
-
-              /* Otherwise, we ran out of source string.  Load another chunk.. */
-              bufferedSize = 0;
-              if (!unreadSize)
-                {
-                  /* Central header is supposedly done?  Bak */
-                  result = ZIP_ERR_FILE_CORRUPT;
-                  goto finished;
-                }
-              bytesToRead = bufferSize - bufferedSize;
-              if (bytesToRead > unreadSize)
-                bytesToRead = unreadSize;
-              result =
-                hyfile_read (zipFile->fd, buffer + bufferedSize, bytesToRead);
-              if (result < 0)
-                {
-                  result = ZIP_ERR_FILE_READ_ERROR;
-                  zipFile->pointer = -1;
-                  goto finished;
-                }
-              zipFile->pointer += result;
-              unreadSize -= result;
-              bufferedSize += result;
-              current = buffer;
-            }
-          filename[entry.filenameLength] = '\0';        /* null-terminate */
-
-          if (((entry.compressionMethod == ZIP_CM_Deflated)
-               && (entry.flags & 0x8)) || (entry.fileCommentLength != 0))
-            {
-              /* Either local header doesn't know the compressedSize, or this entry has a file
-                 comment.  In either case, cache the central header instead of the local header
-                 so we can find the information we need later. */
-
-              result =
-                zipCache_addElement (zipFile->cache, (char *) filename,
-                                     entryPointer);
-
-            }
-          else
-            {
-              result =
-                zipCache_addElement (zipFile->cache, (char *) filename,
-                                     localHeaderOffset);
-            }
-
-          if (!result)
-            {
-              result = ZIP_ERR_OUT_OF_MEMORY;
-              goto finished;
-            }
-
-          /* Skip the data and comment. */
-          bytesToRead = entry.extraFieldLength + entry.fileCommentLength;
-          if (bufferedSize - (current - buffer) >= bytesToRead)
-            {
-              current += bytesToRead;
-            }
-          else
-            {
-              /* The rest of the buffer is uninteresting.  Skip ahead to where the good stuff is */
-              bytesToRead -= (bufferedSize - (current - buffer));
-              current = buffer + bufferedSize;
-              unreadSize -= bytesToRead;
-
-              seekResult = hyfile_seek (zipFile->fd, bytesToRead, HySeekCur);
-              if ((seekResult < 0) || (seekResult > HYCONST64 (0x7FFFFFFF)))
-                {
-                  zipFile->pointer = -1;
-                  result = ZIP_ERR_FILE_READ_ERROR;
-                  goto finished;
-                }
-              zipFile->pointer = (I_32) seekResult;
-            }
-        }
-      bufferedSize -= (current - buffer);
-      memmove (buffer, current, bufferedSize);
-    }
-
-  result = 0;
-
-finished:
-  if (filename)
-    hymem_free_memory (filename);
-  if (buffer)
-    hymem_free_memory (buffer);
-  return result;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION readZipEntry
-/*
-	Read the next zip entry for the zipFile into the zipEntry provided.  If filename is non-NULL, it is expected to match
-	the filename read for the entry.  If (cachePointer != -1) the filename of the entry will be looked up in the cache (assuming
-	there is one) to help detect use of an invalid cache.  If enumerationPointer is non-NULL, sequential access is assumed and
-	either a local zip entry or a data descriptor will be accepted, but a central zip entry will cause ZIP_ERR_NO_MORE_ENTRIES
-	to be returned.  If enumerationPointer is NULL, random access is assumed and either a local zip entry or a central zip
-	entry will be accepted.
-
-	Returns 0 on success or one of the following:
-			ZIP_ERR_FILE_READ_ERROR
-			ZIP_ERR_FILE_CORRUPT
-			ZIP_ERR_OUT_OF_MEMORY
-			ZIP_ERR_NO_MORE_ENTRIES
-*/
-static I_32
-readZipEntry (HyPortLibrary * portLib, HyZipFile * zipFile,
-              HyZipEntry * zipEntry, const char *filename,
-              IDATA * enumerationPointer, IDATA * entryStart,
-              BOOLEAN findDirectory)
-{
-  PORT_ACCESS_FROM_PORT (portLib);
-
-  I_32 result;
-  U_8 buffer[46 + 128];
-  U_8 *current;
-  U_32 sig;
-  IDATA readLength;
-  I_64 seekResult;
-  U_8 *readBuffer;
-  IDATA currentEntryPointer, localEntryPointer;
-  IDATA headerSize;
-  IDATA filenameLength = filename ? strlen (filename) : 0;
-
-retry:
-  if (entryStart)
-    *entryStart = zipFile->pointer;
-  readBuffer = NULL;
-  /* Guess how many bytes we'll need to read.  If we guess correctly we will do fewer I/O operations */
-  headerSize = 30;              /* local zip header size */
-  if (zipFile->cache && (zipFile->pointer >= zipFile->cache->startCentralDir))
-    {
-      headerSize = 46;          /* central zip header size */
-    }
-  readLength = headerSize + (filename ? filenameLength : 128);
-  if (findDirectory)
-    {
-      /* Extra byte for possible trailing '/' */
-      readLength++;
-    }
-
-  /* Allocate some memory if necessary */
-  if (readLength <= sizeof (buffer))
-    {
-      current = buffer;
-    }
-  else
-    {
-      current = readBuffer = hymem_allocate_memory (readLength);
-      if (!readBuffer)
-        return ZIP_ERR_OUT_OF_MEMORY;
-    }
-
-  currentEntryPointer = localEntryPointer = zipFile->pointer;
-
-  result = hyfile_read (zipFile->fd, current, readLength);
-  if ((result < 22)
-      || (filename
-          && !(result == readLength
-               || (findDirectory && result == (readLength - 1)))))
-    {
-      /* We clearly didn't get enough bytes */
-      result = ZIP_ERR_FILE_READ_ERROR;
-      goto finished;
-    }
-  zipFile->pointer += result;
-  readLength = result;          /* If it's not enough, we'll catch that later */
-  (void) ZIP_NEXT_U32 (sig, current);
-
-  if (enumerationPointer)
-    {
-      if ((sig == ZIP_CentralEnd))
-        {
-          result = ZIP_ERR_NO_MORE_ENTRIES;
-          goto finished;
-        }
-    }
-  if ((enumerationPointer || (!zipFile->cache))
-      && (sig == ZIP_DataDescriptor))
-    {
-      /* We failed to predict a data descriptor here.  This should be an error (i.e. only happens in malformed zips?) 
-         but, but we will silently skip over it */
-      seekResult =
-        hyfile_seek (zipFile->fd, currentEntryPointer + 16, HySeekSet);
-      if ((seekResult < 0) || (seekResult > HYCONST64 (0x7FFFFFFF)))
-        {
-          zipFile->pointer = -1;
-          result = ZIP_ERR_FILE_READ_ERROR;
-          goto finished;
-        }
-      zipFile->pointer = (I_32) seekResult;
-
-      if (zipFile->pointer == currentEntryPointer + 16)
-        {
-          if (readBuffer)
-            {
-              hymem_free_memory (readBuffer);
-            }
-          goto retry;
-        }
-      result = ZIP_ERR_FILE_READ_ERROR;
-      goto finished;
-    }
-
-  if ((sig != ZIP_CentralHeader) && (sig != ZIP_LocalHeader))
-    {
-      /* Unexpected. */
-      result = ZIP_ERR_FILE_CORRUPT;
-      goto finished;
-    }
-  headerSize = ((sig == ZIP_CentralHeader) ? 46 : 30);
-  if (readLength < headerSize)
-    {
-      /* We didn't get the whole header (and none of the filename).. */
-      /* NOTE: this could happen in normal use if the assumed filename length above is <16.  Since it's 128, we don't 
-         handle the impossible case where we would have to read more header.  It could also happen if the caller
-         supplied a filename of length <16 but that only happens when we have a cache (so we'll know the header size) 
-       */
-      result = ZIP_ERR_FILE_READ_ERROR;
-    }
-  readLength -= headerSize;
-
-  if (sig == ZIP_CentralHeader)
-    {
-      current += 2;             /* skip versionCreated field */
-    }
-  (void) ZIP_NEXT_U16 (zipEntry->versionNeeded, current);
-  (void) ZIP_NEXT_U16 (zipEntry->flags, current);
-  (void) ZIP_NEXT_U16 (zipEntry->compressionMethod, current);
-  (void) ZIP_NEXT_U16 (zipEntry->lastModTime, current);
-  (void) ZIP_NEXT_U16 (zipEntry->lastModDate, current);
-  (void) ZIP_NEXT_U32 (zipEntry->crc32, current);
-  (void) ZIP_NEXT_U32 (zipEntry->compressedSize, current);
-  (void) ZIP_NEXT_U32 (zipEntry->uncompressedSize, current);
-  (void) ZIP_NEXT_U16 (zipEntry->filenameLength, current);
-  (void) ZIP_NEXT_U16 (zipEntry->extraFieldLength, current);
-  zipEntry->fileCommentLength = 0;
-
-  if (sig == ZIP_CentralHeader)
-    {
-      (void) ZIP_NEXT_U16 (zipEntry->fileCommentLength, current);
-      current += 8;             /* skip disk number start + internal attrs + external attrs */
-      (void) ZIP_NEXT_U32 (localEntryPointer, current);
-    }
-
-  if (filename)
-    {
-      if (zipFile->cache)
-        {
-          if (!
-              (readLength == zipEntry->filenameLength
-               || (findDirectory
-                   && (readLength - 1) == zipEntry->filenameLength)))
-            {
-              /* We knew exactly how much we were supposed to read, and this wasn't it */
-              result = ZIP_ERR_FILE_CORRUPT;
-              goto finished;
-            }
-        }
-    }
-
-  /* Allocate space for filename */
-  if (zipEntry->filenameLength >= ZIP_INTERNAL_MAX)
-    {
-      zipEntry->filename =
-        hymem_allocate_memory (zipEntry->filenameLength + 1);
-      if (!zipEntry->filename)
-        {
-          result = ZIP_ERR_OUT_OF_MEMORY;
-          goto finished;
-        }
-    }
-  else
-    {
-      zipEntry->filename = zipEntry->internalFilename;
-    }
-  if (readLength > zipEntry->filenameLength)
-    {
-      readLength = zipEntry->filenameLength;
-    }
-  memcpy (zipEntry->filename, current, readLength);
-
-  /* Read the rest of the filename if necessary.  Allocate space in HyZipEntry for it! */
-  if (readLength < zipEntry->filenameLength)
-    {
-      result =
-        hyfile_read (zipFile->fd, zipEntry->filename + readLength,
-                     zipEntry->filenameLength - readLength);
-      if (result != (zipEntry->filenameLength - readLength))
-        {
-          result = ZIP_ERR_FILE_READ_ERROR;
-          goto finished;
-        }
-      zipFile->pointer += result;
-    }
-  zipEntry->filename[zipEntry->filenameLength] = '\0';
-
-  /* If we know what filename is supposed to be, compare it and make sure it matches */
-  /* Note: CASE-SENSITIVE COMPARE because filenames in zips are case sensitive (even on platforms with
-     case-insensitive file systems) */
-  if (filename)
-    {
-      if (!
-          ((findDirectory && zipEntry->filenameLength == (filenameLength + 1)
-            && zipEntry->filename[filenameLength] == '/'
-            && !strncmp ((char *) zipEntry->filename, (const char *) filename,
-                         filenameLength))
-           || !strcmp ((const char *) zipEntry->filename,
-                       (const char *) filename)))
-        {
-          /* We seem to have read something totally invalid.. */
-          result = ZIP_ERR_FILE_CORRUPT;
-          goto finished;
-        }
-    }
-
-  zipEntry->filenamePointer = currentEntryPointer + headerSize;
-  zipEntry->extraFieldPointer =
-    localEntryPointer + 30 + zipEntry->filenameLength;
-  zipEntry->dataPointer =
-    zipEntry->extraFieldPointer + zipEntry->extraFieldLength;
-  zipEntry->extraField = NULL;
-  zipEntry->fileCommentPointer = 0;
-  zipEntry->fileComment = NULL;
-  zipEntry->data = NULL;
-
-  if (sig == ZIP_CentralHeader)
-    {
-      U_8 buf[2];
-      U_8 *buf2 = buf;
-      U_16 lost;
-      /* Also, we know where the comment is */
-      zipEntry->fileCommentPointer = currentEntryPointer + headerSize +
-        zipEntry->filenameLength + zipEntry->extraFieldLength;
-      if (hyfile_seek (zipFile->fd, localEntryPointer + 28, HySeekSet) ==
-          localEntryPointer + 28)
-        {
-          if (hyfile_read (zipFile->fd, buf, 2) == 2)
-            {
-              (void) ZIP_NEXT_U16 (lost, buf2);
-              zipEntry->dataPointer = zipEntry->extraFieldPointer + lost;
-              zipFile->pointer = localEntryPointer + 30;
-            }
-        }
-    }
-
-  if ((sig == ZIP_LocalHeader)
-      && (zipEntry->compressionMethod == ZIP_CM_Deflated)
-      && (zipEntry->flags & 0x8))
-    {
-      /* What we just read doesn't tell us how big the compressed data is.  We have to do a heuristic search for a
-         valid data descriptor at the end of the compressed text */
-      result = scanForDataDescriptor (portLib, zipFile, zipEntry);
-      if (result < 0)
-        goto finished;
-    }
-
-  /* Entry read successfully */
-
-  if (enumerationPointer)
-    {
-      /* Work out where the next entry is supposed to be */
-      *enumerationPointer =
-        zipEntry->fileCommentPointer + zipEntry->fileCommentLength;
-    }
-
-  if (readBuffer)
-    hymem_free_memory (readBuffer);
-  return 0;
-
-finished:
-  if (readBuffer)
-    {
-      hymem_free_memory (readBuffer);
-    }
-  if ((zipEntry->filename)
-      && (zipEntry->filename != zipEntry->internalFilename))
-    {
-      hymem_free_memory (zipEntry->filename);
-    }
-  zipEntry->filename = NULL;
-  if (result == ZIP_ERR_FILE_READ_ERROR)
-    {
-      zipFile->pointer = -1;
-    }
-  return result;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zip_closeZipFile
-/**
- * Attempt to close the zipfile. 
- *
- * @param[in] portLib the port library
- * @param[in] zipFile The zip file to be closed
- *
- * @return 0 on success
- * @return 	ZIP_ERR_FILE_CLOSE_ERROR if there is an error closing the file
- * @return 	ZIP_ERR_INTERNAL_ERROR if there is an internal error
- *
-*/
-I_32 VMCALL
-zip_closeZipFile (HyPortLibrary * portLib, struct HyZipFile * zipFile)
-{
-  PORT_ACCESS_FROM_PORT (portLib);
-#if defined(HY_NO_THR)
-  THREAD_ACCESS_FROM_PORT(portLib);
-#endif /* HY_NO_THR */
-  IDATA fd;
-
-  ENTER ();
-
-  fd = zipFile->fd;
-  zipFile->fd = -1;
-
-  if (zipFile->cache && zipFile->cachePool)
-    {
-      zipCachePool_release (zipFile->cachePool, zipFile->cache);
-      zipFile->cache = NULL;
-    }
-  if ((zipFile->filename) && (zipFile->filename != zipFile->internalFilename))
-    {
-      hymem_free_memory (zipFile->filename);
-    }
-  zipFile->filename = NULL;
-
-  if (fd == -1)
-    {
-      EXIT ();
-      return ZIP_ERR_INTERNAL_ERROR;
-    }
-  if (hyfile_close (fd))
-    {
-      EXIT ();
-      return ZIP_ERR_FILE_CLOSE_ERROR;
-    }
-  EXIT ();
-  return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zip_establishCache
-/** 
- * Called to set up a cache when a zip file is opened with a cachePool but without a cache, or when the
- *	current cache is found to be invalid in some way.
- * 
- * @param[in] portLib the port library
- * @param[in] zipFile the zip file for which we want to establish a cache
- * 
- * The current cache is marked as invalid such that new instances of zip files 
- * won't try to use it and an attempt is made to establish a new cache.
- *
- * @return 0 on success
- * @return 	ZIP_ERR_FILE_READ_ERROR if there is an error reading from zipFile 
- * @return	ZIP_ERR_FILE_OPEN_ERROR if is there is an error opening the file 
- * @return	ZIP_ERR_UNKNOWN_FILE_TYPE if the file type is unknown
- * @return	ZIP_ERR_UNSUPPORTED_FILE_TYPE if the file type is unsupported
- * @return	ZIP_ERR_OUT_OF_MEMORY  if there is not enough memory to complete this call
- * @return	ZIP_ERR_INTERNAL_ERROR if there was an internal error
-*/
-
-I_32
-zip_establishCache (HyPortLibrary * portLib, HyZipFile * zipFile)
-{
-  PORT_ACCESS_FROM_PORT (portLib);
-  I_32 result;
-  I_64 timeStamp, actualFileSize;
-  IDATA fileSize, filenameLength;
-
-  if (zipFile->cache)
-    {
-      if (zipFile->cachePool)
-        {
-          /* Whack cache timestamp to keep other people from starting to use it (we will create a new one for them
-             to start to use instead).  Once all the current users of the cache have stopped using it, it will go away */
-          zipFile->cache->zipTimeStamp = -2;
-          zipCachePool_release (zipFile->cachePool, zipFile->cache);
-        }
-      zipFile->cache = NULL;
-    }
-  if (!zipFile->cachePool)
-    {
-      return ZIP_ERR_INTERNAL_ERROR;
-    }
-
-  /* Check the cachePool for a suitable cache. */
-  filenameLength = strlen ((const char *) zipFile->filename);
-
-//  timeStamp = hyfile_lastmod ((const char *) zipFile->filename);
-//  actualFileSize = hyfile_length ((const char *) zipFile->filename);
-  {
-    struct stat st;
-    tzset ();
-    stat ((mcSignednessBull)zipFile->filename, &st);
-    timeStamp = (U_64)st.st_mtime * 1000;
-    actualFileSize = (I_64) st.st_size;
-  }
-
-  if ((actualFileSize < 0) || (actualFileSize > HYCONST64 (0x7FFFFFFF)))
-    {
-      return ZIP_ERR_INTERNAL_ERROR;
-    }
-  fileSize = (IDATA) actualFileSize;
-
-  zipFile->cache =
-    zipCachePool_findCache (zipFile->cachePool,
-                            (const char *) zipFile->filename, filenameLength,
-                            fileSize, timeStamp);
-  if (!zipFile->cache)
-    {
-      /* Build a new cache.  Because caller asked for a cache, fail if we can't provide one */
-      zipFile->cache =
-        zipCache_new (portLib, (char *) zipFile->filename, filenameLength);
-      if (!zipFile->cache)
-        return ZIP_ERR_OUT_OF_MEMORY;
-
-      zipFile->cache->zipFileSize = fileSize;
-      zipFile->cache->zipTimeStamp = timeStamp;
-
-      result = zip_populateCache (portLib, zipFile);
-      if (result != 0)
-        {
-          zipCache_kill (zipFile->cache);
-          zipFile->cache = NULL;
-          return result;
-        }
-      if (!zipCachePool_addCache (zipFile->cachePool, zipFile->cache))
-        {
-          zipCache_kill (zipFile->cache);
-          zipFile->cache = NULL;
-          return ZIP_ERR_OUT_OF_MEMORY;
-        }
-    }
-  return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zip_initZipEntry
-/**
- * Initialize a zip entry.
- * 
- * Should be called before the entry is passed to any other zip support functions 
- *
- * @param[in] portLib the port library
- * @param[in] entry the zip entry to init
- *
- * @return none
-*/
-
-void
-zip_initZipEntry (HyPortLibrary * portLib, HyZipEntry * entry)
-{
-  memset (entry, 0, sizeof (*entry));
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zip_freeZipEntry
-/**
- * Free any memory associated with a zip entry.
- * 
- * @param[in] portLib the port library
- * @param[in] entry the zip entry we are freeing 
- * 
- * @return none 
- * 
- * @note This does not free the entry itself.
-*/
-
-void
-zip_freeZipEntry (HyPortLibrary * portLib, HyZipEntry * entry)
-{
-  PORT_ACCESS_FROM_PORT (portLib);
-
-  if ((entry->filename) && (entry->filename != entry->internalFilename))
-    {
-      hymem_free_memory (entry->filename);
-    }
-  entry->filename = NULL;
-  if (entry->extraField)
-    {
-      hymem_free_memory (entry->extraField);
-      entry->extraField = NULL;
-    }
-  if (entry->data)
-    {
-      hymem_free_memory (entry->data);
-      entry->data = NULL;
-    }
-  if (entry->fileComment)
-    {
-      hymem_free_memory (entry->fileComment);
-      entry->fileComment = NULL;
-    }
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zip_getNextZipEntry
-/**
- *	Read the next zip entry at nextEntryPointer into zipEntry.
- *	
- * Any memory held onto by zipEntry may be lost, and therefore
- *	MUST be freed with @ref zip_freeZipEntry first.
- *
- * @param[in] portLib the port library
- * @param[in] zipFile The zip file being read
- * @param[out] zipEntry compressed data is placed here
- * @param[in] nextEntryPointer
- * 
- * @return 0 on success
- * @return 	ZIP_ERR_FILE_READ_ERROR if there is an error reading zipFile
- * @return ZIP_ERR_FILE_CORRUPT if zipFile is corrupt
- * @return 	ZIP_ERR_NO_MORE_ENTRIES if there are no more entries in zipFile
- * @return 	ZIP_ERR_OUT_OF_MEMORY if there is not enough memory to complete this call
- *
- * @see zip_freeZipEntry
- *
-*/
-I_32
-zip_getNextZipEntry (HyPortLibrary * portLib, HyZipFile * zipFile,
-                     HyZipEntry * zipEntry, IDATA * nextEntryPointer)
-{
-  PORT_ACCESS_FROM_PORT (portLib);
-#if defined(HY_NO_THR)
-  THREAD_ACCESS_FROM_PORT(portLib);
-#endif /* HY_NO_THR */
-  IDATA result;
-  BOOLEAN retryAllowed = TRUE;
-  IDATA pointer;
-  IDATA entryStart;
-  I_64 seekResult;
-
-  ENTER ();
-
-retry:
-  pointer = *nextEntryPointer;
-
-  /* Seek to the entry's position in the file. */
-  if (pointer != zipFile->pointer)
-    {
-      seekResult = hyfile_seek (zipFile->fd, pointer, HySeekSet);
-      if ((seekResult < 0) || (seekResult > HYCONST64 (0x7FFFFFFF)))
-        {
-          zipFile->pointer = -1;
-          EXIT ();
-          return ZIP_ERR_FILE_READ_ERROR;
-        }
-      zipFile->pointer = (I_32) seekResult;
-
-      if (pointer != zipFile->pointer)
-        {
-          zipFile->pointer = -1;
-          EXIT ();
-          return ZIP_ERR_FILE_READ_ERROR;
-        }
-    }
-
-  /* Read the entry */
-  entryStart = *nextEntryPointer;
-  result =
-    readZipEntry (portLib, zipFile, zipEntry, NULL, &pointer, &entryStart,
-                  FALSE);
-  if (result != 0)
-    {
-      if (!retryAllowed || (result == ZIP_ERR_NO_MORE_ENTRIES))
-        {
-          EXIT ();
-          return result;
-        }
-      zip_establishCache (portLib, zipFile);
-      retryAllowed = FALSE;
-      goto retry;
-    }
-
-  if (zipFile->cache)
-    {
-      /* Validity check: look up filename in the cache... */
-      result =
-        (IDATA) zipCache_findElement (zipFile->cache,
-                                      (const char *) zipEntry->filename,
-                                      FALSE);
-      if (result != entryStart)
-        {
-          if (result >= zipFile->cache->startCentralDir)
-            {
-              /* ! Cache contents are not valid.  Invalidate it and make a new one */
-              if (!retryAllowed)
-                {
-                  EXIT ();
-                  return ZIP_ERR_FILE_CORRUPT;  /* should never happen! */
-                }
-              result = zip_establishCache (portLib, zipFile);
-              if (!result)
-                {
-                  /* (silently start operating without a cache if we couldn't make a new one) */
-                }
-              else
-                {
-                  retryAllowed = FALSE;
-                  goto retry;
-                }
-            }
-          else
-            {
-              /* We know that the central header for this entry contains info that the
-                 local header is missing (comment length and/or uncompressed size) */
-              zipEntry->fileCommentPointer = -1;
-            }
-        }
-    }
-
-  *nextEntryPointer = pointer;
-  EXIT ();
-  return 0;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zip_getZipEntry
-/**
- *	Attempt to find and read the zip entry corresponding to filename.
- *	If found, read the entry into the parameter entry. 
- *
- * If an uncached entry is found, the filename field will be filled in. This
- * memory will have to be freed with @ref zip_freeZipEntry.
- * 
- * @param[in] portLib the port library
- * @param[in] zipFile the file being read from
- * @param[out] entry the zip entry found in zipFile is read to here
- * @param[in] filename the name of the file that corresponds to entry
- * @param[in] findDirectory when true, match a directory even if filename does not end in '/'.
- *			Note findDirectory is only supported (for the JCL) when there is a cache
- *
- * @return 0 on success or one of the following:
- * @return	ZIP_ERR_FILE_READ_ERROR if there is an error reading from zipFile
- * @return	ZIP_ERR_FILE_CORRUPT if zipFile is corrupt
- * @return	ZIP_ERR_ENTRY_NOT_FOUND if a zip entry with name filename was not found
- * @return 	ZIP_ERR_OUT_OF_MEMORY if there is not enough memory to complete this call
- *
- * @see zip_freeZipEntry
-*/
-
-I_32
-zip_getZipEntry (HyPortLibrary * portLib, HyZipFile * zipFile,
-                 HyZipEntry * entry, const char *filename,
-                 BOOLEAN findDirectory)
-{
-  PORT_ACCESS_FROM_PORT (portLib);
-#if defined(HY_NO_THR)
-  THREAD_ACCESS_FROM_PORT(portLib);
-#endif /* HY_NO_THR */
-  IDATA result, position;
-  BOOLEAN retryAllowed = TRUE;
-  I_64 seekResult;
-
-  ENTER ();
-
-retry:
-  if (zipFile->cache)
-    {
-      /* Look up filename in the cache. */
-      position =
-        (IDATA) zipCache_findElement (zipFile->cache, filename,
-                                      findDirectory);
-      if (position == -1)
-        {
-          /* Note: we assume the cache is still valid here */
-          EXIT ();
-          return ZIP_ERR_ENTRY_NOT_FOUND;
-        }
-
-      /* Seek to the entry's position in the file. */
-      if (zipFile->pointer != position)
-        {
-          seekResult = hyfile_seek (zipFile->fd, position, HySeekSet);
-          if ((seekResult < 0) || (seekResult > HYCONST64 (0x7FFFFFFF)))
-            {
-              zipFile->pointer = -1;
-              EXIT ();
-              return ZIP_ERR_FILE_READ_ERROR;
-            }
-          zipFile->pointer = (I_32) seekResult;
-
-          if (zipFile->pointer != position)
-            {
-              zipFile->pointer = -1;
-              EXIT ();
-              return ZIP_ERR_FILE_READ_ERROR;
-            }
-        }
-
-      /* Read the entry */
-      result =
-        readZipEntry (portLib, zipFile, entry, filename, NULL, NULL,
-                      findDirectory);
-      if (result != 0)
-        {
-          if (!retryAllowed)
-            {
-              EXIT ();
-              return result;
-            }
-          result = zip_establishCache (portLib, zipFile);       /* invalidate existing cache */
-          if (result)
-            {
-              EXIT ();
-              return result;
-            }
-          retryAllowed = FALSE;
-          goto retry;
-        }
-      EXIT ();
-      return 0;
-    }
-  else
-    {
-      /* Uh oh -- random access without a cache (SLOW!) */
-      position = 0;
-      zip_resetZipFile (PORTLIB, zipFile, &position);
-      while (TRUE)
-        {
-
-          if (zipFile->pointer != position)
-            {
-              seekResult = hyfile_seek (zipFile->fd, position, HySeekSet);
-              if ((seekResult < 0) || (seekResult > HYCONST64 (0x7FFFFFFF)))
-                {
-                  zipFile->pointer = -1;
-                  EXIT ();
-                  return ZIP_ERR_FILE_READ_ERROR;
-                }
-              zipFile->pointer = (I_32) seekResult;
-
-              if (zipFile->pointer != position)
-                {
-                  zipFile->pointer = -1;
-                  EXIT ();
-                  return ZIP_ERR_FILE_READ_ERROR;
-                }
-            }
-
-          result =
-            readZipEntry (portLib, zipFile, entry, NULL, &position, NULL,
-                          FALSE);
-          if (result || !strcmp ((const char *) entry->filename, filename))
-            {
-              EXIT ();
-              return result;
-            }
-
-          /* No match.  Reset for next entry */
-          zip_freeZipEntry (portLib, entry);
-          zip_initZipEntry (portLib, entry);
-        }
-    }
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zip_getZipEntryData
-/** 
- *	Attempt to read and uncompress the data for the zip entry entry.
- * 
- *	If buffer is non-NULL it is used, but not explicitly held onto by the entry.
- *	If buffer is NULL, memory is allocated and held onto by the entry, and thus
- *	should later be freed with @ref zip_freeZipEntry.
- *
- * @param[in] portLib the port library
- * @param[in] zipFile the zip file being read from.
- * @param[in,out] entry the zip entry
- * @param[in] buffer may or may not be NULL
- * @param[in] bufferSize
-
- * @return 0 on success
- * @return	ZIP_ERR_FILE_READ_ERROR if there is an error reading from zipEntry
- * @return	ZIP_ERR_FILE_CORRUPT if zipFile is corrupt
- * @return	ZIP_ERR_ENTRY_NOT_FOUND if entry is not found
- * @return 	ZIP_ERR_OUT_OF_MEMORY  if there is not enough memory to complete this call
- * @return 	ZIP_ERR_BUFFER_TOO_SMALL if buffer is too small to hold the comment for zipFile
- *
- * @see zip_freeZipEntry
- *
-*/
-I_32
-zip_getZipEntryData (HyPortLibrary * portLib, HyZipFile * zipFile,
-                     HyZipEntry * entry, U_8 * buffer, U_32 bufferSize)
-{
-  PORT_ACCESS_FROM_PORT (portLib);
-#if defined(HY_NO_THR)
-  THREAD_ACCESS_FROM_PORT(portLib);
-#endif /* HY_NO_THR */
-
-  I_32 result;
-  U_8 *dataBuffer;
-  struct workBuffer wb;
-  I_64 seekResult;
-
-  ENTER ();
-
-  wb.portLib = portLib;
-  wb.bufferStart = wb.bufferEnd = wb.currentAlloc = 0;
-
-  if (buffer)
-    {
-      if (bufferSize < entry->uncompressedSize)
-        {
-          EXIT ();
-          return ZIP_ERR_BUFFER_TOO_SMALL;
-        }
-      dataBuffer = buffer;
-    }
-  else
-    {
-      /* Note that this is the first zalloc. This memory must be available to the calling method and is freed explicitly in zip_freeZipEntry. */
-      /* Note that other allocs freed in zip_freeZipEntry are not alloc'd using zalloc */
-      dataBuffer = zdataalloc (&wb, 1, entry->uncompressedSize);
-      if (!dataBuffer)
-        {
-          EXIT ();
-          return ZIP_ERR_OUT_OF_MEMORY;
-        }
-      entry->data = dataBuffer;
-    }
-
-  if (entry->compressionMethod == ZIP_CM_Stored)
-    {
-      /* No compression - just read the data in. */
-      if (zipFile->pointer != entry->dataPointer)
-        {
-          seekResult =
-            hyfile_seek (zipFile->fd, entry->dataPointer, HySeekSet);
-          if ((seekResult < 0) || (seekResult > HYCONST64 (0x7FFFFFFF)))
-            {
-              zipFile->pointer = -1;
-              result = ZIP_ERR_FILE_READ_ERROR;
-              goto finished;
-            }
-          zipFile->pointer = (I_32) seekResult;
-
-          if (zipFile->pointer != entry->dataPointer)
-            {
-              result = ZIP_ERR_FILE_READ_ERROR;
-              goto finished;
-            }
-        }
-      result = hyfile_read (zipFile->fd, dataBuffer, entry->compressedSize);
-      if (result != (I_32) entry->compressedSize)
-        {
-          result = ZIP_ERR_FILE_READ_ERROR;
-          goto finished;
-        }
-      zipFile->pointer += result;
-      EXIT ();
-      return 0;
-    }
-
-  if (entry->compressionMethod == ZIP_CM_Deflated)
-    {
-      U_8 *readBuffer;
-
-      /* Ensure that the library is loaded. */
-     if (checkZipLibrary (portLib))
-        {
-          result = ZIP_ERR_UNSUPPORTED_FILE_TYPE;
-          goto finished;
-        }
-
-      /* Read the file contents. */
-      readBuffer = zdataalloc (&wb, 1, entry->compressedSize);
-      if (!readBuffer)
-        {
-          result = ZIP_ERR_OUT_OF_MEMORY;
-          goto finished;
-        }
-      if (zipFile->pointer != entry->dataPointer)
-        {
-          seekResult =
-            hyfile_seek (zipFile->fd, entry->dataPointer, HySeekSet);
-          if ((seekResult < 0) || (seekResult > HYCONST64 (0x7FFFFFFF)))
-            {
-              zipFile->pointer = -1;
-              zdatafree (&wb, readBuffer);
-              result = ZIP_ERR_FILE_READ_ERROR;
-              goto finished;
-            }
-          zipFile->pointer = (I_32) seekResult;
-
-          if (zipFile->pointer != entry->dataPointer)
-            {
-              zdatafree (&wb, readBuffer);
-              result = ZIP_ERR_FILE_READ_ERROR;
-              goto finished;
-            }
-        }
-      if (hyfile_read (zipFile->fd, readBuffer, entry->compressedSize) !=
-          (I_32) entry->compressedSize)
-        {
-          zdatafree (&wb, readBuffer);
-          result = ZIP_ERR_FILE_READ_ERROR;
-          goto finished;
-        }
-      zipFile->pointer += (I_32) entry->compressedSize;
-
-      /* Deflate the data. */
-      result =
-        inflateData (&wb, readBuffer, entry->compressedSize, dataBuffer,
-                     entry->uncompressedSize);
-      zdatafree (&wb, readBuffer);
-      if (result)
-        goto finished;
-      EXIT ();
-      return 0;
-    }
-
-  /* Whatever this is, we can't decompress it */
-  result = ZIP_ERR_UNSUPPORTED_FILE_TYPE;
-
-finished:
-  if (!buffer)
-    {
-      entry->data = NULL;
-      zdatafree (&wb, dataBuffer);
-    }
-  if (result == ZIP_ERR_FILE_READ_ERROR)
-    {
-      zipFile->pointer = -1;
-    }
-  EXIT ();
-  return result;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zip_getZipEntryExtraField
-/** 
- *	Read the extra field of entry from the zip file filename. 
- *
- * buffer is used if non-NULL, but is not held onto by entry. 
- *
- * If buffer is NULL, memory is allocated and held onto by entry, and MUST be freed later with
- *	@ref zip_freeZipEntry.
- *
- * @param[in] portLib the port library
- * @param[in] zipFile the zip file being read from.
- * @param[in,out] entry the zip entry concerned
- * @param[in] buffer may or may not be NULL
- * @param[in] bufferSize
- *
- * @return 0 on success or one of the following:
- * @return ZIP_ERR_FILE_READ_ERROR if there is an error reading from zipFile
- * @return 	ZIP_ERR_FILE_CORRUPT if zipFile is corrupt
- * @return 	ZIP_ERR_OUT_OF_MEMORY if there is not enough memory to complete this call
- * @return 	ZIP_ERR_BUFFER_TOO_SMALL if the buffer was non-Null but not large enough to hold the contents of entry
- *
- * @see zip_freeZipEntry
-*/
-I_32
-zip_getZipEntryExtraField (HyPortLibrary * portLib, HyZipFile * zipFile,
-                           HyZipEntry * entry, U_8 * buffer, U_32 bufferSize)
-{
-  PORT_ACCESS_FROM_PORT (portLib);
-#if defined(HY_NO_THR)
-  THREAD_ACCESS_FROM_PORT(portLib);
-#endif /* HY_NO_THR */
-
-  I_32 result;
-  U_8 *extraFieldBuffer;
-  I_64 seekResult;
-
-  ENTER ();
-
-  if (entry->extraFieldLength == 0)
-    {
-      EXIT ();
-      return 0;
-    }
-
-  if (buffer)
-    {
-      if (bufferSize < entry->extraFieldLength)
-        {
-          EXIT ();
-          return ZIP_ERR_BUFFER_TOO_SMALL;
-        }
-      extraFieldBuffer = buffer;
-    }
-  else
-    {
-      extraFieldBuffer = hymem_allocate_memory (entry->extraFieldLength);
-      if (!extraFieldBuffer)
-        {
-          EXIT ();
-          return ZIP_ERR_OUT_OF_MEMORY;
-        }
-      entry->extraField = extraFieldBuffer;
-    }
-
-  if (zipFile->pointer != entry->extraFieldPointer)
-    {
-      seekResult =
-        hyfile_seek (zipFile->fd, entry->extraFieldPointer, HySeekSet);
-      if ((seekResult < 0) || (seekResult > HYCONST64 (0x7FFFFFFF)))
-        {
-          zipFile->pointer = -1;
-          result = ZIP_ERR_FILE_READ_ERROR;
-          goto finished;
-        }
-      zipFile->pointer = (I_32) seekResult;
-      if (zipFile->pointer != entry->extraFieldPointer)
-        {
-          result = ZIP_ERR_FILE_READ_ERROR;
-          goto finished;
-        }
-    }
-  result =
-    hyfile_read (zipFile->fd, extraFieldBuffer, entry->extraFieldLength);
-  if (result != (I_32) entry->extraFieldLength)
-    {
-      result = ZIP_ERR_FILE_READ_ERROR;
-      goto finished;
-    }
-  zipFile->pointer += result;
-  EXIT ();
-  return 0;
-
-finished:
-  if (!buffer)
-    {
-      entry->extraField = NULL;
-      hymem_free_memory (extraFieldBuffer);
-    }
-  if (result == ZIP_ERR_FILE_READ_ERROR)
-    zipFile->pointer = -1;
-  EXIT ();
-  return result;
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zip_getZipEntryFilename
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zip_getZipEntryComment
-/**
- *	Read the file comment for entry. 
- *
- * If buffer is non-NULL, it is used, but not held onto by entry. 
- *
- * If buffer is NULL, memory is allocated and
- *	held onto by entry, and thus should later be freed with @ref zip_freeZipEntry.
- *
- * @param[in] portLib the port library
- * @param[in] zipFile the zip file concerned
- * @param[in] entry the entry who's comment we want
- * @param[in] buffer may or may not be NULL
- * @param[in] bufferSize
-
- * @return 0 on success or one of the following
- * @return	ZIP_ERR_FILE_READ_ERROR if there is an error reading the file comment from zipEntry
- * @return	ZIP_ERR_FILE_CORRUPT if zipFile is corrupt
- * @return	ZIP_ERR_ENTRY_NOT_FOUND if entry is not found
- * @return 	ZIP_ERR_OUT_OF_MEMORY  if there is not enough memory to complete this call
- * @return 	ZIP_ERR_BUFFER_TOO_SMALL if buffer is too small to hold the comment for zipFile
-*/
-
-I_32
-zip_getZipEntryComment (HyPortLibrary * portLib, HyZipFile * zipFile,
-                        HyZipEntry * entry, U_8 * buffer, U_32 bufferSize)
-{
-  PORT_ACCESS_FROM_PORT (portLib);
-#if defined(HY_NO_THR)
-  THREAD_ACCESS_FROM_PORT(portLib);
-#endif /* HY_NO_THR */
-
-  I_32 result;
-  U_8 *fileCommentBuffer;
-  I_64 seekResult;
-
-  ENTER ();
-
-  if (entry->fileCommentLength == 0)
-    {
-      if (entry->fileCommentPointer == -1)
-        {
-          /* TODO: we don't know where the comment is (or even if there is one)! This only happens if you're running
-             without a cache, so too bad for now */
-        }
-      EXIT ();
-      return 0;
-    }
-
-  if (buffer)
-    {
-      if (bufferSize < entry->fileCommentLength)
-        {
-          EXIT ();
-          return ZIP_ERR_BUFFER_TOO_SMALL;
-        }
-      fileCommentBuffer = buffer;
-    }
-  else
-    {
-      fileCommentBuffer = hymem_allocate_memory (entry->fileCommentLength);
-      if (!fileCommentBuffer)
-        {
-          EXIT ();
-          return ZIP_ERR_OUT_OF_MEMORY;
-        }
-      entry->fileComment = fileCommentBuffer;
-    }
-
-  if (zipFile->pointer != entry->fileCommentPointer)
-    {
-      seekResult =
-        hyfile_seek (zipFile->fd, entry->fileCommentPointer, HySeekSet);
-      if ((seekResult < 0) || (seekResult > HYCONST64 (0x7FFFFFFF)))
-        {
-          zipFile->pointer = -1;
-          result = ZIP_ERR_FILE_READ_ERROR;
-          goto finished;
-        }
-      zipFile->pointer = (I_32) seekResult;
-
-      if (zipFile->pointer != entry->fileCommentPointer)
-        {
-          result = ZIP_ERR_FILE_READ_ERROR;
-          goto finished;
-        }
-    }
-  result =
-    hyfile_read (zipFile->fd, fileCommentBuffer, entry->fileCommentLength);
-  if (result != (I_32) entry->fileCommentLength)
-    {
-      result = ZIP_ERR_FILE_READ_ERROR;
-      goto finished;
-    }
-  zipFile->pointer += result;
-  EXIT ();
-  return 0;
-
-finished:
-  if (!buffer)
-    {
-      entry->fileComment = NULL;
-      hymem_free_memory (fileCommentBuffer);
-    }
-  if (result == ZIP_ERR_FILE_READ_ERROR)
-    {
-      zipFile->pointer = -1;
-    }
-  EXIT ();
-  return result;
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zip_openZipFile
-/**
- * Attempt to open a zip file. 
- * 
- * If the cache pool is non-NULL, the cachePool will be used to find a suitable cache, and if none can be found it will create one and add it to cachePool.
- * Zip support is responsible for managing the lifetime of the cache.  
- *
- * @note If cachePool is NULL, zipFile will be opened without a cache.
- *
- * @param[in] portLib the port library
- * @param[in] filename the zip file to open
- * @param[out] zipFile the zip file structure to populate
- * @param[in] cachePool the cache pool
- * 
- * @return 0 on success
- * @return 	ZIP_ERR_FILE_OPEN_ERROR if is there is an error opening the file
- * @return	ZIP_ERR_FILE_READ_ERROR if there is an error reading the file
- * @return	ZIP_ERR_FILE_CORRUPT if the file is corrupt
- * @return	ZIP_ERR_UNKNOWN_FILE_TYPE if the file type is not known
- * @return	ZIP_ERR_UNSUPPORTED_FILE_TYPE if the file type is unsupported
- * @return	ZIP_ERR_OUT_OF_MEMORY if we are out of memory
-*/
-I_32
-zip_openZipFile (HyPortLibrary * portLib, char *filename, HyZipFile * zipFile,
-                 HyZipCachePool * cachePool)
-{
-  PORT_ACCESS_FROM_PORT (portLib);
-#if defined(HY_NO_THR)
-  THREAD_ACCESS_FROM_PORT(portLib);
-#endif /* HY_NO_THR */
-
-  IDATA fd = -1;
-  I_32 result = 0;
-  I_64 seekResult;
-  U_8 buffer[4];
-  I_32 len;
-
-  ENTER ();
-
-  len = strlen (filename);
-  zipFile->fd = -1;
-  zipFile->type = ZIP_Unknown;
-  zipFile->cache = NULL;
-  zipFile->cachePool = NULL;
-  zipFile->pointer = -1;
-  /* Allocate space for filename */
-  if (len >= ZIP_INTERNAL_MAX)
-    {
-      zipFile->filename = hymem_allocate_memory (len + 1);
-      if (!zipFile->filename)
-        {
-          EXIT ();
-          return ZIP_ERR_OUT_OF_MEMORY;
-        }
-    }
-  else
-    {
-      zipFile->filename = zipFile->internalFilename;
-    }
-
-  strcpy ((char *) zipFile->filename, filename);
-
-  fd = hyfile_open (filename, HyOpenRead, 0);
-  if (fd == -1)
-    {
-      result = ZIP_ERR_FILE_OPEN_ERROR;
-      goto finished;
-    }
-
-  if (hyfile_read (fd, buffer, 4) != 4)
-    {
-      result = ZIP_ERR_FILE_READ_ERROR;
-      goto finished;
-    }
-
-  if ((buffer[0] == 'P') && (buffer[1] == 'K'))
-    {
-      /* If not the central header or local file header, its corrupt */
-      if (!
-          ((buffer[2] == 1 && buffer[3] == 2)
-           || (buffer[2] == 3 && buffer[3] == 4)))
-        {
-          result = ZIP_ERR_FILE_CORRUPT;
-          goto finished;
-        }
-      /* PKZIP file. Back up the pointer to the beginning. */
-      seekResult = hyfile_seek (fd, 0, HySeekSet);
-      if (seekResult != 0)
-        {
-          result = ZIP_ERR_FILE_READ_ERROR;
-          goto finished;
-        }
-
-      zipFile->fd = fd;
-      zipFile->type = ZIP_PKZIP;
-      zipFile->pointer = 0;
-    }
-
-  if ((buffer[0] == 0x1F) && (buffer[1] == 0x8B))
-    {
-      /* GZIP - currently unsupported. 
-         zipFile->fd = fd;
-         zipFile->type = ZIP_GZIP;
-         zipFile->pointer = 2;
-       */
-      result = ZIP_ERR_UNSUPPORTED_FILE_TYPE;
-      goto finished;
-    }
-
-  if (zipFile->type == ZIP_Unknown)
-    {
-      result = ZIP_ERR_UNKNOWN_FILE_TYPE;
-      goto finished;
-    }
-
-  result = 0;
-
-  if (cachePool)
-    {
-      zipFile->cachePool = cachePool;
-      result = zip_establishCache (portLib, zipFile);
-    }
-
-finished:
-  if (result == 0)
-    {
-      zipFile->fd = fd;
-      EXIT ();
-      return 0;
-    }
-  if (fd != -1)
-    {
-      hyfile_close (fd);
-    }
-  if ((zipFile->filename) && (zipFile->filename != zipFile->internalFilename))
-    {
-      hymem_free_memory (zipFile->filename);
-    }
-  zipFile->filename = NULL;
-  EXIT ();
-  return result;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zip_resetZipFile
-/**
- * Reset nextEntryPointer to the first entry in the file.
- *
- * @param[in] portLib the port library
- * @param[in] zipFile the zip being read from
- * @param[out] nextEntryPointer will be reset to the first entry in the file
- *
- * @return none
- *
- * 
-*/
-void
-zip_resetZipFile (HyPortLibrary * portLib, HyZipFile * zipFile,
-                  IDATA * nextEntryPointer)
-{
-  *nextEntryPointer = 0;
-  if (zipFile)
-    {
-      if (zipFile->cache)
-        *nextEntryPointer = zipFile->cache->startCentralDir;
-      else
-        {
-          I_32 result;
-          HyZipCentralEnd endEntry;
-          result = scanForCentralEnd (portLib, zipFile, &endEntry);
-          if (result != 0)
-            return;
-          *nextEntryPointer = (IDATA) ((UDATA) endEntry.dirOffset);
-        }
-    }
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zip_getZipEntryFromOffset
-/**
- * Attempt to read a zip entry at offset from the zip file provided.
- *	If found, read into entry.
- *
- * @note If an uncached entry is found, the filename field will be filled in. This
- *	memory MUST be freed with @ref zip_freeZipEntry.
- *
- * @param[in] portLib the port library
- * @param[in] zipFile the zip file being read
- * @param[in] offset the offset into the zipFile of the desired zip entry
- * @param[out] entry the compressed data
- *
- * @return 0 on success
- * @return ZIP_ERR_FILE_READ_ERROR if there is an error reading from @ref zipFile
- * @return 	ZIP_ERR_FILE_CORRUPT if @ref zipFile is corrupt
- * @return 	ZIP_ERR_ENTRY_NOT_FOUND if the entry is not found 
- * @return 	ZIP_ERR_OUT_OF_MEMORY if there is not enough memory to complete this call
- *
- * @see zip_freeZipEntry
-*/
-I_32
-zip_getZipEntryFromOffset (HyPortLibrary * portLib, HyZipFile * zipFile,
-                           HyZipEntry * entry, IDATA offset)
-{
-  PORT_ACCESS_FROM_PORT (portLib);
-#if defined(HY_NO_THR)
-  THREAD_ACCESS_FROM_PORT(portLib);
-#endif /* HY_NO_THR */
-  I_32 result;
-  I_64 seekResult;
-
-  ENTER ();
-
-  if (zipFile->pointer != offset)
-    {
-      seekResult = hyfile_seek (zipFile->fd, offset, HySeekSet);
-      if ((seekResult < 0) || (seekResult > HYCONST64 (0x7FFFFFFF)))
-        {
-          zipFile->pointer = -1;
-          EXIT ();
-          return ZIP_ERR_FILE_READ_ERROR;
-        }
-      zipFile->pointer = (I_32) seekResult;
-      if (zipFile->pointer != offset)
-        {
-          zipFile->pointer = -1;
-          EXIT ();
-          return ZIP_ERR_FILE_READ_ERROR;
-        }
-    }
-
-  result = readZipEntry (portLib, zipFile, entry, NULL, NULL, NULL, FALSE);
-  EXIT ();
-  return result;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zdataalloc
-/*
-	cached alloc management for zip_getZipEntryData.
-*/
-void *
-zdataalloc (void *opaque, U_32 items, U_32 size)
-{
-  UDATA *returnVal = 0;
-  U_32 byteSize = items * size;
-  U_32 allocSize = WORK_BUFFER_SIZE;
-  struct workBuffer *wb = (struct workBuffer *) opaque;
-
-  PORT_ACCESS_FROM_PORT (wb->portLib);
-
-  /* Round to UDATA multiple */
-  byteSize = (byteSize + (sizeof (UDATA) - 1)) & ~(sizeof (UDATA) - 1);
-
-  if (wb->bufferStart == 0)
-    {
-      if (byteSize > WORK_BUFFER_SIZE)
-        {
-          allocSize = byteSize;
-        }
-      wb->bufferStart = hymem_allocate_memory (allocSize);
-      if (wb->bufferStart)
-        {
-          wb->bufferEnd = (UDATA *) ((UDATA) wb->bufferStart + allocSize);
-          wb->currentAlloc = wb->bufferStart;
-          wb->cntr = 0;
-        }
-    }
-
-  if ((wb->bufferStart == 0)
-      || (((UDATA) wb->currentAlloc + byteSize) > (UDATA) wb->bufferEnd))
-    {
-      returnVal = hymem_allocate_memory (byteSize);
-    }
-  else
-    {
-      ++(wb->cntr);
-      returnVal = wb->currentAlloc;
-      wb->currentAlloc = (UDATA *) ((UDATA) wb->currentAlloc + byteSize);
-    }
-  return returnVal;
-}
-
-#undef CDEV_CURRENT_FUNCTION
-
-#define CDEV_CURRENT_FUNCTION zdatafree
-/*
-	cached alloc management for zip_getZipEntryData.
-*/
-void
-zdatafree (void *opaque, void *address)
-{
-  struct workBuffer *wb = (struct workBuffer *) opaque;
-
-  PORT_ACCESS_FROM_PORT (wb->portLib);
-
-  if ((address < (void *) wb->bufferStart)
-      || (address >= (void *) wb->bufferEnd))
-    {
-      hymem_free_memory (address);
-    }
-  else if (--(wb->cntr) == 0)
-    {
-      hymem_free_memory (wb->bufferStart);
-      wb->bufferStart = wb->bufferEnd = wb->currentAlloc = 0;
-    }
-
-}
-
-#undef CDEV_CURRENT_FUNCTION
diff --git a/luni/src/main/native/zipsup.h b/luni/src/main/native/zipsup.h
deleted file mode 100644
index 67a2eda..0000000
--- a/luni/src/main/native/zipsup.h
+++ /dev/null
@@ -1,232 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.
- */
-
-/**
-* Zip Support Header
-*/
-
-#if !defined(ZIPSUP_H)
-#define ZIPSUP_H
-#if defined(__cplusplus)
-extern "C"
-{
-#endif
-#include "hy2sie.h"
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <memory.h>
-
-#include "zlib.h"
-
-
-typedef struct HyZipCachePool HyZipCachePool;
-
-HyZipCachePool *
-zipsup_GetZipCachePool(HyPortLibrary * portLib);
-
-
-#if defined(HY_LOCAL_ZLIB)
-#define HY_ZIP_DLL_NAME "z"
-#else
-#define HY_ZIP_DLL_NAME "hyzlib"
-#endif
-
-#define ZIP_INTERNAL_MAX  80
-#define ZIP_CM_Reduced1  2
-#define ZIP_Unknown  0
-#define ZIP_GZIP  2
-#define ZIP_ERR_OUT_OF_MEMORY  -3
-#define ZIP_ERR_FILE_CORRUPT  -6
-#define ZIP_ERR_INTERNAL_ERROR  -11
-#define ZIP_CM_Imploded  6
-#define ZIP_CM_Reduced4  5
-#define ZIP_CM_Shrunk  1
-#define ZIP_CM_Reduced2  3
-#define ZIP_ERR_FILE_READ_ERROR  -1
-#define ZIP_CentralHeader  0x2014B50
-#define ZIP_ERR_FILE_CLOSE_ERROR  -10
-#define ZIP_ERR_BUFFER_TOO_SMALL  -7
-#define ZIP_CM_Reduced3  4
-#define ZIP_CM_Deflated  8
-#define ZIP_LocalHeader  0x4034B50
-#define ZIP_CM_Tokenized  7
-#define ZIP_PKZIP  1
-#define ZIP_CM_Stored  0
-#define ZIP_ERR_UNSUPPORTED_FILE_TYPE  -5
-#define ZIP_ERR_NO_MORE_ENTRIES  -2
-#define ZIP_CentralEnd  0x6054B50
-#define ZIP_ERR_FILE_OPEN_ERROR  -9
-#define ZIP_ERR_UNKNOWN_FILE_TYPE  -4
-#define ZIP_ERR_ENTRY_NOT_FOUND  -8
-#define ZIP_DataDescriptor  0x8074B50
-
-  typedef struct HyZipCache
-  {
-    U_8 *zipFileName;
-    IDATA zipFileSize;
-    I_64 zipTimeStamp;
-    IDATA startCentralDir;
-    HyPortLibrary *portLib;
-    void *cachePool;
-    void *cachePoolEntry;
-  } HyZipCache;
-
-
-  typedef struct HyZipCentralEnd
-  {
-    U_16 diskNumber;
-    U_16 dirStartDisk;
-    U_16 thisDiskEntries;
-    U_16 totalEntries;
-    U_32 dirSize;
-    U_32 dirOffset;
-    U_16 commentLength;
-    char _hypadding0012[2];   /* 2 bytes of automatic padding */
-    U_8 *comment;
-  } HyZipCentralEnd;
-
-
-  typedef struct HyZipDataDescriptor
-  {
-    U_32 crc32;
-    U_32 compressedSize;
-    U_32 uncompressedSize;
-  } HyZipDataDescriptor;
-
-
-  typedef struct HyZipEntry
-  {
-    U_8 *data;
-    U_8 *filename;
-    U_8 *extraField;
-    U_8 *fileComment;
-    I_32 dataPointer;
-    I_32 filenamePointer;
-    I_32 extraFieldPointer;
-    I_32 fileCommentPointer;
-    U_32 compressedSize;
-    U_32 uncompressedSize;
-    U_32 crc32;
-    U_16 filenameLength;
-    U_16 extraFieldLength;
-    U_16 fileCommentLength;
-    U_16 internalAttributes;
-    U_16 versionCreated;
-    U_16 versionNeeded;
-    U_16 flags;
-    U_16 compressionMethod;
-    U_16 lastModTime;
-    U_16 lastModDate;
-    U_8 internalFilename[80];
-  } HyZipEntry;
-
-
-  typedef struct HyZipFile
-  {
-    U_8 *filename;
-    struct HyZipCache *cache;
-    void *cachePool;
-    I_32 fd;
-    I_32 pointer;
-    U_8 internalFilename[80];
-    U_8 type;
-    char _hypadding0065[3];  /* 3 bytes of automatic padding */
-  } HyZipFile;
-
-
-
-#include "hymutex.h"
-extern MUTEX zip_GlobalMutex;
-
-
-
-#define jclmem_allocate_memory(env, byteCount) sieb_malloc(env, byteCount)
-#define jclmem_free_memory(env, pointer) sieb_free(env, pointer)
-
-
-/* HySourceZipSupport*/
-  extern HY_CFUNC I_32 zip_getZipEntryData
-    PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile,
-                HyZipEntry * entry, U_8 * buffer, U_32 bufferSize));
-  extern HY_CFUNC I_32 zip_getZipEntryFromOffset
-    PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile,
-                HyZipEntry * entry, IDATA offset));
-  extern HY_CFUNC I_32 zip_establishCache
-    PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile));
-  extern HY_CFUNC void zip_resetZipFile
-    PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile,
-                IDATA * nextEntryPointer));
-  extern HY_CFUNC I_32 zip_getNextZipEntry
-    PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile,
-                HyZipEntry * zipEntry, IDATA * nextEntryPointer));
-  extern HY_CFUNC I_32 zip_getZipEntry
-    PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile,
-                HyZipEntry * entry, const char *filename,
-                BOOLEAN findDirectory));
-  extern HY_CFUNC I_32 zip_getZipEntryExtraField
-    PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile,
-                HyZipEntry * entry, U_8 * buffer, U_32 bufferSize));
-  extern HY_CFUNC void zip_initZipEntry
-    PROTOTYPE ((HyPortLibrary * portLib, HyZipEntry * entry));
-  extern HY_CFUNC I_32 zip_openZipFile
-    PROTOTYPE ((HyPortLibrary * portLib, char *filename, HyZipFile * zipFile,
-                HyZipCachePool * cachePool));
-  extern HY_CFUNC void zip_freeZipEntry
-    PROTOTYPE ((HyPortLibrary * portLib, HyZipEntry * entry));
-  struct HyZipFile;
-  extern HY_CFUNC I_32 VMCALL zip_closeZipFile
-    PROTOTYPE ((HyPortLibrary * portLib, struct HyZipFile * zipFile));
-  extern HY_CFUNC I_32 zip_getZipEntryComment
-    PROTOTYPE ((HyPortLibrary * portLib, HyZipFile * zipFile,
-                HyZipEntry * entry, U_8 * buffer, U_32 bufferSize));
-/* HySourceZipCache*/
-  extern HY_CFUNC UDATA zipCache_findElement
-    PROTOTYPE ((HyZipCache * zipCache, const char *elementName,
-                BOOLEAN searchDirList));
-  extern HY_CFUNC void zipCache_kill PROTOTYPE ((HyZipCache * zipCache));
-  extern HY_CFUNC IDATA zipCache_enumGetDirName
-    PROTOTYPE ((void *handle, char *nameBuf, UDATA nameBufSize));
-  extern HY_CFUNC HyZipCache *zipCache_new
-    PROTOTYPE ((HyPortLibrary * portLib, char *zipName, IDATA zipNameLength));
-  extern HY_CFUNC IDATA zipCache_enumNew
-    PROTOTYPE ((HyZipCache * zipCache, char *directoryName, void **handle));
-  extern HY_CFUNC IDATA zipCache_enumElement
-    PROTOTYPE ((void *handle, char *nameBuf, UDATA nameBufSize,
-                UDATA * offset));
-  extern HY_CFUNC void zipCache_enumKill PROTOTYPE ((void *handle));
-  extern HY_CFUNC BOOLEAN zipCache_addElement
-    PROTOTYPE ((HyZipCache * zipCache, char *elementName,
-                UDATA elementOffset));
-/* HySourceZipCachePool*/
-  extern HY_CFUNC BOOLEAN zipCachePool_release
-    PROTOTYPE ((HyZipCachePool * zcp, HyZipCache * zipCache));
-  extern HY_CFUNC void zipCachePool_kill PROTOTYPE ((HyZipCachePool * zcp));
-  extern HY_CFUNC HyZipCache *zipCachePool_findCache
-    PROTOTYPE ((HyZipCachePool * zcp, char const *zipFileName,
-                IDATA zipFileNameLength, IDATA zipFileSize,
-                I_64 zipTimeStamp));
-  extern HY_CFUNC HyZipCachePool *zipCachePool_new
-    PROTOTYPE ((HyPortLibrary * portLib));
-  extern HY_CFUNC BOOLEAN zipCachePool_addCache
-    PROTOTYPE ((HyZipCachePool * zcp, HyZipCache * zipCache));
-  extern HY_CFUNC BOOLEAN zipCachePool_addRef
-    PROTOTYPE ((HyZipCachePool * zcp, HyZipCache * zipCache));
-#if defined(__cplusplus)
-}
-#endif
-#endif /* ZIPSUP_H */