Main Page   Modules   Compound List   File List   Compound Members   File Members   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 
00023     if (fdi == NULL || Ferror(fdi)) {
00024         fprintf(stderr, _("cannot open package: %s\n"), 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 #ifdef  DYING
00065   { char buffer[BUFSIZ];
00066     int ct;
00067     while ((ct = Fread(buffer, sizeof(buffer[0]), sizeof(buffer), gzdi)) > 0) {
00068         Fwrite(buffer, sizeof(buffer[0]), ct, fdo);
00069     }
00070 
00071     if (ct < 0) {
00072         fprintf (stderr, "rpm2cpio: zlib: %s\n", Fstrerror(gzdi));
00073         rc = EXIT_FAILURE;
00074     } else {
00075         rc = EXIT_SUCCESS;
00076     }
00077   }
00078 #else
00079     rc = ufdCopy(gzdi, fdo);
00080     rc = (rc <= 0) ? EXIT_FAILURE : EXIT_SUCCESS;
00081     Fclose(fdo);
00082 #endif
00083 
00084     Fclose(gzdi);       /* XXX gzdi == fdi */
00085 
00086     return rc;
00087 }

Generated at Sun Apr 8 18:43:01 2001 for rpm by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000