Annotation of /trunk/mkinitrd-magellan/klibc/usr/gzip/unzip.c
Parent Directory | Revision Log
Revision 815 -
(hide annotations)
(download)
Fri Apr 24 18:32:46 2009 UTC (15 years ago) by niro
File MIME type: text/plain
File size: 2116 byte(s)
Fri Apr 24 18:32:46 2009 UTC (15 years ago) by niro
File MIME type: text/plain
File size: 2116 byte(s)
-updated to klibc-1.5.15
1 | niro | 532 | /* unzip.c -- decompress files in gzip or pkzip format. |
2 | * Copyright (C) 1992-1993 Jean-loup Gailly | ||
3 | * This is free software; you can redistribute it and/or modify it under the | ||
4 | * terms of the GNU General Public License, see the file COPYING. | ||
5 | * | ||
6 | * The code in this file is derived from the file funzip.c written | ||
7 | * and put in the public domain by Mark Adler. | ||
8 | */ | ||
9 | |||
10 | /* | ||
11 | This version can extract files in gzip format. | ||
12 | Only the first entry is extracted, and it has to be | ||
13 | either deflated or stored. | ||
14 | */ | ||
15 | |||
16 | #ifdef RCSID | ||
17 | niro | 815 | static char rcsid[] = "$Id: unzip.c,v 1.1 2002/08/18 00:59:21 hpa Exp $"; |
18 | niro | 532 | #endif |
19 | |||
20 | #include "tailor.h" | ||
21 | #include "gzip.h" | ||
22 | |||
23 | /* =========================================================================== | ||
24 | * Unzip in to out. This routine works on gzip files only. | ||
25 | * | ||
26 | * IN assertions: the buffer inbuf contains already the beginning of | ||
27 | * the compressed data, from offsets inptr to insize-1 included. | ||
28 | * The magic header has already been checked. The output buffer is cleared. | ||
29 | */ | ||
30 | int unzip(in, out) | ||
31 | int in, out; /* input and output file descriptors */ | ||
32 | { | ||
33 | ulg orig_crc = 0; /* original crc */ | ||
34 | ulg orig_len = 0; /* original uncompressed length */ | ||
35 | int n; | ||
36 | uch buf[8]; /* extended local header */ | ||
37 | |||
38 | ifd = in; | ||
39 | ofd = out; | ||
40 | |||
41 | updcrc(NULL, 0); /* initialize crc */ | ||
42 | |||
43 | /* Decompress */ | ||
44 | if (method == DEFLATED) { | ||
45 | |||
46 | int res = inflate(); | ||
47 | |||
48 | if (res == 3) { | ||
49 | error("out of memory"); | ||
50 | } else if (res != 0) { | ||
51 | error("invalid compressed data--format violated"); | ||
52 | } | ||
53 | |||
54 | } else { | ||
55 | error("internal error, invalid method"); | ||
56 | } | ||
57 | |||
58 | /* Get the crc and original length */ | ||
59 | /* crc32 (see algorithm.doc) | ||
60 | * uncompressed input size modulo 2^32 | ||
61 | */ | ||
62 | for (n = 0; n < 8; n++) { | ||
63 | buf[n] = (uch)get_byte(); /* may cause an error if EOF */ | ||
64 | } | ||
65 | orig_crc = LG(buf); | ||
66 | orig_len = LG(buf+4); | ||
67 | |||
68 | /* Validate decompression */ | ||
69 | if (orig_crc != updcrc(outbuf, 0)) { | ||
70 | error("invalid compressed data--crc error"); | ||
71 | } | ||
72 | if (orig_len != (ulg)bytes_out) { | ||
73 | error("invalid compressed data--length error"); | ||
74 | } | ||
75 | |||
76 | return OK; | ||
77 | } |