rpm: rpm2cpio.c Source File

rpm 4.11.1-rc1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

rpm2cpio.c
Go to the documentation of this file.
1 /* rpmarchive: spit out the main archive portion of a package */
2
3 #include "system.h"
4 const char *__progname;
5
6 #include <rpm/rpmlib.h> /* rpmReadPackageFile .. */
7 #include <rpm/rpmtag.h>
8 #include <rpm/rpmio.h>
9 #include <rpm/rpmpgp.h>
10
11 #include <rpm/rpmts.h>
12
13 #include "debug.h"
14
15 int main(int argc, char *argv[])
16 {
17 FD_t fdi, fdo;
18 Header h;
19 char * rpmio_flags = NULL;
20 int rc;
21 off_t payload_size;
22 FD_t gzdi;
23
24 setprogname(argv[0]); /* Retrofit glibc __progname */
25 rpmReadConfigFiles(NULL, NULL);
26 if (argc == 1)
27 fdi = fdDup(STDIN_FILENO);
28 else {
29 if (rstreq(argv[1], "-h") || rstreq(argv[1], "--help")) {
30 fprintf(stderr, "Usage: rpm2cpio file.rpm\n");
31 exit(EXIT_FAILURE);
32 }
33 fdi = Fopen(argv[1], "r.ufdio");
34 }
35
36 if (Ferror(fdi)) {
37 fprintf(stderr, "%s: %s: %s\n", argv[0],
38 (argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fdi));
39 exit(EXIT_FAILURE);
40 }
41 fdo = fdDup(STDOUT_FILENO);
42
43 { rpmts ts = rpmtsCreate();
44 rpmVSFlags vsflags = 0;
45
46 /* XXX retain the ageless behavior of rpm2cpio */
47 vsflags |= _RPMVSF_NODIGESTS;
48 vsflags |= _RPMVSF_NOSIGNATURES;
49 vsflags |= RPMVSF_NOHDRCHK;
50 (void) rpmtsSetVSFlags(ts, vsflags);
51
52 rc = rpmReadPackageFile(ts, fdi, "rpm2cpio", &h);
53
54 ts = rpmtsFree(ts);
55 }
56
57 switch (rc) {
58 case RPMRC_OK:
59 case RPMRC_NOKEY:
60 case RPMRC_NOTTRUSTED:
61 break;
62 case RPMRC_NOTFOUND:
63 fprintf(stderr, _("argument is not an RPM package\n"));
64 exit(EXIT_FAILURE);
65 break;
66 case RPMRC_FAIL:
67 default:
68 fprintf(stderr, _("error reading header from package\n"));
69 exit(EXIT_FAILURE);
70 break;
71 }
72
73 /* Retrieve payload size and compression type. */
74 { const char *compr = headerGetString(h, RPMTAG_PAYLOADCOMPRESSOR);
75 rpmio_flags = rstrscat(NULL, "r.", compr ? compr : "gzip", NULL);
76 payload_size = headerGetNumber(h, RPMTAG_LONGARCHIVESIZE);
77 }
78
79 gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */
80 free(rpmio_flags);
81
82 if (gzdi == NULL) {
83 fprintf(stderr, _("cannot re-open payload: %s\n"), Fstrerror(gzdi));
84 exit(EXIT_FAILURE);
85 }
86
87 rc = (ufdCopy(gzdi, fdo) == payload_size) ? EXIT_SUCCESS : EXIT_FAILURE;
88
89 Fclose(fdo);
90
91 Fclose(gzdi); /* XXX gzdi == fdi */
92
93 return rc;
94 }