diff options
author | Anthony Green <green@redhat.com> | 2000-09-06 02:13:28 +0000 |
---|---|---|
committer | Anthony Green <green@gcc.gnu.org> | 2000-09-06 02:13:28 +0000 |
commit | 3ca8c9aea002945be6cc6164d3eee6e55acc1b67 (patch) | |
tree | f11498ff99199cfd9ecb821a470faf66c9a566dd /gcc/java/jcf-io.c | |
parent | 2a7ffc85e5eb9506241ee725324156bc3da9cf69 (diff) | |
download | gcc-3ca8c9aea002945be6cc6164d3eee6e55acc1b67.zip gcc-3ca8c9aea002945be6cc6164d3eee6e55acc1b67.tar.gz gcc-3ca8c9aea002945be6cc6164d3eee6e55acc1b67.tar.bz2 |
jcf-io.c: Include zlib.h.
2000-09-02 Anthony Green <green@redhat.com>
* jcf-io.c: Include zlib.h.
(open_in_zip): Read compressed class file archives.
* zipfile.h (ZipDirectory): Add uncompressed_size and
compression_method fields.
* zextract.c (read_zip_archive): Collect file compression info.
From-SVN: r36175
Diffstat (limited to 'gcc/java/jcf-io.c')
-rw-r--r-- | gcc/java/jcf-io.c | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/gcc/java/jcf-io.c b/gcc/java/jcf-io.c index b4f4e2e..7bd4fe8 100644 --- a/gcc/java/jcf-io.c +++ b/gcc/java/jcf-io.c @@ -30,6 +30,8 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ #include "toplev.h" #include "java-tree.h" +#include "zlib.h" + /* DOS brain-damage */ #ifndef O_BINARY #define O_BINARY 0 /* MS-DOS brain-damage */ @@ -149,6 +151,7 @@ DEFUN(open_in_zip, (jcf, zipfile, zipmember, is_system), ZipDirectory *zipd; int i, len; ZipFile *zipf = opendir_in_zip (zipfile, is_system); + z_stream d_stream; /* decompression stream */ if (zipf == NULL) return -2; @@ -156,6 +159,10 @@ DEFUN(open_in_zip, (jcf, zipfile, zipmember, is_system), if (!zipmember) return 0; + d_stream.zalloc = (alloc_func) 0; + d_stream.zfree = (free_func) 0; + d_stream.opaque = (voidpf) 0; + len = strlen (zipmember); zipd = (struct ZipDirectory*) zipf->central_directory; @@ -165,17 +172,45 @@ DEFUN(open_in_zip, (jcf, zipfile, zipmember, is_system), strncmp (ZIPDIR_FILENAME (zipd), zipmember, len) == 0) { JCF_ZERO (jcf); - jcf->buffer = ALLOC (zipd->size); - jcf->buffer_end = jcf->buffer + zipd->size; - jcf->read_ptr = jcf->buffer; - jcf->read_end = jcf->buffer_end; + jcf->filbuf = jcf_unexpected_eof; jcf->filename = xstrdup (zipfile); jcf->classname = xstrdup (zipmember); jcf->zipd = (void *)zipd; - if (lseek (zipf->fd, zipd->filestart, 0) < 0 - || read (zipf->fd, jcf->buffer, zipd->size) != zipd->size) - return -2; + + if (zipd->compression_method == Z_NO_COMPRESSION) + { + jcf->buffer = ALLOC (zipd->size); + jcf->buffer_end = jcf->buffer + zipd->size; + jcf->read_ptr = jcf->buffer; + jcf->read_end = jcf->buffer_end; + if (lseek (zipf->fd, zipd->filestart, 0) < 0 + || read (zipf->fd, jcf->buffer, zipd->size) != zipd->size) + return -2; + } + else + { + char *buffer; + jcf->buffer = ALLOC (zipd->uncompressed_size); + d_stream.next_out = jcf->buffer; + d_stream.avail_out = zipd->uncompressed_size; + jcf->buffer_end = jcf->buffer + zipd->uncompressed_size; + jcf->read_ptr = jcf->buffer; + jcf->read_end = jcf->buffer_end; + buffer = ALLOC (zipd->size); + d_stream.next_in = buffer; + d_stream.avail_in = zipd->size; + if (lseek (zipf->fd, zipd->filestart, 0) < 0 + || read (zipf->fd, buffer, zipd->size) != zipd->size) + return -2; + /* Handle NO_HEADER using undocumented zlib feature. + This is a very common hack. */ + inflateInit2 (&d_stream, -MAX_WBITS); + inflate (&d_stream, Z_NO_FLUSH); + inflateEnd (&d_stream); + FREE (buffer); + } + return 0; } } |