Consolidate i18n baggage into AM_GNU_GETTEXT and system.h.
[platform/upstream/rpm.git] / rpm2cpio.c
1 /* rpmarchive: spit out the main archive portion of a package */
2
3 #include "system.h"
4
5 #include "rpmlib.h"
6
7 char *zlib_err [] = {
8    "No",
9    "Unix",
10    "Data",
11    "Memory",
12    "Buffer",
13    "Version"
14 };
15
16 int main(int argc, char **argv)
17 {
18     int fd;
19     Header hd;
20     int rc, isSource;
21     char buffer[1024];
22     int ct;
23     gzFile stream;
24     
25     if (argc == 1) {
26         fd = 0;
27     } else {
28         fd = open(argv[1], O_RDONLY, 0644);
29     }
30
31     if (fd < 0) {
32         perror("cannot open package");
33         exit(1);
34     }
35
36     rc = rpmReadPackageHeader(fd, &hd, &isSource, NULL, NULL);
37     if (rc == 1) {
38         fprintf(stderr, _("argument is not an RPM package\n"));
39         exit(1);
40     } else if (rc) {
41         fprintf(stderr, _("error reading header from package\n"));
42         exit(1);
43     }
44
45     stream = gzdopen(fd, "r");
46
47     while ((ct = gzread(stream, &buffer, 1024)) > 0) {
48         write(1, &buffer, ct);
49     }
50     if (ct < 0){
51         int zerror;
52        
53         gzerror (stream, &zerror);
54         if (zerror == Z_ERRNO){
55             perror ("While uncompressing");
56             gzclose(stream);
57             return 1;
58         }
59         fprintf (stderr, "rpm2cpio: zlib: %s error\n", zlib_err [-zerror - 1]);
60     }
61
62     gzclose(stream);
63
64     return 0;
65 }