jdk/src/java.base/share/native/libzip/ZipFile.c
author fparain
Thu, 09 Oct 2014 04:48:12 -0700
changeset 27184 2996674bd701
parent 25859 3317bb8137f4
child 27186 c1b8debdfcc2
permissions -rw-r--r--
8057777: Cleanup of old and unused VM interfaces Reviewed-by: coleenp, hseigel, alanb, sherman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22643
ba2891b3f866 8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents: 18223
diff changeset
     2
 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5148
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5148
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5148
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5148
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5148
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * Native method support for java.util.zip.ZipFile
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <errno.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <ctype.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <assert.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "jlong.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "jvm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "zip_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#ifdef WIN32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#include "io_util_md.h"
3078
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
    43
#else
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
    44
#include "io_util.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#include "java_util_zip_ZipFile.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#include "java_util_jar_JarFile.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#define DEFLATED 8
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#define STORED 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
static jfieldID jzfileID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
static int OPEN_READ = java_util_zip_ZipFile_OPEN_READ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
static int OPEN_DELETE = java_util_zip_ZipFile_OPEN_DELETE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
Java_java_util_zip_ZipFile_initIDs(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    jzfileID = (*env)->GetFieldID(env, cls, "jzfile", "J");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    assert(jzfileID != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
ThrowZipException(JNIEnv *env, const char *msg)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    jstring s = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    jobject x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    if (msg != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        s = JNU_NewStringPlatform(env, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
22643
ba2891b3f866 8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents: 18223
diff changeset
    74
    if (s != NULL) {
ba2891b3f866 8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents: 18223
diff changeset
    75
        x = JNU_NewObjectByName(env,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                            "java/util/zip/ZipException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                            "(Ljava/lang/String;)V", s);
22643
ba2891b3f866 8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents: 18223
diff changeset
    78
        if (x != NULL) {
ba2891b3f866 8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents: 18223
diff changeset
    79
            (*env)->Throw(env, x);
ba2891b3f866 8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents: 18223
diff changeset
    80
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
Java_java_util_zip_ZipFile_open(JNIEnv *env, jclass cls, jstring name,
5148
2bf5469864ea 6929479: Add a system property sun.zip.disableMemoryMapping to disable mmap use in ZipFile
sherman
parents: 3078
diff changeset
    86
                                        jint mode, jlong lastModified,
2bf5469864ea 6929479: Add a system property sun.zip.disableMemoryMapping to disable mmap use in ZipFile
sherman
parents: 3078
diff changeset
    87
                                        jboolean usemmap)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    const char *path = JNU_GetStringPlatformChars(env, name, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    char *msg = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    jlong result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    int flag = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    jzfile *zip = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    if (mode & OPEN_READ) flag |= O_RDONLY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    if (path != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        zip = ZIP_Get_From_Cache(path, &msg, lastModified);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (zip == 0 && msg == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            ZFILE zfd = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
#ifdef WIN32
27184
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
   102
            if (mode & OPEN_DELETE) flag |= O_TEMPORARY;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            zfd = winFileHandleOpen(env, name, flag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            if (zfd == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                /* Exception already pending. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                goto finally;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
#else
27184
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
   109
            zfd = open(path, flag, 0);
3078
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   110
            if (zfd < 0) {
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   111
                throwFileNotFoundException(env, name);
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   112
                goto finally;
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   113
            }
27184
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
   114
            if (mode & OPEN_DELETE) {
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
   115
                unlink(path);
2996674bd701 8057777: Cleanup of old and unused VM interfaces
fparain
parents: 25859
diff changeset
   116
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
#endif
5148
2bf5469864ea 6929479: Add a system property sun.zip.disableMemoryMapping to disable mmap use in ZipFile
sherman
parents: 3078
diff changeset
   118
            zip = ZIP_Put_In_Cache0(path, zfd, &msg, lastModified, usemmap);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (zip != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            result = ptr_to_jlong(zip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        } else if (msg != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            ThrowZipException(env, msg);
12543
b77bc2f404ba 7159982: ZipFile uses static for error message when malformed zip file encountered
zhouyx
parents: 7668
diff changeset
   125
            free(msg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        } else if (errno == ENOMEM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            JNU_ThrowOutOfMemoryError(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            ThrowZipException(env, "error in opening zip file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
finally:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        JNU_ReleaseStringPlatformChars(env, name, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
Java_java_util_zip_ZipFile_getTotal(JNIEnv *env, jclass cls, jlong zfile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    jzfile *zip = jlong_to_ptr(zfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    return zip->total;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
18223
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 14342
diff changeset
   145
JNIEXPORT jboolean JNICALL
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 14342
diff changeset
   146
Java_java_util_zip_ZipFile_startsWithLOC(JNIEnv *env, jclass cls, jlong zfile)
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 14342
diff changeset
   147
{
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 14342
diff changeset
   148
    jzfile *zip = jlong_to_ptr(zfile);
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 14342
diff changeset
   149
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 14342
diff changeset
   150
    return zip->locsig;
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 14342
diff changeset
   151
}
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 14342
diff changeset
   152
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
Java_java_util_zip_ZipFile_close(JNIEnv *env, jclass cls, jlong zfile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    ZIP_Close(jlong_to_ptr(zfile));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
Java_java_util_zip_ZipFile_getEntry(JNIEnv *env, jclass cls, jlong zfile,
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   161
                                    jbyteArray name, jboolean addSlash)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
#define MAXNAME 1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    jzfile *zip = jlong_to_ptr(zfile);
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   165
    jsize ulen = (*env)->GetArrayLength(env, name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    char buf[MAXNAME+2], *path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    jzentry *ze;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    if (ulen > MAXNAME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        path = malloc(ulen + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (path == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            JNU_ThrowOutOfMemoryError(env, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        path = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   178
    (*env)->GetByteArrayRegion(env, name, 0, ulen, (jbyte *)path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    path[ulen] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    if (addSlash == JNI_FALSE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        ze = ZIP_GetEntry(zip, path, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        ze = ZIP_GetEntry(zip, path, (jint)ulen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    if (path != buf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        free(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    return ptr_to_jlong(ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
Java_java_util_zip_ZipFile_freeEntry(JNIEnv *env, jclass cls, jlong zfile,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                    jlong zentry)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    jzfile *zip = jlong_to_ptr(zfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    jzentry *ze = jlong_to_ptr(zentry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    ZIP_FreeEntry(zip, ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
JNIEXPORT jlong JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
Java_java_util_zip_ZipFile_getNextEntry(JNIEnv *env, jclass cls, jlong zfile,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                                        jint n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    jzentry *ze = ZIP_GetNextEntry(jlong_to_ptr(zfile), n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    return ptr_to_jlong(ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
JNIEXPORT jint JNICALL
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   209
Java_java_util_zip_ZipFile_getEntryMethod(JNIEnv *env, jclass cls, jlong zentry)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    jzentry *ze = jlong_to_ptr(zentry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    return ze->csize != 0 ? DEFLATED : STORED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   215
JNIEXPORT jint JNICALL
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   216
Java_java_util_zip_ZipFile_getEntryFlag(JNIEnv *env, jclass cls, jlong zentry)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    jzentry *ze = jlong_to_ptr(zentry);
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   219
    return ze->flag;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   220
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   222
JNIEXPORT jlong JNICALL
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   223
Java_java_util_zip_ZipFile_getEntryCSize(JNIEnv *env, jclass cls, jlong zentry)
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   224
{
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   225
    jzentry *ze = jlong_to_ptr(zentry);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    return ze->csize != 0 ? ze->csize : ze->size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
JNIEXPORT jlong JNICALL
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   230
Java_java_util_zip_ZipFile_getEntrySize(JNIEnv *env, jclass cls, jlong zentry)
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   231
{
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   232
    jzentry *ze = jlong_to_ptr(zentry);
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   233
    return ze->size;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   234
}
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   235
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   236
JNIEXPORT jlong JNICALL
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   237
Java_java_util_zip_ZipFile_getEntryTime(JNIEnv *env, jclass cls, jlong zentry)
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   238
{
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   239
    jzentry *ze = jlong_to_ptr(zentry);
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   240
    return (jlong)ze->time & 0xffffffffUL;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   241
}
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   242
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   243
JNIEXPORT jlong JNICALL
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   244
Java_java_util_zip_ZipFile_getEntryCrc(JNIEnv *env, jclass cls, jlong zentry)
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   245
{
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   246
    jzentry *ze = jlong_to_ptr(zentry);
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   247
    return (jlong)ze->crc & 0xffffffffUL;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   248
}
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   249
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   250
JNIEXPORT jbyteArray JNICALL
3078
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   251
Java_java_util_zip_ZipFile_getCommentBytes(JNIEnv *env,
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   252
                                           jclass cls,
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   253
                                           jlong zfile)
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   254
{
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   255
    jzfile *zip = jlong_to_ptr(zfile);
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   256
    jbyteArray jba = NULL;
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   257
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   258
    if (zip->comment != NULL) {
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   259
        if ((jba = (*env)->NewByteArray(env, zip->clen)) == NULL)
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   260
            return NULL;
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   261
        (*env)->SetByteArrayRegion(env, jba, 0, zip->clen, (jbyte*)zip->comment);
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   262
    }
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   263
    return jba;
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   264
}
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   265
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   266
JNIEXPORT jbyteArray JNICALL
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   267
Java_java_util_zip_ZipFile_getEntryBytes(JNIEnv *env,
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   268
                                         jclass cls,
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   269
                                         jlong zentry, jint type)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    jzentry *ze = jlong_to_ptr(zentry);
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   272
    int len = 0;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   273
    jbyteArray jba = NULL;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   274
    switch (type) {
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   275
    case java_util_zip_ZipFile_JZENTRY_NAME:
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   276
        if (ze->name != 0) {
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   277
            len = (int)strlen(ze->name);
25222
5d63cd3696d6 8048990: ZipFile.entries() can't handle empty zip entry names
martin
parents: 22643
diff changeset
   278
            // Unlike for extra and comment, we never return null for
5d63cd3696d6 8048990: ZipFile.entries() can't handle empty zip entry names
martin
parents: 22643
diff changeset
   279
            // an (extremely rarely seen) empty name
5d63cd3696d6 8048990: ZipFile.entries() can't handle empty zip entry names
martin
parents: 22643
diff changeset
   280
            if ((jba = (*env)->NewByteArray(env, len)) == NULL)
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   281
                break;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   282
            (*env)->SetByteArrayRegion(env, jba, 0, len, (jbyte *)ze->name);
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   283
        }
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   284
        break;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   285
    case java_util_zip_ZipFile_JZENTRY_EXTRA:
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   286
        if (ze->extra != 0) {
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   287
            unsigned char *bp = (unsigned char *)&ze->extra[0];
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   288
            len = (bp[0] | (bp[1] << 8));
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   289
            if (len <= 0 || (jba = (*env)->NewByteArray(env, len)) == NULL)
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   290
                break;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   291
            (*env)->SetByteArrayRegion(env, jba, 0, len, &ze->extra[2]);
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   292
        }
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   293
        break;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   294
    case java_util_zip_ZipFile_JZENTRY_COMMENT:
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   295
        if (ze->comment != 0) {
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   296
            len = (int)strlen(ze->comment);
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   297
            if (len == 0 || (jba = (*env)->NewByteArray(env, len)) == NULL)
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   298
                break;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   299
            (*env)->SetByteArrayRegion(env, jba, 0, len, (jbyte*)ze->comment);
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   300
        }
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   301
        break;
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   302
    }
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2
diff changeset
   303
    return jba;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
Java_java_util_zip_ZipFile_read(JNIEnv *env, jclass cls, jlong zfile,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                jlong zentry, jlong pos, jbyteArray bytes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                jint off, jint len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    jzfile *zip = jlong_to_ptr(zfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    char *msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
#define BUFSIZE 8192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /* copy via tmp stack buffer: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    jbyte buf[BUFSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    if (len > BUFSIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        len = BUFSIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    ZIP_Lock(zip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    len = ZIP_Read(zip, jlong_to_ptr(zentry), pos, buf, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    msg = zip->msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    ZIP_Unlock(zip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    if (len != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        (*env)->SetByteArrayRegion(env, bytes, off, len, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    if (len == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        if (msg != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            ThrowZipException(env, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            char errmsg[128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            sprintf(errmsg, "errno: %d, error: %s\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    errno, "Error reading ZIP file");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            JNU_ThrowIOExceptionWithLastError(env, errmsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    return len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
 * Returns an array of strings representing the names of all entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
 * that begin with "META-INF/" (case ignored). This native method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
 * used in JarFile as an optimization when looking up manifest and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
 * signature file entries. Returns null if no entries were found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
JNIEXPORT jobjectArray JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
Java_java_util_jar_JarFile_getMetaInfEntryNames(JNIEnv *env, jobject obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    jlong zfile = (*env)->GetLongField(env, obj, jzfileID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    jzfile *zip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    int i, count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    jobjectArray result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    if (zfile == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        JNU_ThrowByName(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                        "java/lang/IllegalStateException", "zip file closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    zip = jlong_to_ptr(zfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /* count the number of valid ZIP metanames */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    if (zip->metanames != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        for (i = 0; i < zip->metacount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            if (zip->metanames[i] != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /* If some names were found then build array of java strings */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    if (count > 0) {
22643
ba2891b3f866 8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents: 18223
diff changeset
   377
        jclass cls = JNU_ClassString(env);
ba2891b3f866 8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents: 18223
diff changeset
   378
        CHECK_NULL_RETURN(cls, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        result = (*env)->NewObjectArray(env, count, cls, 0);
22643
ba2891b3f866 8029020: Check src/share/native/java/util/zip code for JNI pending exceptions
coffeys
parents: 18223
diff changeset
   380
        CHECK_NULL_RETURN(result, NULL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (result != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            for (i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                jstring str = (*env)->NewStringUTF(env, zip->metanames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                if (str == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                (*env)->SetObjectArrayElement(env, result, i, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                (*env)->DeleteLocalRef(env, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
JNIEXPORT jstring JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
Java_java_util_zip_ZipFile_getZipMessage(JNIEnv *env, jclass cls, jlong zfile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    jzfile *zip = jlong_to_ptr(zfile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    char *msg = zip->msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    if (msg == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    return JNU_NewStringPlatform(env, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
}