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