JNIEXPORT jlong JNICALL Java_java_util_zip_ZipFile_open(JNIEnv *env, jclass cls, jstring name, jint mode, jlong lastModified, jboolean usemmap) { const char *path = JNU_GetStringPlatformChars(env, name, 0); char *msg = 0; jlong result = 0; int flag = 0; jzfile *zip = 0; if (mode & OPEN_READ) flag |= O_RDONLY; if (mode & OPEN_DELETE) flag |= JVM_O_DELETE; if (path != 0) { zip = ZIP_Get_From_Cache(path, &msg, lastModified); if (zip == 0 && msg == 0) { ZFILE zfd = 0; #ifdef WIN32 zfd = winFileHandleOpen(env, name, flag); if (zfd == -1) { /* Exception already pending. */ goto finally; } #else zfd = JVM_Open(path, flag, 0); if (zfd < 0) { throwFileNotFoundException(env, name); goto finally; } #endif zip = ZIP_Put_In_Cache0(path, zfd, &msg, lastModified, usemmap); } if (zip != 0) { result = ptr_to_jlong(zip); } else if (msg != 0) { ThrowZipException(env, msg); free(msg); } else if (errno == ENOMEM) { JNU_ThrowOutOfMemoryError(env, 0); } else { ThrowZipException(env, "error in opening zip file"); } finally: JNU_ReleaseStringPlatformChars(env, name, path); } return result; }
jzfile * ZIP_Put_In_Cache(const char *name, ZFILE zfd, char **pmsg, jlong lastModified) { return ZIP_Put_In_Cache0(name, zfd, pmsg, lastModified, JNI_TRUE); }