jdk/src/share/native/java/util/zip/zip_util.c
changeset 1228 1515928f48cd
parent 2 90ce3da70b43
child 1572 9fed7b18f517
equal deleted inserted replaced
1227:4546977d0d66 1228:1515928f48cd
     1 /*
     1 /*
     2  * Copyright 1995-2006 Sun Microsystems, Inc.  All Rights Reserved.
     2  * Copyright 1995-2008 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Sun designates this
     7  * published by the Free Software Foundation.  Sun designates this
   720         freeZip(zip);
   720         freeZip(zip);
   721         return NULL;
   721         return NULL;
   722     }
   722     }
   723 
   723 
   724     len = zip->len = ZFILE_Lseek(zfd, 0, SEEK_END);
   724     len = zip->len = ZFILE_Lseek(zfd, 0, SEEK_END);
   725     if (len == -1) {
   725     if (len <= 0) {
   726         if (pmsg && JVM_GetLastErrorString(errbuf, sizeof(errbuf)) > 0)
   726         if (len == 0) { /* zip file is empty */
   727             *pmsg = errbuf;
   727             if (pmsg) {
       
   728                 *pmsg = "zip file is empty";
       
   729             }
       
   730         } else { /* error */
       
   731             if (pmsg && JVM_GetLastErrorString(errbuf, sizeof(errbuf)) > 0)
       
   732                 *pmsg = errbuf;
       
   733         }
   728         ZFILE_Close(zfd);
   734         ZFILE_Close(zfd);
   729         freeZip(zip);
   735         freeZip(zip);
   730         return NULL;
   736         return NULL;
   731     }
   737     }
   732 
   738 
   733     zip->zfd = zfd;
   739     zip->zfd = zfd;
   734     if (readCEN(zip, -1) <= 0) {
   740     if (readCEN(zip, -1) < 0) {
   735         /* An error occurred while trying to read the zip file */
   741         /* An error occurred while trying to read the zip file */
   736         if (pmsg != 0) {
   742         if (pmsg != 0) {
   737             /* Set the zip error message */
   743             /* Set the zip error message */
   738             *pmsg = zip->msg;
   744             *pmsg = zip->msg;
   739         }
   745         }
   945  */
   951  */
   946 jzentry *
   952 jzentry *
   947 ZIP_GetEntry(jzfile *zip, char *name, jint ulen)
   953 ZIP_GetEntry(jzfile *zip, char *name, jint ulen)
   948 {
   954 {
   949     unsigned int hsh = hash(name);
   955     unsigned int hsh = hash(name);
   950     jint idx = zip->table[hsh % zip->tablelen];
   956     jint idx;
   951     jzentry *ze;
   957     jzentry *ze = 0;
   952 
   958 
   953     ZIP_Lock(zip);
   959     ZIP_Lock(zip);
       
   960     if (zip->total == 0) {
       
   961         goto Finally;
       
   962     }
       
   963 
       
   964     idx = zip->table[hsh % zip->tablelen];
   954 
   965 
   955     /*
   966     /*
   956      * This while loop is an optimization where a double lookup
   967      * This while loop is an optimization where a double lookup
   957      * for name and name+/ is being performed. The name char
   968      * for name and name+/ is being performed. The name char
   958      * array has enough room at the end to try again with a
   969      * array has enough room at the end to try again with a
  1023         hsh = hash_append(hsh, '/');
  1034         hsh = hash_append(hsh, '/');
  1024         idx = zip->table[hsh % zip->tablelen];
  1035         idx = zip->table[hsh % zip->tablelen];
  1025         ulen = 0;
  1036         ulen = 0;
  1026     }
  1037     }
  1027 
  1038 
       
  1039 Finally:
  1028     ZIP_Unlock(zip);
  1040     ZIP_Unlock(zip);
  1029     return ze;
  1041     return ze;
  1030 }
  1042 }
  1031 
  1043 
  1032 /*
  1044 /*