blob: 046027cc69e5a0a48e2e82bfd69b45d0ba2bb145 [file] [log] [blame]
Glenn L McGrath87ac7022002-01-02 13:52:26 +00001/* vi: set sw=4 ts=4: */
2/*
3 * Mini unzip implementation for busybox
4 *
Paul Fox0840b762005-07-20 20:26:49 +00005 * Copyright (C) 2004 by Ed Clark
6 *
7 * Loosely based on original busybox unzip applet by Laurence Anderson.
8 * All options and features should work in this version.
Glenn L McGrath87ac7022002-01-02 13:52:26 +00009 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +020010 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Glenn L McGrath87ac7022002-01-02 13:52:26 +000011 */
12
Glenn L McGrathf34b0e92004-06-06 10:22:43 +000013/* For reference see
Paul Fox0840b762005-07-20 20:26:49 +000014 * http://www.pkware.com/company/standards/appnote/
Glenn L McGrathf34b0e92004-06-06 10:22:43 +000015 * http://www.info-zip.org/pub/infozip/doc/appnote-iz-latest.zip
16 */
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000017
Paul Fox0840b762005-07-20 20:26:49 +000018/* TODO
Paul Fox0840b762005-07-20 20:26:49 +000019 * Zip64 + other methods
Paul Fox0840b762005-07-20 20:26:49 +000020 */
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000021
Pere Orga1f4447b2011-03-27 22:40:30 +020022//usage:#define unzip_trivial_usage
Denys Vlasenkoe3e0d2b2012-06-19 12:46:59 +020023//usage: "[-lnopq] FILE[.zip] [FILE]... [-x FILE...] [-d DIR]"
Pere Orga1f4447b2011-03-27 22:40:30 +020024//usage:#define unzip_full_usage "\n\n"
Denys Vlasenkoe3e0d2b2012-06-19 12:46:59 +020025//usage: "Extract FILEs from ZIP archive\n"
26//usage: "\n -l List contents (with -q for short form)"
Denys Vlasenkoc5b01012012-06-15 16:43:26 +020027//usage: "\n -n Never overwrite files (default: ask)"
Pere Orga1f4447b2011-03-27 22:40:30 +020028//usage: "\n -o Overwrite"
Denys Vlasenkoe3e0d2b2012-06-19 12:46:59 +020029//usage: "\n -p Print to stdout"
Pere Orga1f4447b2011-03-27 22:40:30 +020030//usage: "\n -q Quiet"
Denys Vlasenkoe3e0d2b2012-06-19 12:46:59 +020031//usage: "\n -x FILE Exclude FILEs"
32//usage: "\n -d DIR Extract into DIR"
Pere Orga1f4447b2011-03-27 22:40:30 +020033
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000034#include "libbb.h"
Denys Vlasenkod184a722011-09-22 12:45:14 +020035#include "bb_archive.h"
Glenn L McGrath87ac7022002-01-02 13:52:26 +000036
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +000037enum {
38#if BB_BIG_ENDIAN
39 ZIP_FILEHEADER_MAGIC = 0x504b0304,
Denys Vlasenko4e8ff732010-05-24 04:33:02 +020040 ZIP_CDF_MAGIC = 0x504b0102, /* central directory's file header */
41 ZIP_CDE_MAGIC = 0x504b0506, /* "end of central directory" record */
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +000042 ZIP_DD_MAGIC = 0x504b0708,
43#else
44 ZIP_FILEHEADER_MAGIC = 0x04034b50,
Denys Vlasenko4e8ff732010-05-24 04:33:02 +020045 ZIP_CDF_MAGIC = 0x02014b50,
Denis Vlasenko006e8622008-09-21 01:01:46 +000046 ZIP_CDE_MAGIC = 0x06054b50,
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +000047 ZIP_DD_MAGIC = 0x08074b50,
48#endif
49};
Glenn L McGrath7ca04f32002-09-25 02:47:48 +000050
Paul Foxcb981632007-11-05 23:09:03 +000051#define ZIP_HEADER_LEN 26
52
Paul Fox0840b762005-07-20 20:26:49 +000053typedef union {
Paul Foxcb981632007-11-05 23:09:03 +000054 uint8_t raw[ZIP_HEADER_LEN];
Paul Fox0840b762005-07-20 20:26:49 +000055 struct {
Denis Vlasenko006e8622008-09-21 01:01:46 +000056 uint16_t version; /* 0-1 */
Denys Vlasenkoe98884b2010-05-24 04:46:18 +020057 uint16_t zip_flags; /* 2-3 */
Denis Vlasenko006e8622008-09-21 01:01:46 +000058 uint16_t method; /* 4-5 */
59 uint16_t modtime; /* 6-7 */
60 uint16_t moddate; /* 8-9 */
61 uint32_t crc32 PACKED; /* 10-13 */
62 uint32_t cmpsize PACKED; /* 14-17 */
63 uint32_t ucmpsize PACKED; /* 18-21 */
64 uint16_t filename_len; /* 22-23 */
65 uint16_t extra_len; /* 24-25 */
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000066 } formatted PACKED;
67} zip_header_t; /* PACKED - gcc 4.2.1 doesn't like it (spews warning) */
Paul Fox0840b762005-07-20 20:26:49 +000068
Paul Foxcb981632007-11-05 23:09:03 +000069/* Check the offset of the last element, not the length. This leniency
70 * allows for poor packing, whereby the overall struct may be too long,
71 * even though the elements are all in the right place.
72 */
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +000073struct BUG_zip_header_must_be_26_bytes {
Paul Foxcb981632007-11-05 23:09:03 +000074 char BUG_zip_header_must_be_26_bytes[
Denis Vlasenko006e8622008-09-21 01:01:46 +000075 offsetof(zip_header_t, formatted.extra_len) + 2
76 == ZIP_HEADER_LEN ? 1 : -1];
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +000077};
78
Denis Vlasenko006e8622008-09-21 01:01:46 +000079#define FIX_ENDIANNESS_ZIP(zip_header) do { \
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +000080 (zip_header).formatted.version = SWAP_LE16((zip_header).formatted.version ); \
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +000081 (zip_header).formatted.method = SWAP_LE16((zip_header).formatted.method ); \
82 (zip_header).formatted.modtime = SWAP_LE16((zip_header).formatted.modtime ); \
83 (zip_header).formatted.moddate = SWAP_LE16((zip_header).formatted.moddate ); \
84 (zip_header).formatted.crc32 = SWAP_LE32((zip_header).formatted.crc32 ); \
85 (zip_header).formatted.cmpsize = SWAP_LE32((zip_header).formatted.cmpsize ); \
86 (zip_header).formatted.ucmpsize = SWAP_LE32((zip_header).formatted.ucmpsize ); \
87 (zip_header).formatted.filename_len = SWAP_LE16((zip_header).formatted.filename_len); \
88 (zip_header).formatted.extra_len = SWAP_LE16((zip_header).formatted.extra_len ); \
89} while (0)
90
Denys Vlasenko4e8ff732010-05-24 04:33:02 +020091#define CDF_HEADER_LEN 42
Denis Vlasenko006e8622008-09-21 01:01:46 +000092
93typedef union {
Denys Vlasenko4e8ff732010-05-24 04:33:02 +020094 uint8_t raw[CDF_HEADER_LEN];
Denis Vlasenko006e8622008-09-21 01:01:46 +000095 struct {
96 /* uint32_t signature; 50 4b 01 02 */
97 uint16_t version_made_by; /* 0-1 */
98 uint16_t version_needed; /* 2-3 */
Denys Vlasenko4e8ff732010-05-24 04:33:02 +020099 uint16_t cdf_flags; /* 4-5 */
Denis Vlasenko006e8622008-09-21 01:01:46 +0000100 uint16_t method; /* 6-7 */
101 uint16_t mtime; /* 8-9 */
102 uint16_t mdate; /* 10-11 */
103 uint32_t crc32; /* 12-15 */
104 uint32_t cmpsize; /* 16-19 */
105 uint32_t ucmpsize; /* 20-23 */
106 uint16_t file_name_length; /* 24-25 */
107 uint16_t extra_field_length; /* 26-27 */
108 uint16_t file_comment_length; /* 28-29 */
109 uint16_t disk_number_start; /* 30-31 */
110 uint16_t internal_file_attributes; /* 32-33 */
111 uint32_t external_file_attributes PACKED; /* 34-37 */
112 uint32_t relative_offset_of_local_header PACKED; /* 38-41 */
113 } formatted PACKED;
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200114} cdf_header_t;
Denis Vlasenko006e8622008-09-21 01:01:46 +0000115
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200116struct BUG_cdf_header_must_be_42_bytes {
117 char BUG_cdf_header_must_be_42_bytes[
118 offsetof(cdf_header_t, formatted.relative_offset_of_local_header) + 4
119 == CDF_HEADER_LEN ? 1 : -1];
Denis Vlasenko006e8622008-09-21 01:01:46 +0000120};
121
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200122#define FIX_ENDIANNESS_CDF(cdf_header) do { \
123 (cdf_header).formatted.crc32 = SWAP_LE32((cdf_header).formatted.crc32 ); \
124 (cdf_header).formatted.cmpsize = SWAP_LE32((cdf_header).formatted.cmpsize ); \
125 (cdf_header).formatted.ucmpsize = SWAP_LE32((cdf_header).formatted.ucmpsize ); \
126 (cdf_header).formatted.file_name_length = SWAP_LE16((cdf_header).formatted.file_name_length); \
127 (cdf_header).formatted.extra_field_length = SWAP_LE16((cdf_header).formatted.extra_field_length); \
128 (cdf_header).formatted.file_comment_length = SWAP_LE16((cdf_header).formatted.file_comment_length); \
129 IF_DESKTOP( \
130 (cdf_header).formatted.version_made_by = SWAP_LE16((cdf_header).formatted.version_made_by); \
131 (cdf_header).formatted.external_file_attributes = SWAP_LE32((cdf_header).formatted.external_file_attributes); \
132 ) \
Denis Vlasenko006e8622008-09-21 01:01:46 +0000133} while (0)
134
135#define CDE_HEADER_LEN 16
136
137typedef union {
138 uint8_t raw[CDE_HEADER_LEN];
139 struct {
140 /* uint32_t signature; 50 4b 05 06 */
141 uint16_t this_disk_no;
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200142 uint16_t disk_with_cdf_no;
143 uint16_t cdf_entries_on_this_disk;
144 uint16_t cdf_entries_total;
145 uint32_t cdf_size;
146 uint32_t cdf_offset;
Denis Vlasenko006e8622008-09-21 01:01:46 +0000147 /* uint16_t file_comment_length; */
148 /* .ZIP file comment (variable size) */
149 } formatted PACKED;
150} cde_header_t;
151
152struct BUG_cde_header_must_be_16_bytes {
153 char BUG_cde_header_must_be_16_bytes[
154 sizeof(cde_header_t) == CDE_HEADER_LEN ? 1 : -1];
155};
156
157#define FIX_ENDIANNESS_CDE(cde_header) do { \
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200158 (cde_header).formatted.cdf_offset = SWAP_LE32((cde_header).formatted.cdf_offset); \
Denis Vlasenko006e8622008-09-21 01:01:46 +0000159} while (0)
160
161enum { zip_fd = 3 };
162
163
164#if ENABLE_DESKTOP
Dan Fandrichb76f18d2010-06-17 21:39:44 -0700165
166#define PEEK_FROM_END 16384
167
Denis Vlasenko006e8622008-09-21 01:01:46 +0000168/* NB: does not preserve file position! */
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200169static uint32_t find_cdf_offset(void)
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000170{
Denis Vlasenko006e8622008-09-21 01:01:46 +0000171 cde_header_t cde_header;
172 unsigned char *p;
173 off_t end;
Dan Fandrichb76f18d2010-06-17 21:39:44 -0700174 unsigned char *buf = xzalloc(PEEK_FROM_END);
Denis Vlasenko006e8622008-09-21 01:01:46 +0000175
176 end = xlseek(zip_fd, 0, SEEK_END);
Dan Fandrichb76f18d2010-06-17 21:39:44 -0700177 end -= PEEK_FROM_END;
Denys Vlasenkofc2bb8f2010-05-24 13:07:55 +0200178 if (end < 0)
179 end = 0;
Denis Vlasenko006e8622008-09-21 01:01:46 +0000180 xlseek(zip_fd, end, SEEK_SET);
Dan Fandrichb76f18d2010-06-17 21:39:44 -0700181 full_read(zip_fd, buf, PEEK_FROM_END);
Denis Vlasenko006e8622008-09-21 01:01:46 +0000182
183 p = buf;
Dan Fandrichb76f18d2010-06-17 21:39:44 -0700184 while (p <= buf + PEEK_FROM_END - CDE_HEADER_LEN - 4) {
Denis Vlasenko006e8622008-09-21 01:01:46 +0000185 if (*p != 'P') {
186 p++;
187 continue;
188 }
189 if (*++p != 'K')
190 continue;
191 if (*++p != 5)
192 continue;
193 if (*++p != 6)
194 continue;
195 /* we found CDE! */
196 memcpy(cde_header.raw, p + 1, CDE_HEADER_LEN);
197 FIX_ENDIANNESS_CDE(cde_header);
Dan Fandrichb76f18d2010-06-17 21:39:44 -0700198 free(buf);
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200199 return cde_header.formatted.cdf_offset;
Denis Vlasenko006e8622008-09-21 01:01:46 +0000200 }
Dan Fandrichb76f18d2010-06-17 21:39:44 -0700201 //free(buf);
Denis Vlasenko006e8622008-09-21 01:01:46 +0000202 bb_error_msg_and_die("can't find file table");
203};
204
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200205static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr)
Denis Vlasenko006e8622008-09-21 01:01:46 +0000206{
207 off_t org;
208
209 org = xlseek(zip_fd, 0, SEEK_CUR);
210
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200211 if (!cdf_offset)
212 cdf_offset = find_cdf_offset();
Denis Vlasenko006e8622008-09-21 01:01:46 +0000213
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200214 xlseek(zip_fd, cdf_offset + 4, SEEK_SET);
215 xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN);
216 FIX_ENDIANNESS_CDF(*cdf_ptr);
217 cdf_offset += 4 + CDF_HEADER_LEN
218 + cdf_ptr->formatted.file_name_length
219 + cdf_ptr->formatted.extra_field_length
220 + cdf_ptr->formatted.file_comment_length;
Denis Vlasenko006e8622008-09-21 01:01:46 +0000221
222 xlseek(zip_fd, org, SEEK_SET);
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200223 return cdf_offset;
Denis Vlasenko006e8622008-09-21 01:01:46 +0000224};
225#endif
226
227static void unzip_skip(off_t skip)
228{
Stefani Seiboldf3b56b42009-07-25 02:02:22 +0200229 if (lseek(zip_fd, skip, SEEK_CUR) == (off_t)-1)
230 bb_copyfd_exact_size(zip_fd, -1, skip);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000231}
232
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000233static void unzip_create_leading_dirs(const char *fn)
Paul Fox0840b762005-07-20 20:26:49 +0000234{
235 /* Create all leading directories */
Rob Landleyd921b2e2006-08-03 15:41:12 +0000236 char *name = xstrdup(fn);
Paul Fox0840b762005-07-20 20:26:49 +0000237 if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) {
Denys Vlasenko831756b2011-09-09 17:30:55 +0200238 xfunc_die(); /* bb_make_directory is noisy */
Paul Fox0840b762005-07-20 20:26:49 +0000239 }
240 free(name);
241}
242
Denis Vlasenko006e8622008-09-21 01:01:46 +0000243static void unzip_extract(zip_header_t *zip_header, int dst_fd)
Paul Fox0840b762005-07-20 20:26:49 +0000244{
"Robert P. J. Day"eea56182006-07-20 19:02:24 +0000245 if (zip_header->formatted.method == 0) {
Paul Fox0840b762005-07-20 20:26:49 +0000246 /* Method 0 - stored (not compressed) */
Denis Vlasenko7039a662006-10-08 17:54:47 +0000247 off_t size = zip_header->formatted.ucmpsize;
Denis Vlasenko714701c2006-12-22 00:21:07 +0000248 if (size)
Denis Vlasenko006e8622008-09-21 01:01:46 +0000249 bb_copyfd_exact_size(zip_fd, dst_fd, size);
Paul Fox0840b762005-07-20 20:26:49 +0000250 } else {
251 /* Method 8 - inflate */
Denys Vlasenko8a6a2f92012-03-06 16:27:48 +0100252 transformer_aux_data_t aux;
253 init_transformer_aux_data(&aux);
254 aux.bytes_in = zip_header->formatted.cmpsize;
255 if (inflate_unzip(&aux, zip_fd, dst_fd) < 0)
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000256 bb_error_msg_and_die("inflate error");
Paul Fox0840b762005-07-20 20:26:49 +0000257 /* Validate decompression - crc */
Denys Vlasenko8a6a2f92012-03-06 16:27:48 +0100258 if (zip_header->formatted.crc32 != (aux.crc32 ^ 0xffffffffL)) {
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000259 bb_error_msg_and_die("crc error");
Paul Fox0840b762005-07-20 20:26:49 +0000260 }
261 /* Validate decompression - size */
Denys Vlasenko8a6a2f92012-03-06 16:27:48 +0100262 if (zip_header->formatted.ucmpsize != aux.bytes_out) {
Denis Vlasenkofcc56962007-10-19 21:03:09 +0000263 /* Don't die. Who knows, maybe len calculation
264 * was botched somewhere. After all, crc matched! */
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000265 bb_error_msg("bad length");
Paul Fox0840b762005-07-20 20:26:49 +0000266 }
267 }
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000268}
269
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000270int unzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Rob Landleydfba7412006-03-06 20:47:33 +0000271int unzip_main(int argc, char **argv)
Glenn L McGrath87ac7022002-01-02 13:52:26 +0000272{
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000273 enum { O_PROMPT, O_NEVER, O_ALWAYS };
274
Paul Fox0840b762005-07-20 20:26:49 +0000275 zip_header_t zip_header;
Denys Vlasenko386bc9f2009-09-06 16:52:50 +0200276 smallint quiet = 0;
277 IF_NOT_DESKTOP(const) smallint verbose = 0;
Paul Fox9382b382007-09-07 20:28:25 +0000278 smallint listing = 0;
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000279 smallint overwrite = O_PROMPT;
Denys Vlasenkoc5b01012012-06-15 16:43:26 +0200280 smallint x_opt_seen;
Denis Vlasenko006e8622008-09-21 01:01:46 +0000281#if ENABLE_DESKTOP
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200282 uint32_t cdf_offset;
Denis Vlasenko006e8622008-09-21 01:01:46 +0000283#endif
Denys Vlasenko386bc9f2009-09-06 16:52:50 +0200284 unsigned long total_usize;
285 unsigned long total_size;
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000286 unsigned total_entries;
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000287 int dst_fd = -1;
288 char *src_fn = NULL;
289 char *dst_fn = NULL;
Mike Frysinger69024552005-07-30 07:30:26 +0000290 llist_t *zaccept = NULL;
291 llist_t *zreject = NULL;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000292 char *base_dir = NULL;
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000293 int i, opt;
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000294 char key_buf[80];
Paul Fox0840b762005-07-20 20:26:49 +0000295 struct stat stat_buf;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000296
Denys Vlasenko386bc9f2009-09-06 16:52:50 +0200297/* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP:
298 *
299 * # /usr/bin/unzip -qq -v decompress_unlzma.i.zip
300 * 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i
301 * # /usr/bin/unzip -q -v decompress_unlzma.i.zip
302 * Length Method Size Ratio Date Time CRC-32 Name
303 * -------- ------ ------- ----- ---- ---- ------ ----
304 * 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i
305 * -------- ------- --- -------
306 * 204372 35278 83% 1 file
307 * # /usr/bin/unzip -v decompress_unlzma.i.zip
308 * Archive: decompress_unlzma.i.zip
309 * Length Method Size Ratio Date Time CRC-32 Name
310 * -------- ------ ------- ----- ---- ---- ------ ----
311 * 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i
312 * -------- ------- --- -------
313 * 204372 35278 83% 1 file
314 * # unzip -v decompress_unlzma.i.zip
315 * Archive: decompress_unlzma.i.zip
316 * Length Date Time Name
317 * -------- ---- ---- ----
318 * 204372 09-06-09 14:23 decompress_unlzma.i
319 * -------- -------
320 * 204372 1 files
321 * # /usr/bin/unzip -l -qq decompress_unlzma.i.zip
322 * 204372 09-06-09 14:23 decompress_unlzma.i
323 * # /usr/bin/unzip -l -q decompress_unlzma.i.zip
324 * Length Date Time Name
325 * -------- ---- ---- ----
326 * 204372 09-06-09 14:23 decompress_unlzma.i
327 * -------- -------
328 * 204372 1 file
329 * # /usr/bin/unzip -l decompress_unlzma.i.zip
330 * Archive: decompress_unlzma.i.zip
331 * Length Date Time Name
332 * -------- ---- ---- ----
333 * 204372 09-06-09 14:23 decompress_unlzma.i
334 * -------- -------
335 * 204372 1 file
336 */
337
Denys Vlasenkoc5b01012012-06-15 16:43:26 +0200338 x_opt_seen = 0;
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000339 /* '-' makes getopt return 1 for non-options */
Denys Vlasenko386bc9f2009-09-06 16:52:50 +0200340 while ((opt = getopt(argc, argv, "-d:lnopqxv")) != -1) {
Denys Vlasenkoc5b01012012-06-15 16:43:26 +0200341 switch (opt) {
342 case 'd': /* Extract to base directory */
343 base_dir = optarg;
344 break;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000345
Denys Vlasenkoc5b01012012-06-15 16:43:26 +0200346 case 'l': /* List */
347 listing = 1;
348 break;
Paul Fox0840b762005-07-20 20:26:49 +0000349
Denys Vlasenkoc5b01012012-06-15 16:43:26 +0200350 case 'n': /* Never overwrite existing files */
351 overwrite = O_NEVER;
352 break;
Paul Fox0840b762005-07-20 20:26:49 +0000353
Denys Vlasenkoc5b01012012-06-15 16:43:26 +0200354 case 'o': /* Always overwrite existing files */
355 overwrite = O_ALWAYS;
356 break;
Paul Fox0840b762005-07-20 20:26:49 +0000357
Denys Vlasenkoc5b01012012-06-15 16:43:26 +0200358 case 'p': /* Extract files to stdout and fall through to set verbosity */
359 dst_fd = STDOUT_FILENO;
Denys Vlasenko386bc9f2009-09-06 16:52:50 +0200360
Denys Vlasenkoc5b01012012-06-15 16:43:26 +0200361 case 'q': /* Be quiet */
362 quiet++;
363 break;
Paul Fox0840b762005-07-20 20:26:49 +0000364
Denys Vlasenkoc5b01012012-06-15 16:43:26 +0200365 case 'v': /* Verbose list */
366 IF_DESKTOP(verbose++;)
367 listing = 1;
368 break;
369
370 case 'x':
371 x_opt_seen = 1;
372 break;
373
374 case 1:
375 if (!src_fn) {
376 /* The zip file */
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000377 /* +5: space for ".zip" and NUL */
378 src_fn = xmalloc(strlen(optarg) + 5);
Denis Vlasenko666c40c2007-03-31 10:17:24 +0000379 strcpy(src_fn, optarg);
Denys Vlasenkoc5b01012012-06-15 16:43:26 +0200380 } else if (!x_opt_seen) {
381 /* Include files */
382 llist_add_to(&zaccept, optarg);
383 } else {
384 /* Exclude files */
385 llist_add_to(&zreject, optarg);
Paul Fox0840b762005-07-20 20:26:49 +0000386 }
387 break;
388
Paul Fox0840b762005-07-20 20:26:49 +0000389 default:
390 bb_show_usage();
Glenn L McGrath87ac7022002-01-02 13:52:26 +0000391 }
392 }
393
Denys Vlasenkoc5b01012012-06-15 16:43:26 +0200394#ifndef __GLIBC__
395 /*
396 * This code is needed for non-GNU getopt
397 * which doesn't understand "-" in option string.
398 * The -x option won't work properly in this case:
399 * "unzip a.zip q -x w e" will be interpreted as
400 * "unzip a.zip q w e -x" = "unzip a.zip q w e"
401 */
402 argv += optind;
403 if (argv[0]) {
404 /* +5: space for ".zip" and NUL */
405 src_fn = xmalloc(strlen(argv[0]) + 5);
406 strcpy(src_fn, argv[0]);
407 while (*++argv)
408 llist_add_to(&zaccept, *argv);
409 }
410#endif
411
412 if (!src_fn) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000413 bb_show_usage();
Glenn L McGrath87ac7022002-01-02 13:52:26 +0000414 }
415
Paul Fox0840b762005-07-20 20:26:49 +0000416 /* Open input file */
Denis Vlasenko9f739442006-12-16 23:49:13 +0000417 if (LONE_DASH(src_fn)) {
Denis Vlasenko006e8622008-09-21 01:01:46 +0000418 xdup2(STDIN_FILENO, zip_fd);
Paul Fox0840b762005-07-20 20:26:49 +0000419 /* Cannot use prompt mode since zip data is arriving on STDIN */
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000420 if (overwrite == O_PROMPT)
421 overwrite = O_NEVER;
Glenn L McGrath237ae422002-11-03 14:05:15 +0000422 } else {
Denys Vlasenkoc5b01012012-06-15 16:43:26 +0200423 static const char extn[][5] = { ".zip", ".ZIP" };
424 char *ext = src_fn + strlen(src_fn);
425 int src_fd;
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000426
Denys Vlasenkoc5b01012012-06-15 16:43:26 +0200427 i = 0;
428 for (;;) {
Paul Fox0840b762005-07-20 20:26:49 +0000429 src_fd = open(src_fn, O_RDONLY);
Denys Vlasenkoc5b01012012-06-15 16:43:26 +0200430 if (src_fd >= 0)
431 break;
432 if (++i > 2) {
433 *ext = '\0';
434 bb_error_msg_and_die("can't open %s[.zip]", src_fn);
435 }
436 strcpy(ext, extn[i - 1]);
Paul Fox0840b762005-07-20 20:26:49 +0000437 }
Denis Vlasenko006e8622008-09-21 01:01:46 +0000438 xmove_fd(src_fd, zip_fd);
Glenn L McGrath237ae422002-11-03 14:05:15 +0000439 }
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000440
Paul Fox0840b762005-07-20 20:26:49 +0000441 /* Change dir if necessary */
Bernhard Reutner-Fischerd9cf7ac2006-04-12 18:39:58 +0000442 if (base_dir)
Rob Landleyd921b2e2006-08-03 15:41:12 +0000443 xchdir(base_dir);
Glenn L McGrath87ac7022002-01-02 13:52:26 +0000444
Denys Vlasenko386bc9f2009-09-06 16:52:50 +0200445 if (quiet <= 1) { /* not -qq */
446 if (quiet == 0)
447 printf("Archive: %s\n", src_fn);
448 if (listing) {
449 puts(verbose ?
450 " Length Method Size Ratio Date Time CRC-32 Name\n"
451 "-------- ------ ------- ----- ---- ---- ------ ----"
452 :
453 " Length Date Time Name\n"
454 " -------- ---- ---- ----"
455 );
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000456 }
457 }
Glenn L McGrath87ac7022002-01-02 13:52:26 +0000458
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200459/* Example of an archive with one 0-byte long file named 'z'
460 * created by Zip 2.31 on Unix:
461 * 0000 [50 4b]03 04 0a 00 00 00 00 00 42 1a b8 3c 00 00 |PK........B..<..|
462 * sig........ vneed flags compr mtime mdate crc32>
463 * 0010 00 00 00 00 00 00 00 00 00 00 01 00 15 00 7a 55 |..............zU|
464 * >..... csize...... usize...... fnlen exlen fn ex>
465 * 0020 54 09 00 03 cc d3 f9 4b cc d3 f9 4b 55 78 04 00 |T......K...KUx..|
466 * >tra_field......................................
467 * 0030 00 00 00 00[50 4b]01 02 17 03 0a 00 00 00 00 00 |....PK..........|
468 * ........... sig........ vmade vneed flags compr
469 * 0040 42 1a b8 3c 00 00 00 00 00 00 00 00 00 00 00 00 |B..<............|
470 * mtime mdate crc32...... csize...... usize......
471 * 0050 01 00 0d 00 00 00 00 00 00 00 00 00 a4 81 00 00 |................|
472 * fnlen exlen clen. dnum. iattr eattr...... relofs> (eattr = rw-r--r--)
473 * 0060 00 00 7a 55 54 05 00 03 cc d3 f9 4b 55 78 00 00 |..zUT......KUx..|
474 * >..... fn extra_field...........................
475 * 0070 [50 4b]05 06 00 00 00 00 01 00 01 00 3c 00 00 00 |PK..........<...|
476 * 0080 34 00 00 00 00 00 |4.....|
477 */
Denys Vlasenko386bc9f2009-09-06 16:52:50 +0200478 total_usize = 0;
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000479 total_size = 0;
480 total_entries = 0;
Denis Vlasenko006e8622008-09-21 01:01:46 +0000481#if ENABLE_DESKTOP
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200482 cdf_offset = 0;
Denis Vlasenko006e8622008-09-21 01:01:46 +0000483#endif
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000484 while (1) {
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000485 uint32_t magic;
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200486 mode_t dir_mode = 0777;
487#if ENABLE_DESKTOP
488 mode_t file_mode = 0666;
489#endif
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000490
Paul Fox0840b762005-07-20 20:26:49 +0000491 /* Check magic number */
Denis Vlasenko006e8622008-09-21 01:01:46 +0000492 xread(zip_fd, &magic, 4);
Denis Vlasenko48a99712008-07-26 17:32:41 +0000493 /* Central directory? It's at the end, so exit */
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200494 if (magic == ZIP_CDF_MAGIC)
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000495 break;
Denis Vlasenko006e8622008-09-21 01:01:46 +0000496#if ENABLE_DESKTOP
497 /* Data descriptor? It was a streaming file, go on */
498 if (magic == ZIP_DD_MAGIC) {
499 /* skip over duplicate crc32, cmpsize and ucmpsize */
500 unzip_skip(3 * 4);
501 continue;
502 }
503#endif
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000504 if (magic != ZIP_FILEHEADER_MAGIC)
Denis Vlasenko48a99712008-07-26 17:32:41 +0000505 bb_error_msg_and_die("invalid zip magic %08X", (int)magic);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000506
507 /* Read the file header */
Denis Vlasenko006e8622008-09-21 01:01:46 +0000508 xread(zip_fd, zip_header.raw, ZIP_HEADER_LEN);
509 FIX_ENDIANNESS_ZIP(zip_header);
"Robert P. J. Day"eea56182006-07-20 19:02:24 +0000510 if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) {
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000511 bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000512 }
Denis Vlasenko006e8622008-09-21 01:01:46 +0000513#if !ENABLE_DESKTOP
Denys Vlasenkoe98884b2010-05-24 04:46:18 +0200514 if (zip_header.formatted.zip_flags & SWAP_LE16(0x0009)) {
Denis Vlasenko006e8622008-09-21 01:01:46 +0000515 bb_error_msg_and_die("zip flags 1 and 8 are not supported");
516 }
517#else
Denys Vlasenkoe98884b2010-05-24 04:46:18 +0200518 if (zip_header.formatted.zip_flags & SWAP_LE16(0x0001)) {
Denis Vlasenko48a99712008-07-26 17:32:41 +0000519 /* 0x0001 - encrypted */
Denis Vlasenko006e8622008-09-21 01:01:46 +0000520 bb_error_msg_and_die("zip flag 1 (encryption) is not supported");
521 }
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200522
523 {
524 cdf_header_t cdf_header;
525 cdf_offset = read_next_cdf(cdf_offset, &cdf_header);
Denys Vlasenkoe98884b2010-05-24 04:46:18 +0200526 if (zip_header.formatted.zip_flags & SWAP_LE16(0x0008)) {
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200527 /* 0x0008 - streaming. [u]cmpsize can be reliably gotten
528 * only from Central Directory. See unzip_doc.txt */
529 zip_header.formatted.crc32 = cdf_header.formatted.crc32;
530 zip_header.formatted.cmpsize = cdf_header.formatted.cmpsize;
531 zip_header.formatted.ucmpsize = cdf_header.formatted.ucmpsize;
532 }
533 if ((cdf_header.formatted.version_made_by >> 8) == 3) {
534 /* this archive is created on Unix */
535 dir_mode = file_mode = (cdf_header.formatted.external_file_attributes >> 16);
536 }
Denis Vlasenko48a99712008-07-26 17:32:41 +0000537 }
Denis Vlasenko006e8622008-09-21 01:01:46 +0000538#endif
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000539
540 /* Read filename */
Paul Fox0840b762005-07-20 20:26:49 +0000541 free(dst_fn);
"Robert P. J. Day"eea56182006-07-20 19:02:24 +0000542 dst_fn = xzalloc(zip_header.formatted.filename_len + 1);
Denis Vlasenko006e8622008-09-21 01:01:46 +0000543 xread(zip_fd, dst_fn, zip_header.formatted.filename_len);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000544
Paul Fox0840b762005-07-20 20:26:49 +0000545 /* Skip extra header bytes */
Denis Vlasenko006e8622008-09-21 01:01:46 +0000546 unzip_skip(zip_header.formatted.extra_len);
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000547
Paul Fox0840b762005-07-20 20:26:49 +0000548 /* Filter zip entries */
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000549 if (find_list_entry(zreject, dst_fn)
550 || (zaccept && !find_list_entry(zaccept, dst_fn))
551 ) { /* Skip entry */
Paul Fox0840b762005-07-20 20:26:49 +0000552 i = 'n';
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000553
Paul Fox0840b762005-07-20 20:26:49 +0000554 } else { /* Extract entry */
Paul Fox9382b382007-09-07 20:28:25 +0000555 if (listing) { /* List entry */
Denys Vlasenko386bc9f2009-09-06 16:52:50 +0200556 unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
557 if (!verbose) {
558 // " Length Date Time Name\n"
559 // " -------- ---- ---- ----"
560 printf( "%9u %02u-%02u-%02u %02u:%02u %s\n",
561 (unsigned)zip_header.formatted.ucmpsize,
562 (dostime & 0x01e00000) >> 21,
563 (dostime & 0x001f0000) >> 16,
564 (((dostime & 0xfe000000) >> 25) + 1980) % 100,
565 (dostime & 0x0000f800) >> 11,
566 (dostime & 0x000007e0) >> 5,
567 dst_fn);
568 total_usize += zip_header.formatted.ucmpsize;
Denis Vlasenkofeb7ae72007-10-01 12:05:12 +0000569 } else {
Denys Vlasenko386bc9f2009-09-06 16:52:50 +0200570 unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize;
571 percents = percents * 100;
572 if (zip_header.formatted.ucmpsize)
573 percents /= zip_header.formatted.ucmpsize;
574 // " Length Method Size Ratio Date Time CRC-32 Name\n"
575 // "-------- ------ ------- ----- ---- ---- ------ ----"
576 printf( "%8u Defl:N" "%9u%4u%% %02u-%02u-%02u %02u:%02u %08x %s\n",
577 (unsigned)zip_header.formatted.ucmpsize,
578 (unsigned)zip_header.formatted.cmpsize,
579 (unsigned)percents,
580 (dostime & 0x01e00000) >> 21,
581 (dostime & 0x001f0000) >> 16,
582 (((dostime & 0xfe000000) >> 25) + 1980) % 100,
583 (dostime & 0x0000f800) >> 11,
584 (dostime & 0x000007e0) >> 5,
585 zip_header.formatted.crc32,
586 dst_fn);
587 total_usize += zip_header.formatted.ucmpsize;
588 total_size += zip_header.formatted.cmpsize;
Denis Vlasenkofeb7ae72007-10-01 12:05:12 +0000589 }
590 i = 'n';
Paul Fox0840b762005-07-20 20:26:49 +0000591 } else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
592 i = -1;
Paul Fox0840b762005-07-20 20:26:49 +0000593 } else if (last_char_is(dst_fn, '/')) { /* Extract directory */
594 if (stat(dst_fn, &stat_buf) == -1) {
595 if (errno != ENOENT) {
Denis Vlasenko006e8622008-09-21 01:01:46 +0000596 bb_perror_msg_and_die("can't stat '%s'", dst_fn);
Paul Fox0840b762005-07-20 20:26:49 +0000597 }
Denys Vlasenko386bc9f2009-09-06 16:52:50 +0200598 if (!quiet) {
Paul Fox0840b762005-07-20 20:26:49 +0000599 printf(" creating: %s\n", dst_fn);
600 }
601 unzip_create_leading_dirs(dst_fn);
Natanael Copa02112d82012-05-22 17:11:46 +0200602 if (bb_make_directory(dst_fn, dir_mode, FILEUTILS_IGNORE_CHMOD_ERR)) {
Denys Vlasenko831756b2011-09-09 17:30:55 +0200603 xfunc_die();
Paul Fox0840b762005-07-20 20:26:49 +0000604 }
605 } else {
606 if (!S_ISDIR(stat_buf.st_mode)) {
607 bb_error_msg_and_die("'%s' exists but is not directory", dst_fn);
608 }
609 }
610 i = 'n';
611
612 } else { /* Extract file */
Denis Vlasenko48a99712008-07-26 17:32:41 +0000613 check_file:
Paul Fox0840b762005-07-20 20:26:49 +0000614 if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */
615 if (errno != ENOENT) {
Denis Vlasenko006e8622008-09-21 01:01:46 +0000616 bb_perror_msg_and_die("can't stat '%s'", dst_fn);
Paul Fox0840b762005-07-20 20:26:49 +0000617 }
618 i = 'y';
Paul Fox0840b762005-07-20 20:26:49 +0000619 } else { /* File already exists */
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000620 if (overwrite == O_NEVER) {
Paul Fox0840b762005-07-20 20:26:49 +0000621 i = 'n';
Paul Fox0840b762005-07-20 20:26:49 +0000622 } else if (S_ISREG(stat_buf.st_mode)) { /* File is regular file */
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000623 if (overwrite == O_ALWAYS) {
Paul Fox0840b762005-07-20 20:26:49 +0000624 i = 'y';
625 } else {
626 printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
Denys Vlasenko831756b2011-09-09 17:30:55 +0200627 fflush_all();
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000628 if (!fgets(key_buf, sizeof(key_buf), stdin)) {
Denis Vlasenko006e8622008-09-21 01:01:46 +0000629 bb_perror_msg_and_die("can't read input");
Paul Fox0840b762005-07-20 20:26:49 +0000630 }
631 i = key_buf[0];
632 }
Paul Fox0840b762005-07-20 20:26:49 +0000633 } else { /* File is not regular file */
Denis Vlasenkof5d8c902008-06-26 14:32:57 +0000634 bb_error_msg_and_die("'%s' exists but is not regular file", dst_fn);
Paul Fox0840b762005-07-20 20:26:49 +0000635 }
636 }
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000637 }
638 }
639
Paul Fox0840b762005-07-20 20:26:49 +0000640 switch (i) {
641 case 'A':
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000642 overwrite = O_ALWAYS;
Paul Fox0840b762005-07-20 20:26:49 +0000643 case 'y': /* Open file and fall into unzip */
644 unzip_create_leading_dirs(dst_fn);
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200645#if ENABLE_DESKTOP
646 dst_fd = xopen3(dst_fn, O_WRONLY | O_CREAT | O_TRUNC, file_mode);
647#else
Bernhard Reutner-Fischer64d7e932006-09-11 16:01:40 +0000648 dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
Denys Vlasenko4e8ff732010-05-24 04:33:02 +0200649#endif
Paul Fox0840b762005-07-20 20:26:49 +0000650 case -1: /* Unzip */
Denys Vlasenko386bc9f2009-09-06 16:52:50 +0200651 if (!quiet) {
Paul Fox0840b762005-07-20 20:26:49 +0000652 printf(" inflating: %s\n", dst_fn);
653 }
Denis Vlasenko006e8622008-09-21 01:01:46 +0000654 unzip_extract(&zip_header, dst_fd);
Paul Fox0840b762005-07-20 20:26:49 +0000655 if (dst_fd != STDOUT_FILENO) {
656 /* closing STDOUT is potentially bad for future business */
657 close(dst_fd);
658 }
659 break;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000660
Paul Fox0840b762005-07-20 20:26:49 +0000661 case 'N':
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000662 overwrite = O_NEVER;
Paul Fox0840b762005-07-20 20:26:49 +0000663 case 'n':
664 /* Skip entry data */
Denis Vlasenko006e8622008-09-21 01:01:46 +0000665 unzip_skip(zip_header.formatted.cmpsize);
Paul Fox0840b762005-07-20 20:26:49 +0000666 break;
667
668 case 'r':
669 /* Prompt for new name */
670 printf("new name: ");
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000671 if (!fgets(key_buf, sizeof(key_buf), stdin)) {
Denis Vlasenko006e8622008-09-21 01:01:46 +0000672 bb_perror_msg_and_die("can't read input");
Paul Fox0840b762005-07-20 20:26:49 +0000673 }
674 free(dst_fn);
Rob Landleyd921b2e2006-08-03 15:41:12 +0000675 dst_fn = xstrdup(key_buf);
Paul Fox0840b762005-07-20 20:26:49 +0000676 chomp(dst_fn);
Denis Vlasenko48a99712008-07-26 17:32:41 +0000677 goto check_file;
Paul Fox0840b762005-07-20 20:26:49 +0000678
679 default:
Denys Vlasenko386bc9f2009-09-06 16:52:50 +0200680 printf("error: invalid response [%c]\n", (char)i);
Denis Vlasenko48a99712008-07-26 17:32:41 +0000681 goto check_file;
Paul Fox0840b762005-07-20 20:26:49 +0000682 }
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000683
Denis Vlasenko006e8622008-09-21 01:01:46 +0000684 total_entries++;
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000685 }
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000686
Denys Vlasenko386bc9f2009-09-06 16:52:50 +0200687 if (listing && quiet <= 1) {
688 if (!verbose) {
689 // " Length Date Time Name\n"
690 // " -------- ---- ---- ----"
691 printf( " -------- -------\n"
692 "%9lu" " %u files\n",
693 total_usize, total_entries);
694 } else {
695 unsigned long percents = total_usize - total_size;
696 percents = percents * 100;
697 if (total_usize)
698 percents /= total_usize;
699 // " Length Method Size Ratio Date Time CRC-32 Name\n"
700 // "-------- ------ ------- ----- ---- ---- ------ ----"
701 printf( "-------- ------- --- -------\n"
702 "%8lu" "%17lu%4u%% %u files\n",
703 total_usize, total_size, (unsigned)percents,
704 total_entries);
705 }
Glenn L McGrath7ca04f32002-09-25 02:47:48 +0000706 }
707
Denis Vlasenkobc7c5d02007-10-18 23:27:46 +0000708 return 0;
Glenn L McGrath87ac7022002-01-02 13:52:26 +0000709}