summaryrefslogtreecommitdiffstats
path: root/isys/gzlib/test.c
blob: 227df692872d8dc40eb56ebeb9bb20562dfa4064 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include "gzlib.h"

int main(int argc, char ** argv) {
    gzFile fd;
    char buf[4096];
    int i;

    if (argv[1]) {
	if (!strcmp(argv[1], "-d")) {
	    fd = gunzip_dopen(0);
	    while ((i = gunzip_read(fd, buf, sizeof(buf))) > 0)
		if (write(1, buf, i) != i) break;
	    if (i != 0) {
		fprintf(stderr, "error occured: %s\n", strerror(errno));
		return -1;
	    }
	} else {
	    fprintf(stderr, "unknown argument\n");
	    return -1;
	}
    } else {
	fd = gzip_dopen(1);
	while ((i = read(0, buf, sizeof(buf))) > 0)
	    if (gzip_write(fd, buf, i) != i) break;

	if (i != 0) {
	    fprintf(stderr, "error occured: %s\n", strerror(errno));
	    return -1;
	}
    }

    return 0;
}