src/share/native/java/util/zip/zip_util.c

Print this page




1432 ZIP_FindEntry(jzfile *zip, char *name, jint *sizeP, jint *nameLenP)
1433 {
1434     jzentry *entry = ZIP_GetEntry(zip, name, 0);
1435     if (entry) {
1436         *sizeP = (jint)entry->size;
1437         *nameLenP = strlen(entry->name);
1438     }
1439     return entry;
1440 }
1441 
1442 /*
1443  * Reads a zip file entry into the specified byte array
1444  * When the method completes, it releases the jzentry.
1445  * Note: this is called from the separately delivered VM (hotspot/classic)
1446  * so we have to be careful to maintain the expected behaviour.
1447  */
1448 jboolean JNICALL
1449 ZIP_ReadEntry(jzfile *zip, jzentry *entry, unsigned char *buf, char *entryname)
1450 {
1451     char *msg;

1452 
1453     strcpy(entryname, entry->name);
1454     if (entry->csize == 0) {
1455         /* Entry is stored */
1456         jlong pos = 0;
1457         jlong size = entry->size;
1458         while (pos < size) {
1459             jint n;
1460             jlong limit = ((((jlong) 1) << 31) - 1);
1461             jint count = (size - pos < limit) ?
1462                 /* These casts suppress a VC++ Internal Compiler Error */
1463                 (jint) (size - pos) :
1464                 (jint) limit;
1465             ZIP_Lock(zip);
1466             n = ZIP_Read(zip, entry, pos, buf, count);
1467             msg = zip->msg;
1468             ZIP_Unlock(zip);
1469             if (n == -1) {
1470                 jio_fprintf(stderr, "%s: %s\n", zip->name,
1471                             msg != 0 ? msg : strerror(errno));



1472                 return JNI_FALSE;
1473             }
1474             buf += n;
1475             pos += n;
1476         }
1477     } else {
1478         /* Entry is compressed */
1479         int ok = InflateFully(zip, entry, buf, &msg);
1480         if (!ok) {
1481             if ((msg == NULL) || (*msg == 0)) {
1482                 msg = zip->msg;
1483             }
1484             jio_fprintf(stderr, "%s: %s\n", zip->name,
1485                         msg != 0 ? msg : strerror(errno));



1486             return JNI_FALSE;
1487         }
1488     }
1489 
1490     ZIP_FreeEntry(zip, entry);
1491 
1492     return JNI_TRUE;
1493 }


1432 ZIP_FindEntry(jzfile *zip, char *name, jint *sizeP, jint *nameLenP)
1433 {
1434     jzentry *entry = ZIP_GetEntry(zip, name, 0);
1435     if (entry) {
1436         *sizeP = (jint)entry->size;
1437         *nameLenP = strlen(entry->name);
1438     }
1439     return entry;
1440 }
1441 
1442 /*
1443  * Reads a zip file entry into the specified byte array
1444  * When the method completes, it releases the jzentry.
1445  * Note: this is called from the separately delivered VM (hotspot/classic)
1446  * so we have to be careful to maintain the expected behaviour.
1447  */
1448 jboolean JNICALL
1449 ZIP_ReadEntry(jzfile *zip, jzentry *entry, unsigned char *buf, char *entryname)
1450 {
1451     char *msg;
1452     char tmpbuf[1024];
1453 
1454     strcpy(entryname, entry->name);
1455     if (entry->csize == 0) {
1456         /* Entry is stored */
1457         jlong pos = 0;
1458         jlong size = entry->size;
1459         while (pos < size) {
1460             jint n;
1461             jlong limit = ((((jlong) 1) << 31) - 1);
1462             jint count = (size - pos < limit) ?
1463                 /* These casts suppress a VC++ Internal Compiler Error */
1464                 (jint) (size - pos) :
1465                 (jint) limit;
1466             ZIP_Lock(zip);
1467             n = ZIP_Read(zip, entry, pos, buf, count);
1468             msg = zip->msg;
1469             ZIP_Unlock(zip);
1470             if (n == -1) {
1471                 if (msg == 0) {
1472                     getErrorString(errno, tmpbuf, sizeof(tmpbuf));
1473                     msg = tmpbuf;
1474                 }
1475                 jio_fprintf(stderr, "%s: %s\n", zip->name, msg);
1476                 return JNI_FALSE;
1477             }
1478             buf += n;
1479             pos += n;
1480         }
1481     } else {
1482         /* Entry is compressed */
1483         int ok = InflateFully(zip, entry, buf, &msg);
1484         if (!ok) {
1485             if ((msg == NULL) || (*msg == 0)) {
1486                 msg = zip->msg;
1487             }
1488             if (msg == 0) {
1489                 getErrorString(errno, tmpbuf, sizeof(tmpbuf));
1490                 msg = tmpbuf;
1491             }
1492             jio_fprintf(stderr, "%s: %s\n", zip->name, msg);
1493             return JNI_FALSE;
1494         }
1495     }
1496 
1497     ZIP_FreeEntry(zip, entry);
1498 
1499     return JNI_TRUE;
1500 }