1 /* rpmarchive: spit out the main archive portion of a package */
4 const char *__progname;
6 #include <rpm/rpmlib.h> /* rpmReadPackageFile .. */
7 #include <rpm/rpmtag.h>
9 #include <rpm/rpmpgp.h>
11 #include <rpm/rpmts.h>
15 int main(int argc, char *argv[])
23 setprogname(argv[0]); /* Retrofit glibc __progname */
25 fdi = fdDup(STDIN_FILENO);
27 fdi = Fopen(argv[1], "r.ufdio");
30 fprintf(stderr, "%s: %s: %s\n", argv[0],
31 (argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fdi));
34 fdo = fdDup(STDOUT_FILENO);
36 { rpmts ts = rpmtsCreate();
37 rpmVSFlags vsflags = 0;
39 /* XXX retain the ageless behavior of rpm2cpio */
40 vsflags |= _RPMVSF_NODIGESTS;
41 vsflags |= _RPMVSF_NOSIGNATURES;
42 vsflags |= RPMVSF_NOHDRCHK;
43 (void) rpmtsSetVSFlags(ts, vsflags);
46 rc = rpmReadPackageFile(ts, fdi, "rpm2cpio", &h);
54 case RPMRC_NOTTRUSTED:
57 fprintf(stderr, _("argument is not an RPM package\n"));
62 fprintf(stderr, _("error reading header from package\n"));
67 /* Retrieve type of payload compression. */
68 { const char * payload_compressor = NULL;
70 if (!headerGetEntry(h, RPMTAG_PAYLOADCOMPRESSOR, NULL,
71 (rpm_data_t *) &payload_compressor, NULL))
72 payload_compressor = "gzip";
73 if (!strcmp(payload_compressor, "gzip"))
74 rpmio_flags = "r.gzdio";
75 if (!strcmp(payload_compressor, "bzip2"))
76 rpmio_flags = "r.bzdio";
79 gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */
81 fprintf(stderr, _("cannot re-open payload: %s\n"), Fstrerror(gzdi));
85 rc = ufdCopy(gzdi, fdo);
86 rc = (rc <= 0) ? EXIT_FAILURE : EXIT_SUCCESS;
89 Fclose(gzdi); /* XXX gzdi == fdi */