1 /* rpmarchive: spit out the main archive portion of a package */
8 int main(int argc, char **argv)
16 setprogname(argv[0]); /* Retrofit glibc __progname */
18 fdi = fdDup(STDIN_FILENO);
20 fdi = Fopen(argv[1], "r.ufdio");
23 if (fdi == NULL || Ferror(fdi)) {
24 fprintf(stderr, _("cannot open package: %s\n"), Fstrerror(fdi));
27 fdo = fdDup(STDOUT_FILENO);
29 rc = rpmReadPackageHeader(fdi, &h, &isSource, NULL, NULL);
34 fprintf(stderr, _("argument is not an RPM package\n"));
38 fprintf(stderr, _("error reading header from package\n"));
43 /* Retrieve type of payload compression. */
44 { const char * payload_compressor = NULL;
47 if (!headerGetEntry(h, RPMTAG_PAYLOADCOMPRESSOR, NULL,
48 (void **) &payload_compressor, NULL))
49 payload_compressor = "gzip";
50 rpmio_flags = t = alloca(sizeof("r.gzdio"));
52 if (!strcmp(payload_compressor, "gzip"))
53 t = stpcpy(t, ".gzdio");
54 if (!strcmp(payload_compressor, "bzip2"))
55 t = stpcpy(t, ".bzdio");
58 gzdi = Fdopen(fdi, rpmio_flags); /* XXX gzdi == fdi */
60 fprintf(stderr, _("cannot re-open payload: %s\n"), Fstrerror(gzdi));
65 { char buffer[BUFSIZ];
67 while ((ct = Fread(buffer, sizeof(buffer[0]), sizeof(buffer), gzdi)) > 0) {
68 Fwrite(buffer, sizeof(buffer[0]), ct, fdo);
72 fprintf (stderr, "rpm2cpio: zlib: %s\n", Fstrerror(gzdi));
79 rc = ufdCopy(gzdi, fdo);
80 rc = (rc <= 0) ? EXIT_FAILURE : EXIT_SUCCESS;
84 Fclose(gzdi); /* XXX gzdi == fdi */