View | Details | Raw Unified | Return to bug 13043 | Differences between
and this patch

Collapse All | Expand All

(-)../../lib/libz/minigzip.c (-8 / +35 lines)
Lines 122-128 Link Here
122
        if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
122
        if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
123
    }
123
    }
124
    fclose(in);
124
    fclose(in);
125
    if (gzclose(out) != Z_OK) error("failed gzclose");
126
}
125
}
127
126
128
#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
127
#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
Lines 157-163 Link Here
157
156
158
    munmap(buf, buf_len);
157
    munmap(buf, buf_len);
159
    fclose(in);
158
    fclose(in);
160
    if (gzclose(out) != Z_OK) error("failed gzclose");
161
    return Z_OK;
159
    return Z_OK;
162
}
160
}
163
#endif /* USE_MMAP */
161
#endif /* USE_MMAP */
Lines 182-188 Link Here
182
	    error("failed fwrite");
180
	    error("failed fwrite");
183
	}
181
	}
184
    }
182
    }
185
    if (fclose(out)) error("failed fclose");
186
183
187
    if (gzclose(in) != Z_OK) error("failed gzclose");
184
    if (gzclose(in) != Z_OK) error("failed gzclose");
188
}
185
}
Lines 215-220 Link Here
215
    }
212
    }
216
    gz_compress(in, out);
213
    gz_compress(in, out);
217
214
215
    if (gzclose(out) != Z_OK) error("failed gzclose");
218
    unlink(file);
216
    unlink(file);
219
}
217
}
220
218
Lines 255-266 Link Here
255
253
256
    gz_uncompress(in, out);
254
    gz_uncompress(in, out);
257
255
256
    if (fclose(out)) error("failed fclose");
258
    unlink(infile);
257
    unlink(infile);
259
}
258
}
260
259
261
260
262
/* ===========================================================================
261
/* ===========================================================================
263
 * Usage:  minigzip [-d] [-f] [-h] [-1 to -9] [files...]
262
 * Usage:  minigzip [-c] [-d] [-f] [-h] [-1 to -9] [files...]
263
 *   -c : standart output
264
 *   -d : decompress
264
 *   -d : decompress
265
 *   -f : compress with Z_FILTERED
265
 *   -f : compress with Z_FILTERED
266
 *   -h : compress with Z_HUFFMAN_ONLY
266
 *   -h : compress with Z_HUFFMAN_ONLY
Lines 271-276 Link Here
271
    int argc;
271
    int argc;
272
    char *argv[];
272
    char *argv[];
273
{
273
{
274
    int copyout = 0;
274
    int uncompr = 0;
275
    int uncompr = 0;
275
    gzFile file;
276
    gzFile file;
276
    char *bname, outmode[20];
277
    char *bname, outmode[20];
Lines 285-296 Link Here
285
      bname = argv[0];
286
      bname = argv[0];
286
    argc--, argv++;
287
    argc--, argv++;
287
288
288
    if (!strcmp(bname, "gunzip") || !strcmp(bname, "zcat"))
289
    if (!strcmp(bname, "gunzip"))
289
      uncompr = 1;
290
      uncompr = 1;
291
    else if (!strcmp(bname, "zcat"))
292
      copyout = uncompr = 1;
290
293
291
    while (argc > 0) {
294
    while (argc > 0) {
292
      if (strcmp(*argv, "-c") == 0)
295
      if (strcmp(*argv, "-c") == 0)
293
	; /* Just for compatability with gzip */
296
	copyout = 1; /* Just for compatability with gzip */
294
      else if (strcmp(*argv, "-d") == 0)
297
      else if (strcmp(*argv, "-d") == 0)
295
	uncompr = 1;
298
	uncompr = 1;
296
      else if (strcmp(*argv, "-f") == 0)
299
      else if (strcmp(*argv, "-f") == 0)
Lines 315-329 Link Here
315
            file = gzdopen(fileno(stdout), outmode);
318
            file = gzdopen(fileno(stdout), outmode);
316
            if (file == NULL) error("can't gzdopen stdout");
319
            if (file == NULL) error("can't gzdopen stdout");
317
            gz_compress(stdin, file);
320
            gz_compress(stdin, file);
321
	    if (gzclose(file) != Z_OK) error("failed gzclose");
318
        }
322
        }
319
    } else {
323
    } else {
324
	if (copyout) {
325
	    SET_BINARY_MODE(stdout);
326
            if (!uncompr) {
327
		file = gzdopen(fileno(stdout), outmode);
328
		if (file == NULL) error("can't gzdopen stdout");
329
	    }
330
	}
320
        do {
331
        do {
321
            if (uncompr) {
332
            if (uncompr) {
322
                file_uncompress(*argv);
333
		if (copyout) {
334
		    file = gzopen(*argv, "rb");
335
		    if (file == NULL)
336
			fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv);
337
		    else
338
			gz_uncompress(file, stdout);
339
		} else
340
		    file_uncompress(*argv);
323
            } else {
341
            } else {
324
                file_compress(*argv, outmode);
342
		if (copyout) {
343
		    FILE * in = fopen(*argv, "rb");
344
		    if (in == NULL)
345
			perror(*argv);
346
		    else
347
			gz_compress(in, file);
348
		} else
349
		    file_compress(*argv, outmode);
325
            }
350
            }
326
        } while (argv++, --argc);
351
        } while (argv++, --argc);
352
	if (copyout && !uncompr)
353
	    if (gzclose(file) != Z_OK) error("failed gzclose");
327
    }
354
    }
328
    exit(0);
355
    exit(0);
329
    return 0; /* to avoid warning */
356
    return 0; /* to avoid warning */
(-)minigzip.1 (+5 lines)
Lines 32-37 Link Here
32
.Nd minimal implementation of the 'gzip' compression tool
32
.Nd minimal implementation of the 'gzip' compression tool
33
.Sh SYNOPSIS
33
.Sh SYNOPSIS
34
.Nm minigzip
34
.Nm minigzip
35
.Op Fl c
35
.Op Fl d
36
.Op Fl d
36
.Op Ar file ...
37
.Op Ar file ...
37
.Sh DESCRIPTION
38
.Sh DESCRIPTION
Lines 63-68 Link Here
63
.Nm
64
.Nm
64
reads from standard input and writes the results of the operation 
65
reads from standard input and writes the results of the operation 
65
to standard output.
66
to standard output.
67
.Pp
68
If the
69
.Fl c
70
option is specified, write results to standard output.
66
.Sh SEE ALSO
71
.Sh SEE ALSO
67
.Xr gzip 1
72
.Xr gzip 1
68
.Sh AUTHORS
73
.Sh AUTHORS

Return to bug 13043