diff options
Diffstat (limited to 'minigzip.c')
-rw-r--r-- | minigzip.c | 29 |
1 files changed, 16 insertions, 13 deletions
@@ -1,6 +1,7 @@ | |||
1 | /* minigzip.c -- simulate gzip using the zlib compression library | 1 | /* minigzip.c -- simulate gzip using the zlib compression library |
2 | * Copyright (C) 1995-2002 Jean-loup Gailly. | 2 | * Copyright (C) 1995-2002 Jean-loup Gailly. |
3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * Adapted for Z_RLE by Cosmin Truta, 2003. |
4 | * For conditions of distribution and use, see copyright notice in zlib.h | ||
4 | */ | 5 | */ |
5 | 6 | ||
6 | /* | 7 | /* |
@@ -147,7 +148,7 @@ int gz_compress_mmap(in, out) | |||
147 | if (buf_len <= 0) return Z_ERRNO; | 148 | if (buf_len <= 0) return Z_ERRNO; |
148 | 149 | ||
149 | /* Now do the actual mmap: */ | 150 | /* Now do the actual mmap: */ |
150 | buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0); | 151 | buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0); |
151 | if (buf == (caddr_t)(-1)) return Z_ERRNO; | 152 | if (buf == (caddr_t)(-1)) return Z_ERRNO; |
152 | 153 | ||
153 | /* Compress the whole file at once: */ | 154 | /* Compress the whole file at once: */ |
@@ -179,8 +180,8 @@ void gz_uncompress(in, out) | |||
179 | if (len == 0) break; | 180 | if (len == 0) break; |
180 | 181 | ||
181 | if ((int)fwrite(buf, 1, (unsigned)len, out) != len) { | 182 | if ((int)fwrite(buf, 1, (unsigned)len, out) != len) { |
182 | error("failed fwrite"); | 183 | error("failed fwrite"); |
183 | } | 184 | } |
184 | } | 185 | } |
185 | if (fclose(out)) error("failed fclose"); | 186 | if (fclose(out)) error("failed fclose"); |
186 | 187 | ||
@@ -260,10 +261,11 @@ void file_uncompress(file) | |||
260 | 261 | ||
261 | 262 | ||
262 | /* =========================================================================== | 263 | /* =========================================================================== |
263 | * Usage: minigzip [-d] [-f] [-h] [-1 to -9] [files...] | 264 | * Usage: minigzip [-d] [-f] [-h] [-r] [-1 to -9] [files...] |
264 | * -d : decompress | 265 | * -d : decompress |
265 | * -f : compress with Z_FILTERED | 266 | * -f : compress with Z_FILTERED |
266 | * -h : compress with Z_HUFFMAN_ONLY | 267 | * -h : compress with Z_HUFFMAN_ONLY |
268 | * -r : compress with Z_RLE | ||
267 | * -1 to -9 : compression level | 269 | * -1 to -9 : compression level |
268 | */ | 270 | */ |
269 | 271 | ||
@@ -282,16 +284,18 @@ int main(argc, argv) | |||
282 | 284 | ||
283 | while (argc > 0) { | 285 | while (argc > 0) { |
284 | if (strcmp(*argv, "-d") == 0) | 286 | if (strcmp(*argv, "-d") == 0) |
285 | uncompr = 1; | 287 | uncompr = 1; |
286 | else if (strcmp(*argv, "-f") == 0) | 288 | else if (strcmp(*argv, "-f") == 0) |
287 | outmode[3] = 'f'; | 289 | outmode[3] = 'f'; |
288 | else if (strcmp(*argv, "-h") == 0) | 290 | else if (strcmp(*argv, "-h") == 0) |
289 | outmode[3] = 'h'; | 291 | outmode[3] = 'h'; |
292 | else if (strcmp(*argv, "-r") == 0) | ||
293 | outmode[3] = 'R'; | ||
290 | else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' && | 294 | else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' && |
291 | (*argv)[2] == 0) | 295 | (*argv)[2] == 0) |
292 | outmode[2] = (*argv)[1]; | 296 | outmode[2] = (*argv)[1]; |
293 | else | 297 | else |
294 | break; | 298 | break; |
295 | argc--, argv++; | 299 | argc--, argv++; |
296 | } | 300 | } |
297 | if (argc == 0) { | 301 | if (argc == 0) { |
@@ -315,6 +319,5 @@ int main(argc, argv) | |||
315 | } | 319 | } |
316 | } while (argv++, --argc); | 320 | } while (argv++, --argc); |
317 | } | 321 | } |
318 | exit(0); | 322 | return 0; |
319 | return 0; /* to avoid warning */ | ||
320 | } | 323 | } |