Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

rpm2cpio.c

Go to the documentation of this file.
00001 /* rpmarchive: spit out the main archive portion of a package */
00002 
00003 #include "system.h"
00004 
00005 #include "rpmlib.h"
00006 #include "debug.h"
00007 
00008 int main(int argc, char **argv)
00009 {
00010     FD_t fdi, fdo;
00011     Header h;
00012     char * rpmio_flags;
00013     int rc, isSource;
00014     FD_t gzdi;
00015     
00016     setprogname(argv[0]);       /* Retrofit glibc __progname */
00017     if (argc == 1)
00018         fdi = fdDup(STDIN_FILENO);
00019     else
00020         fdi = Fopen(argv[1], "r.ufdio");
00021 
00022     if (Ferror(fdi)) {
00023         fprintf(stderr, "%s: %s: %s\n", argv[0],
00024                 (argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fdi));
00025         exit(EXIT_FAILURE);
00026     }
00027     fdo = fdDup(STDOUT_FILENO);
00028 
00029     rc = rpmReadPackageHeader(fdi, &h, &isSource, NULL, NULL);
00030     switch (rc) {
00031     case 0:
00032         break;
00033     case 1:
00034         fprintf(stderr, _("argument is not an RPM package\n"));
00035         exit(EXIT_FAILURE);
00036         break;
00037     default:
00038         fprintf(stderr, _("error reading header from package\n"));
00039         exit(EXIT_FAILURE);
00040         break;
00041     }
00042 
00043     /* Retrieve type of payload compression. */
00044     {   const char * payload_compressor = NULL;
00045         char * t;
00046 
00047         if (!headerGetEntry(h, RPMTAG_PAYLOADCOMPRESSOR, NULL,
00048                             (void **) &payload_compressor, NULL))
00049             payload_compressor = "gzip";
00050         rpmio_flags = t = alloca(sizeof("r.gzdio"));
00051         *t++ = 'r';
00052         if (!strcmp(payload_compressor, "gzip"))
00053             t = stpcpy(t, ".gzdio");
00054         if (!strcmp(payload_compressor, "bzip2"))
00055             t = stpcpy(t, ".bzdio");
00056     }
00057 
00058     gzdi = Fdopen(fdi, rpmio_flags);    /* XXX gzdi == fdi */
00059     if (gzdi == NULL) {
00060         fprintf(stderr, _("cannot re-open payload: %s\n"), Fstrerror(gzdi));
00061         exit(EXIT_FAILURE);
00062     }
00063 
00064     rc = ufdCopy(gzdi, fdo);
00065     rc = (rc <= 0) ? EXIT_FAILURE : EXIT_SUCCESS;
00066     Fclose(fdo);
00067 
00068     Fclose(gzdi);       /* XXX gzdi == fdi */
00069 
00070     return rc;
00071 }

Generated on Fri Jan 21 18:52:37 2005 for rpm by doxygen 1.3.6