xref: /openbsd/gnu/usr.bin/gcc/gcc/java/zextract.c (revision c87b03e5)
1*c87b03e5Sespie /* Handle a .class file embedded in a .zip archive.
2*c87b03e5Sespie    This extracts a member from a .zip file, but does not handle
3*c87b03e5Sespie    uncompression (since that is not needed for classes.zip).
4*c87b03e5Sespie 
5*c87b03e5Sespie    Copyright (C) 1996, 1997, 1998, 1999, 2000  Free Software Foundation, Inc.
6*c87b03e5Sespie 
7*c87b03e5Sespie This program is free software; you can redistribute it and/or modify
8*c87b03e5Sespie it under the terms of the GNU General Public License as published by
9*c87b03e5Sespie the Free Software Foundation; either version 2, or (at your option)
10*c87b03e5Sespie any later version.
11*c87b03e5Sespie 
12*c87b03e5Sespie This program is distributed in the hope that it will be useful,
13*c87b03e5Sespie but WITHOUT ANY WARRANTY; without even the implied warranty of
14*c87b03e5Sespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*c87b03e5Sespie GNU General Public License for more details.
16*c87b03e5Sespie 
17*c87b03e5Sespie You should have received a copy of the GNU General Public License
18*c87b03e5Sespie along with GNU CC; see the file COPYING.  If not, write to
19*c87b03e5Sespie the Free Software Foundation, 59 Temple Place - Suite 330,
20*c87b03e5Sespie Boston, MA 02111-1307, USA.
21*c87b03e5Sespie 
22*c87b03e5Sespie Java and all Java-based marks are trademarks or registered trademarks
23*c87b03e5Sespie of Sun Microsystems, Inc. in the United States and other countries.
24*c87b03e5Sespie The Free Software Foundation is independent of Sun Microsystems, Inc.  */
25*c87b03e5Sespie 
26*c87b03e5Sespie /* Written by Per Bothner <bothner@cygnus.com>, February 1996. */
27*c87b03e5Sespie 
28*c87b03e5Sespie #include "config.h"
29*c87b03e5Sespie #include "system.h"
30*c87b03e5Sespie #include "zipfile.h"
31*c87b03e5Sespie 
32*c87b03e5Sespie /* This stuff is partly based on the 28 August 1994 public release of the
33*c87b03e5Sespie Info-ZIP group's portable UnZip zipfile-extraction program (and related
34*c87b03e5Sespie utilities). */
35*c87b03e5Sespie 
36*c87b03e5Sespie /*************/
37*c87b03e5Sespie /*  Defines  */
38*c87b03e5Sespie /*************/
39*c87b03e5Sespie 
40*c87b03e5Sespie #define UNZIP
41*c87b03e5Sespie #define UNZIP_VERSION     20   /* compatible with PKUNZIP 2.0 */
42*c87b03e5Sespie #define VMS_UNZIP_VERSION 42   /* if OS-needed-to-extract is VMS:  can do */
43*c87b03e5Sespie 
44*c87b03e5Sespie 
45*c87b03e5Sespie #define ZSUFX             ".zip"
46*c87b03e5Sespie #define CENTRAL_HDR_SIG   "\113\001\002"   /* the infamous "PK" signature */
47*c87b03e5Sespie #define LOCAL_HDR_SIG     "\113\003\004"   /*  bytes, sans "P" (so unzip */
48*c87b03e5Sespie #define END_CENTRAL_SIG   "\113\005\006"   /*  executable not mistaken for */
49*c87b03e5Sespie #define EXTD_LOCAL_SIG    "\113\007\010"   /*  zipfile itself) */
50*c87b03e5Sespie 
51*c87b03e5Sespie #define STORED            0    /* compression methods */
52*c87b03e5Sespie #define SHRUNK            1
53*c87b03e5Sespie #define REDUCED1          2
54*c87b03e5Sespie #define REDUCED2          3
55*c87b03e5Sespie #define REDUCED3          4
56*c87b03e5Sespie #define REDUCED4          5
57*c87b03e5Sespie #define IMPLODED          6
58*c87b03e5Sespie #define TOKENIZED         7
59*c87b03e5Sespie #define DEFLATED          8
60*c87b03e5Sespie #define NUM_METHODS       9    /* index of last method + 1 */
61*c87b03e5Sespie /* don't forget to update list_files() appropriately if NUM_METHODS changes */
62*c87b03e5Sespie 
63*c87b03e5Sespie #define PK_OK             0    /* no error */
64*c87b03e5Sespie #define PK_COOL           0    /* no error */
65*c87b03e5Sespie #define PK_GNARLY         0    /* no error */
66*c87b03e5Sespie #define PK_WARN           1    /* warning error */
67*c87b03e5Sespie #define PK_ERR            2    /* error in zipfile */
68*c87b03e5Sespie #define PK_BADERR         3    /* severe error in zipfile */
69*c87b03e5Sespie #define PK_MEM            4    /* insufficient memory */
70*c87b03e5Sespie #define PK_MEM2           5    /* insufficient memory */
71*c87b03e5Sespie #define PK_MEM3           6    /* insufficient memory */
72*c87b03e5Sespie #define PK_MEM4           7    /* insufficient memory */
73*c87b03e5Sespie #define PK_MEM5           8    /* insufficient memory */
74*c87b03e5Sespie #define PK_NOZIP          9    /* zipfile not found */
75*c87b03e5Sespie #define PK_PARAM          10   /* bad or illegal parameters specified */
76*c87b03e5Sespie #define PK_FIND           11   /* no files found */
77*c87b03e5Sespie #define PK_DISK           50   /* disk full */
78*c87b03e5Sespie #define PK_EOF            51   /* unexpected EOF */
79*c87b03e5Sespie 
80*c87b03e5Sespie /*---------------------------------------------------------------------------
81*c87b03e5Sespie     True sizes of the various headers, as defined by PKWARE--so it is not
82*c87b03e5Sespie     likely that these will ever change.  But if they do, make sure both these
83*c87b03e5Sespie     defines AND the typedefs below get updated accordingly.
84*c87b03e5Sespie   ---------------------------------------------------------------------------*/
85*c87b03e5Sespie #define LREC_SIZE     26    /* lengths of local file headers, central */
86*c87b03e5Sespie #define CREC_SIZE     42    /*  directory headers, and the end-of-    */
87*c87b03e5Sespie #define ECREC_SIZE    18    /*  central-dir record, respectively      */
88*c87b03e5Sespie 
89*c87b03e5Sespie 
90*c87b03e5Sespie #ifndef SEEK_SET
91*c87b03e5Sespie #  define SEEK_SET  0
92*c87b03e5Sespie #  define SEEK_CUR  1
93*c87b03e5Sespie #  define SEEK_END  2
94*c87b03e5Sespie #endif
95*c87b03e5Sespie 
96*c87b03e5Sespie /**************/
97*c87b03e5Sespie /*  Typedefs  */
98*c87b03e5Sespie /**************/
99*c87b03e5Sespie 
100*c87b03e5Sespie typedef char              boolean;
101*c87b03e5Sespie typedef unsigned char     uch;  /* code assumes unsigned bytes; these type-  */
102*c87b03e5Sespie typedef unsigned short    ush;  /*  defs replace byte/UWORD/ULONG (which are */
103*c87b03e5Sespie typedef unsigned long     ulg;  /*  predefined on some systems) & match zip  */
104*c87b03e5Sespie 
105*c87b03e5Sespie /*---------------------------------------------------------------------------
106*c87b03e5Sespie     Zipfile layout declarations.  If these headers ever change, make sure the
107*c87b03e5Sespie     xxREC_SIZE defines (above) change with them!
108*c87b03e5Sespie   ---------------------------------------------------------------------------*/
109*c87b03e5Sespie 
110*c87b03e5Sespie    typedef uch   local_byte_hdr[ LREC_SIZE ];
111*c87b03e5Sespie #      define L_VERSION_NEEDED_TO_EXTRACT_0     0
112*c87b03e5Sespie #      define L_VERSION_NEEDED_TO_EXTRACT_1     1
113*c87b03e5Sespie #      define L_GENERAL_PURPOSE_BIT_FLAG        2
114*c87b03e5Sespie #      define L_COMPRESSION_METHOD              4
115*c87b03e5Sespie #      define L_LAST_MOD_FILE_TIME              6
116*c87b03e5Sespie #      define L_LAST_MOD_FILE_DATE              8
117*c87b03e5Sespie #      define L_CRC32                           10
118*c87b03e5Sespie #      define L_COMPRESSED_SIZE                 14
119*c87b03e5Sespie #      define L_UNCOMPRESSED_SIZE               18
120*c87b03e5Sespie #      define L_FILENAME_LENGTH                 22
121*c87b03e5Sespie #      define L_EXTRA_FIELD_LENGTH              24
122*c87b03e5Sespie 
123*c87b03e5Sespie   typedef uch   cdir_byte_hdr[ CREC_SIZE ];
124*c87b03e5Sespie #      define C_VERSION_MADE_BY_0               0
125*c87b03e5Sespie #      define C_VERSION_MADE_BY_1               1
126*c87b03e5Sespie #      define C_VERSION_NEEDED_TO_EXTRACT_0     2
127*c87b03e5Sespie #      define C_VERSION_NEEDED_TO_EXTRACT_1     3
128*c87b03e5Sespie #      define C_GENERAL_PURPOSE_BIT_FLAG        4
129*c87b03e5Sespie #      define C_COMPRESSION_METHOD              6
130*c87b03e5Sespie #      define C_LAST_MOD_FILE_TIME              8
131*c87b03e5Sespie #      define C_LAST_MOD_FILE_DATE              10
132*c87b03e5Sespie #      define C_CRC32                           12
133*c87b03e5Sespie #      define C_COMPRESSED_SIZE                 16
134*c87b03e5Sespie #      define C_UNCOMPRESSED_SIZE               20
135*c87b03e5Sespie #      define C_FILENAME_LENGTH                 24
136*c87b03e5Sespie #      define C_EXTRA_FIELD_LENGTH              26
137*c87b03e5Sespie #      define C_FILE_COMMENT_LENGTH             28
138*c87b03e5Sespie #      define C_DISK_NUMBER_START               30
139*c87b03e5Sespie #      define C_INTERNAL_FILE_ATTRIBUTES        32
140*c87b03e5Sespie #      define C_EXTERNAL_FILE_ATTRIBUTES        34
141*c87b03e5Sespie #      define C_RELATIVE_OFFSET_LOCAL_HEADER    38
142*c87b03e5Sespie 
143*c87b03e5Sespie    typedef uch   ec_byte_rec[ ECREC_SIZE+4 ];
144*c87b03e5Sespie /*     define SIGNATURE                         0   space-holder only */
145*c87b03e5Sespie #      define NUMBER_THIS_DISK                  4
146*c87b03e5Sespie #      define NUM_DISK_WITH_START_CENTRAL_DIR   6
147*c87b03e5Sespie #      define NUM_ENTRIES_CENTRL_DIR_THS_DISK   8
148*c87b03e5Sespie #      define TOTAL_ENTRIES_CENTRAL_DIR         10
149*c87b03e5Sespie #      define SIZE_CENTRAL_DIRECTORY            12
150*c87b03e5Sespie #      define OFFSET_START_CENTRAL_DIRECTORY    16
151*c87b03e5Sespie #      define ZIPFILE_COMMENT_LENGTH            20
152*c87b03e5Sespie 
153*c87b03e5Sespie 
154*c87b03e5Sespie    typedef struct local_file_header {                 /* LOCAL */
155*c87b03e5Sespie        uch version_needed_to_extract[2];
156*c87b03e5Sespie        ush general_purpose_bit_flag;
157*c87b03e5Sespie        ush compression_method;
158*c87b03e5Sespie        ush last_mod_file_time;
159*c87b03e5Sespie        ush last_mod_file_date;
160*c87b03e5Sespie        ulg crc32;
161*c87b03e5Sespie        ulg csize;
162*c87b03e5Sespie        ulg ucsize;
163*c87b03e5Sespie        ush filename_length;
164*c87b03e5Sespie        ush extra_field_length;
165*c87b03e5Sespie    } local_file_hdr;
166*c87b03e5Sespie 
167*c87b03e5Sespie    typedef struct central_directory_file_header {     /* CENTRAL */
168*c87b03e5Sespie        uch version_made_by[2];
169*c87b03e5Sespie        uch version_needed_to_extract[2];
170*c87b03e5Sespie        ush general_purpose_bit_flag;
171*c87b03e5Sespie        ush compression_method;
172*c87b03e5Sespie        ush last_mod_file_time;
173*c87b03e5Sespie        ush last_mod_file_date;
174*c87b03e5Sespie        ulg crc32;
175*c87b03e5Sespie        ulg csize;
176*c87b03e5Sespie        ulg ucsize;
177*c87b03e5Sespie        ush filename_length;
178*c87b03e5Sespie        ush extra_field_length;
179*c87b03e5Sespie        ush file_comment_length;
180*c87b03e5Sespie        ush disk_number_start;
181*c87b03e5Sespie        ush internal_file_attributes;
182*c87b03e5Sespie        ulg external_file_attributes;
183*c87b03e5Sespie        ulg relative_offset_local_header;
184*c87b03e5Sespie    } cdir_file_hdr;
185*c87b03e5Sespie 
186*c87b03e5Sespie    typedef struct end_central_dir_record {            /* END CENTRAL */
187*c87b03e5Sespie        ush number_this_disk;
188*c87b03e5Sespie        ush num_disk_with_start_central_dir;
189*c87b03e5Sespie        ush num_entries_centrl_dir_ths_disk;
190*c87b03e5Sespie        ush total_entries_central_dir;
191*c87b03e5Sespie        ulg size_central_directory;
192*c87b03e5Sespie        ulg offset_start_central_directory;
193*c87b03e5Sespie        ush zipfile_comment_length;
194*c87b03e5Sespie    } ecdir_rec;
195*c87b03e5Sespie 
196*c87b03e5Sespie 
197*c87b03e5Sespie /************/
198*c87b03e5Sespie /*  Macros  */
199*c87b03e5Sespie /************/
200*c87b03e5Sespie 
201*c87b03e5Sespie #ifndef MAX
202*c87b03e5Sespie #  define MAX(a,b)   ((a) > (b) ? (a) : (b))
203*c87b03e5Sespie #endif
204*c87b03e5Sespie #ifndef MIN
205*c87b03e5Sespie #  define MIN(a,b)   ((a) < (b) ? (a) : (b))
206*c87b03e5Sespie #endif
207*c87b03e5Sespie 
208*c87b03e5Sespie 
209*c87b03e5Sespie /***********************/
210*c87b03e5Sespie /* Prototypes          */
211*c87b03e5Sespie /***********************/
212*c87b03e5Sespie 
213*c87b03e5Sespie static ush makeword PARAMS ((const uch *));
214*c87b03e5Sespie static ulg makelong PARAMS ((const uch *));
215*c87b03e5Sespie static long find_zip_file_start PARAMS ((int fd, long offset));
216*c87b03e5Sespie 
217*c87b03e5Sespie /***********************/
218*c87b03e5Sespie /* Function makeword() */
219*c87b03e5Sespie /***********************/
220*c87b03e5Sespie 
makeword(b)221*c87b03e5Sespie static ush makeword(b)
222*c87b03e5Sespie     const uch *b;
223*c87b03e5Sespie {
224*c87b03e5Sespie     /*
225*c87b03e5Sespie      * Convert Intel style 'short' integer to non-Intel non-16-bit
226*c87b03e5Sespie      * host format.  This routine also takes care of byte-ordering.
227*c87b03e5Sespie      */
228*c87b03e5Sespie     return (ush)((b[1] << 8) | b[0]);
229*c87b03e5Sespie }
230*c87b03e5Sespie 
231*c87b03e5Sespie 
232*c87b03e5Sespie /***********************/
233*c87b03e5Sespie /* Function makelong() */
234*c87b03e5Sespie /***********************/
235*c87b03e5Sespie 
makelong(sig)236*c87b03e5Sespie static ulg makelong(sig)
237*c87b03e5Sespie     const uch *sig;
238*c87b03e5Sespie {
239*c87b03e5Sespie     /*
240*c87b03e5Sespie      * Convert intel style 'long' variable to non-Intel non-16-bit
241*c87b03e5Sespie      * host format.  This routine also takes care of byte-ordering.
242*c87b03e5Sespie      */
243*c87b03e5Sespie     return (((ulg)sig[3]) << 24)
244*c87b03e5Sespie         + (((ulg)sig[2]) << 16)
245*c87b03e5Sespie         + (((ulg)sig[1]) << 8)
246*c87b03e5Sespie         + ((ulg)sig[0]);
247*c87b03e5Sespie }
248*c87b03e5Sespie 
249*c87b03e5Sespie /* Examine file's header in zip file and return the offset of the
250*c87b03e5Sespie    start of the actual data.  Return -1 on error.  OFFSET is the
251*c87b03e5Sespie    offset from the beginning of the zip file of the file's header.  */
252*c87b03e5Sespie static long
find_zip_file_start(fd,offset)253*c87b03e5Sespie find_zip_file_start (fd, offset)
254*c87b03e5Sespie      int fd;
255*c87b03e5Sespie      long offset;
256*c87b03e5Sespie {
257*c87b03e5Sespie   int filename_length, extra_field_length;
258*c87b03e5Sespie   unsigned char buffer[LREC_SIZE + 4];
259*c87b03e5Sespie 
260*c87b03e5Sespie   if (lseek (fd, offset, SEEK_SET) < 0)
261*c87b03e5Sespie     return -1;
262*c87b03e5Sespie 
263*c87b03e5Sespie   if (read (fd, buffer, LREC_SIZE + 4) != LREC_SIZE + 4)
264*c87b03e5Sespie     return -1;
265*c87b03e5Sespie 
266*c87b03e5Sespie   if (buffer[0] != 'P' || strncmp (&buffer[1], LOCAL_HDR_SIG, 3))
267*c87b03e5Sespie     return -1;
268*c87b03e5Sespie 
269*c87b03e5Sespie   filename_length = makeword (&buffer[4 + L_FILENAME_LENGTH]);
270*c87b03e5Sespie   extra_field_length = makeword (&buffer[4 + L_EXTRA_FIELD_LENGTH]);
271*c87b03e5Sespie 
272*c87b03e5Sespie   return offset + (4 + LREC_SIZE) + filename_length + extra_field_length;
273*c87b03e5Sespie }
274*c87b03e5Sespie 
275*c87b03e5Sespie int
read_zip_archive(zipf)276*c87b03e5Sespie read_zip_archive (zipf)
277*c87b03e5Sespie      register ZipFile *zipf;
278*c87b03e5Sespie {
279*c87b03e5Sespie   int i;
280*c87b03e5Sespie   int dir_last_pad;
281*c87b03e5Sespie   char *dir_ptr;
282*c87b03e5Sespie   char buffer[100];
283*c87b03e5Sespie 
284*c87b03e5Sespie   zipf->size = lseek (zipf->fd, 0L, SEEK_END);
285*c87b03e5Sespie 
286*c87b03e5Sespie   if (zipf->size < (ECREC_SIZE+4) || lseek (zipf->fd, (long)(-(ECREC_SIZE+4)), SEEK_CUR) <= 0)
287*c87b03e5Sespie     return -1;
288*c87b03e5Sespie   if (read (zipf->fd, buffer, ECREC_SIZE+4) != ECREC_SIZE+4)
289*c87b03e5Sespie     return -2;
290*c87b03e5Sespie   zipf->count = makeword(&buffer[TOTAL_ENTRIES_CENTRAL_DIR]);
291*c87b03e5Sespie   zipf->dir_size = makelong(&buffer[SIZE_CENTRAL_DIRECTORY]);
292*c87b03e5Sespie #define ALLOC xmalloc
293*c87b03e5Sespie   /* Allocate 1 more to allow appending '\0' to last filename. */
294*c87b03e5Sespie   zipf->central_directory = ALLOC (zipf->dir_size+1);
295*c87b03e5Sespie   if (lseek (zipf->fd, -(zipf->dir_size+ECREC_SIZE+4), SEEK_CUR) < 0)
296*c87b03e5Sespie     return -2;
297*c87b03e5Sespie   if (read (zipf->fd, zipf->central_directory, zipf->dir_size) < 0)
298*c87b03e5Sespie     return -2;
299*c87b03e5Sespie 
300*c87b03e5Sespie #ifdef TEST
301*c87b03e5Sespie   printf ("number_this_disk = %d\n", makeword(&buffer[NUMBER_THIS_DISK]));
302*c87b03e5Sespie   printf ("num_disk_with_start_central_dir = %d\n", makeword(&buffer[NUM_DISK_WITH_START_CENTRAL_DIR]));
303*c87b03e5Sespie 
304*c87b03e5Sespie   printf ("num_entries_centrl_dir_ths_disk = %d\n",
305*c87b03e5Sespie         makeword(&buffer[NUM_ENTRIES_CENTRL_DIR_THS_DISK]));
306*c87b03e5Sespie   printf ("total_entries_central_dir = %d\n",
307*c87b03e5Sespie         makeword(&buffer[TOTAL_ENTRIES_CENTRAL_DIR]));
308*c87b03e5Sespie   printf ("size_central_directory = %d\n",
309*c87b03e5Sespie         makelong(&buffer[SIZE_CENTRAL_DIRECTORY]));
310*c87b03e5Sespie   printf ("offset_start_central_directory = %d\n",
311*c87b03e5Sespie         makelong(&buffer[OFFSET_START_CENTRAL_DIRECTORY]));
312*c87b03e5Sespie   printf ("zipfile_comment_length = %d\n",
313*c87b03e5Sespie         makeword(&buffer[ZIPFILE_COMMENT_LENGTH]));
314*c87b03e5Sespie #endif
315*c87b03e5Sespie 
316*c87b03e5Sespie   dir_last_pad = 0;
317*c87b03e5Sespie   dir_ptr = zipf->central_directory;
318*c87b03e5Sespie   for (i = 0; i < zipf->count; i++)
319*c87b03e5Sespie     {
320*c87b03e5Sespie       ZipDirectory *zipd = (ZipDirectory*)(dir_ptr + dir_last_pad);
321*c87b03e5Sespie       int compression_method = (int) dir_ptr[4+C_COMPRESSION_METHOD];
322*c87b03e5Sespie       long size = makelong (&dir_ptr[4+C_COMPRESSED_SIZE]);
323*c87b03e5Sespie       long uncompressed_size = makelong (&dir_ptr[4+C_UNCOMPRESSED_SIZE]);
324*c87b03e5Sespie       long filename_length = makeword (&dir_ptr[4+C_FILENAME_LENGTH]);
325*c87b03e5Sespie       long extra_field_length = makeword (&dir_ptr[4+C_EXTRA_FIELD_LENGTH]);
326*c87b03e5Sespie       long file_offset = makelong (&dir_ptr[4+C_RELATIVE_OFFSET_LOCAL_HEADER]);
327*c87b03e5Sespie       int unpadded_direntry_length;
328*c87b03e5Sespie       if ((dir_ptr-zipf->central_directory)+filename_length+CREC_SIZE+4>zipf->dir_size)
329*c87b03e5Sespie 	return -1;
330*c87b03e5Sespie 
331*c87b03e5Sespie       zipd->filename_length = filename_length;
332*c87b03e5Sespie       zipd->compression_method = compression_method;
333*c87b03e5Sespie       zipd->size = size;
334*c87b03e5Sespie       zipd->uncompressed_size = uncompressed_size;
335*c87b03e5Sespie       zipd->zipf = zipf;
336*c87b03e5Sespie #ifdef __GNUC__
337*c87b03e5Sespie #define DIR_ALIGN __alignof__(ZipDirectory)
338*c87b03e5Sespie #else
339*c87b03e5Sespie #define DIR_ALIGN sizeof(long)
340*c87b03e5Sespie #endif
341*c87b03e5Sespie       zipd->filestart = find_zip_file_start (zipf->fd, file_offset);
342*c87b03e5Sespie       zipd->filename_offset = CREC_SIZE+4 - dir_last_pad;
343*c87b03e5Sespie       unpadded_direntry_length
344*c87b03e5Sespie 	  = zipd->filename_offset + zipd->filename_length + extra_field_length;
345*c87b03e5Sespie       zipd->direntry_size =
346*c87b03e5Sespie 	((unpadded_direntry_length + DIR_ALIGN) / DIR_ALIGN) * DIR_ALIGN;
347*c87b03e5Sespie       dir_last_pad = zipd->direntry_size - unpadded_direntry_length;
348*c87b03e5Sespie       dir_ptr = (char*)zipd + unpadded_direntry_length;
349*c87b03e5Sespie       *dir_ptr = '\0';
350*c87b03e5Sespie     }
351*c87b03e5Sespie   return 0;
352*c87b03e5Sespie }
353*c87b03e5Sespie 
354*c87b03e5Sespie #ifdef TEST
main()355*c87b03e5Sespie main ()
356*c87b03e5Sespie {
357*c87b03e5Sespie   ZipFile zipf[1];
358*c87b03e5Sespie   ZipDirectory *zipd;
359*c87b03e5Sespie   int i;
360*c87b03e5Sespie 
361*c87b03e5Sespie   zipf->fd = 0;
362*c87b03e5Sespie 
363*c87b03e5Sespie   i = read_zip_archive (zipf);
364*c87b03e5Sespie   if (i)
365*c87b03e5Sespie     {
366*c87b03e5Sespie       fprintf (stderr, "Bad zip file.\n");
367*c87b03e5Sespie       exit (i);
368*c87b03e5Sespie     }
369*c87b03e5Sespie 
370*c87b03e5Sespie   zipd = (ZipDirectory*) zipf->central_directory;
371*c87b03e5Sespie   for (i = 0; i < zipf->count; i++, zipd = ZIPDIR_NEXT (zipd))
372*c87b03e5Sespie     {
373*c87b03e5Sespie       printf ("%d: size:%d, name(#%d)%s, offset:%d\n",
374*c87b03e5Sespie 	      i, zipd->size, zipd->filename_length,
375*c87b03e5Sespie 	      ZIPDIR_FILENAME (zipd),
376*c87b03e5Sespie 	      zipd->filestart);
377*c87b03e5Sespie     }
378*c87b03e5Sespie }
379*c87b03e5Sespie #endif
380