jzfile * ZIP_Put_In_Cache0(const char *name, ZFILE zfd, char **pmsg, jlong lastModified, jboolean usemmap) { static char errbuf[256]; jlong len; jzfile *zip; if ((zip = allocZip(name)) == NULL) { return NULL; } #ifdef USE_MMAP zip->usemmap = usemmap; #endif zip->refs = 1; zip->lastModified = lastModified; if (zfd == -1) { if (pmsg && JVM_GetLastErrorString(errbuf, sizeof(errbuf)) > 0) *pmsg = errbuf; freeZip(zip); return NULL; } len = zip->len = IO_Lseek(zfd, 0, SEEK_END); //获取当前jar/zip文件的长度 if (len <= 0) { if (len == 0) { /* zip file is empty */ if (pmsg) { *pmsg = "zip file is empty"; } } else { /* error */ if (pmsg && JVM_GetLastErrorString(errbuf, sizeof(errbuf)) > 0) *pmsg = errbuf; } ZFILE_Close(zfd); freeZip(zip); return NULL; } zip->zfd = zfd; //当前jar/zip文件的文件描述符 if (readCEN(zip, -1) < 0) { /* An error occurred while trying to read the zip file */ if (pmsg != 0) { /* Set the zip error message */ *pmsg = zip->msg; } freeZip(zip); return NULL; } MLOCK(zfiles_lock); zip->next = zfiles; zfiles = zip; MUNLOCK(zfiles_lock); return zip; }
static void win32Error(JNIEnv *env, const char *functionName) { static const char * const format = "%s error=%d, %s"; static const char * const fallbackFormat = "%s failed, error=%d"; char buf[256]; char errmsg[sizeof(buf) + 100]; const int errnum = GetLastError(); const int n = JVM_GetLastErrorString(buf, sizeof(buf)); if (n > 0) sprintf(errmsg, format, functionName, errnum, buf); else sprintf(errmsg, fallbackFormat, functionName, errnum); JNU_ThrowIOException(env, errmsg); }
jzfile * ZIP_Put_In_Cache0(const char *name, ZFILE zfd, char **pmsg, jlong lastModified, jboolean usemmap) { char errbuf[256]; jlong len; jzfile *zip; if ((zip = allocZip(name)) == NULL) { return NULL; } #ifdef USE_MMAP zip->usemmap = usemmap; #endif zip->refs = 1; zip->lastModified = lastModified; if (zfd == -1) { if (pmsg && JVM_GetLastErrorString(errbuf, sizeof(errbuf)) > 0) *pmsg = strdup(errbuf); freeZip(zip); return NULL; } // Assumption, zfd refers to start of file. Trivially, reuse errbuf. if (readFully(zfd, errbuf, 4) != -1) { // errors will be handled later if (GETSIG(errbuf) == LOCSIG) zip->locsig = JNI_TRUE; else zip->locsig = JNI_FALSE; } len = zip->len = IO_Lseek(zfd, 0, SEEK_END); if (len <= 0) { if (len == 0) { /* zip file is empty */ if (pmsg) { *pmsg = strdup("zip file is empty"); } } else { /* error */ if (pmsg && JVM_GetLastErrorString(errbuf, sizeof(errbuf)) > 0) *pmsg = strdup(errbuf); } ZFILE_Close(zfd); freeZip(zip); return NULL; } zip->zfd = zfd; if (readCEN(zip, -1) < 0) { /* An error occurred while trying to read the zip file */ if (pmsg != 0) { /* Set the zip error message */ if (zip->msg != NULL) *pmsg = strdup(zip->msg); } freeZip(zip); return NULL; } MLOCK(zfiles_lock); zip->next = zfiles; zfiles = zip; MUNLOCK(zfiles_lock); return zip; }