src/java.base/share/native/libzip/ZipFile.c

Print this page




  76                             "java/util/zip/ZipException",
  77                             "(Ljava/lang/String;)V", s);
  78         if (x != NULL) {
  79             (*env)->Throw(env, x);
  80         }
  81     }
  82 }
  83 
  84 JNIEXPORT jlong JNICALL
  85 Java_java_util_zip_ZipFile_open(JNIEnv *env, jclass cls, jstring name,
  86                                         jint mode, jlong lastModified,
  87                                         jboolean usemmap)
  88 {
  89     const char *path = JNU_GetStringPlatformChars(env, name, 0);
  90     char *msg = 0;
  91     jlong result = 0;
  92     int flag = 0;
  93     jzfile *zip = 0;
  94 
  95     if (mode & OPEN_READ) flag |= O_RDONLY;
  96     if (mode & OPEN_DELETE) flag |= JVM_O_DELETE;
  97 
  98     if (path != 0) {
  99         zip = ZIP_Get_From_Cache(path, &msg, lastModified);
 100         if (zip == 0 && msg == 0) {
 101             ZFILE zfd = 0;
 102 #ifdef WIN32

 103             zfd = winFileHandleOpen(env, name, flag);
 104             if (zfd == -1) {
 105                 /* Exception already pending. */
 106                 goto finally;
 107             }
 108 #else
 109             zfd = JVM_Open(path, flag, 0);
 110             if (zfd < 0) {
 111                 throwFileNotFoundException(env, name);
 112                 goto finally;
 113             }



 114 #endif
 115             zip = ZIP_Put_In_Cache0(path, zfd, &msg, lastModified, usemmap);
 116         }
 117 
 118         if (zip != 0) {
 119             result = ptr_to_jlong(zip);
 120         } else if (msg != 0) {
 121             ThrowZipException(env, msg);
 122             free(msg);
 123         } else if (errno == ENOMEM) {
 124             JNU_ThrowOutOfMemoryError(env, 0);
 125         } else {
 126             ThrowZipException(env, "error in opening zip file");
 127         }
 128 finally:
 129         JNU_ReleaseStringPlatformChars(env, name, path);
 130     }
 131     return result;
 132 }
 133 




  76                             "java/util/zip/ZipException",
  77                             "(Ljava/lang/String;)V", s);
  78         if (x != NULL) {
  79             (*env)->Throw(env, x);
  80         }
  81     }
  82 }
  83 
  84 JNIEXPORT jlong JNICALL
  85 Java_java_util_zip_ZipFile_open(JNIEnv *env, jclass cls, jstring name,
  86                                         jint mode, jlong lastModified,
  87                                         jboolean usemmap)
  88 {
  89     const char *path = JNU_GetStringPlatformChars(env, name, 0);
  90     char *msg = 0;
  91     jlong result = 0;
  92     int flag = 0;
  93     jzfile *zip = 0;
  94 
  95     if (mode & OPEN_READ) flag |= O_RDONLY;

  96 
  97     if (path != 0) {
  98         zip = ZIP_Get_From_Cache(path, &msg, lastModified);
  99         if (zip == 0 && msg == 0) {
 100             ZFILE zfd = 0;
 101 #ifdef WIN32
 102             if (mode & OPEN_DELETE) flag |= O_TEMPORARY;
 103             zfd = winFileHandleOpen(env, name, flag);
 104             if (zfd == -1) {
 105                 /* Exception already pending. */
 106                 goto finally;
 107             }
 108 #else
 109             zfd = open(path, flag, 0);
 110             if (zfd < 0) {
 111                 throwFileNotFoundException(env, name);
 112                 goto finally;
 113             }
 114             if (mode & OPEN_DELETE) {
 115                 unlink(path);
 116             }
 117 #endif
 118             zip = ZIP_Put_In_Cache0(path, zfd, &msg, lastModified, usemmap);
 119         }
 120 
 121         if (zip != 0) {
 122             result = ptr_to_jlong(zip);
 123         } else if (msg != 0) {
 124             ThrowZipException(env, msg);
 125             free(msg);
 126         } else if (errno == ENOMEM) {
 127             JNU_ThrowOutOfMemoryError(env, 0);
 128         } else {
 129             ThrowZipException(env, "error in opening zip file");
 130         }
 131 finally:
 132         JNU_ReleaseStringPlatformChars(env, name, path);
 133     }
 134     return result;
 135 }
 136