~ubuntu-branches/ubuntu/precise/gzip/precise

« back to all changes in this revision

Viewing changes to sample/zread.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-10-19 11:42:42 UTC
  • mfrom: (4.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20111019114242-d8wiiu8kbvdtgmgj
Tags: 1.4-1ubuntu1
* Merge with Debian testing.  Remaining Ubuntu changes:
  - debian/{control,rules}: Remove the Win32 build and mingw64
    build-dependency, since mingw is in universe, and will remain so for
    the forseeable future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <config.h>
1
2
#include <stdio.h>
 
3
#include <stdlib.h>
2
4
 
3
5
/* Trivial example of reading a gzip'ed file or gzip'ed standard input
4
6
 * using stdio functions fread(), getc(), etc... fseek() is not supported.
19
21
 
20
22
    if (argc < 1 || argc > 2) {
21
23
        fprintf(stderr, "usage: %s [file[.gz]]\n", argv[0]);
22
 
        exit(1);
 
24
        exit(EXIT_FAILURE);
23
25
    }
24
26
    strcpy(cmd, "gzip -dc ");  /* use "gzip -c" for zwrite */
25
27
    if (argc == 2) {
28
30
    infile = popen(cmd, "r");  /* use "w" for zwrite */
29
31
    if (infile == NULL) {
30
32
        fprintf(stderr, "%s: popen('%s', 'r') failed\n", argv[0], cmd);
31
 
        exit(1);
 
33
        exit(EXIT_FAILURE);
32
34
    }
33
35
    /* Read one byte using getc: */
34
36
    n = getc(infile);
35
37
    if (n == EOF) {
36
38
        pclose(infile);
37
 
        exit(0);
 
39
        exit(EXIT_SUCCESS);
38
40
    }
39
41
    putchar(n);
40
42
 
46
48
    }
47
49
    if (pclose(infile) != 0) {
48
50
        fprintf(stderr, "%s: pclose failed\n", argv[0]);
49
 
        exit(1);
 
51
        exit(EXIT_FAILURE);
50
52
    }
51
 
    exit(0);
 
53
    exit(EXIT_SUCCESS);
52
54
    return 0; /* just to make compiler happy */
53
55
}