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[])
19 char * rpmio_flags = NULL;
23 setprogname(argv[0]); /* Retrofit glibc __progname */
25 fdi = fdDup(STDIN_FILENO);
27 if (rstreq(argv[1], "-h") || rstreq(argv[1], "--help")) {
28 fprintf(stderr, "Usage: rpm2cpio file.rpm\n");
31 fdi = Fopen(argv[1], "r.ufdio");
35 fprintf(stderr, "%s: %s: %s\n", argv[0],
36 (argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fdi));
39 fdo = fdDup(STDOUT_FILENO);
40 rpmReadConfigFiles(NULL, NULL);
42 { rpmts ts = rpmtsCreate();
43 rpmVSFlags vsflags = 0;
45 /* XXX retain the ageless behavior of rpm2cpio */
46 vsflags |= _RPMVSF_NODIGESTS;
47 vsflags |= _RPMVSF_NOSIGNATURES;
48 vsflags |= RPMVSF_NOHDRCHK;
49 (void) rpmtsSetVSFlags(ts, vsflags);
51 rc = rpmReadPackageFile(ts, fdi, "rpm2cpio", &h);
59 case RPMRC_NOTTRUSTED:
62 fprintf(stderr, _("argument is not an RPM package\n"));
67 fprintf(stderr, _("error reading header from package\n"));
72 /* Retrieve type of payload compression. */
73 { const char *compr = headerGetString(h, RPMTAG_PAYLOADCOMPRESSOR);
74 rpmio_flags = rstrscat(NULL, "r.", compr ? compr : "gzip", NULL);
77 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 */