1996-03-03 01:36:57 +08:00
|
|
|
/* rpmarchive: spit out the main archive portion of a package */
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include "system.h"
|
|
|
|
|
1996-03-03 01:36:57 +08:00
|
|
|
#include "rpmlib.h"
|
|
|
|
|
1996-06-11 04:47:55 +08:00
|
|
|
char *zlib_err [] = {
|
|
|
|
"No",
|
|
|
|
"Unix",
|
|
|
|
"Data",
|
|
|
|
"Memory",
|
|
|
|
"Buffer",
|
|
|
|
"Version"
|
|
|
|
};
|
|
|
|
|
1996-03-03 01:36:57 +08:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
1998-11-19 05:41:05 +08:00
|
|
|
FD_t fdi, fdo;
|
1996-03-03 01:36:57 +08:00
|
|
|
Header hd;
|
|
|
|
int rc, isSource;
|
|
|
|
char buffer[1024];
|
|
|
|
int ct;
|
|
|
|
gzFile stream;
|
|
|
|
|
|
|
|
if (argc == 1) {
|
1998-11-19 05:41:05 +08:00
|
|
|
fdi = fdDup(0);
|
1996-03-03 01:36:57 +08:00
|
|
|
} else {
|
1998-11-19 05:41:05 +08:00
|
|
|
fdi = fdOpen(argv[1], O_RDONLY, 0644);
|
1996-03-03 01:36:57 +08:00
|
|
|
}
|
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
if (fdFileno(fdi) < 0) {
|
1996-03-03 01:36:57 +08:00
|
|
|
perror("cannot open package");
|
|
|
|
exit(1);
|
|
|
|
}
|
1998-11-19 05:41:05 +08:00
|
|
|
fdo = fdDup(1);
|
1996-03-03 01:36:57 +08:00
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
rc = rpmReadPackageHeader(fdi, &hd, &isSource, NULL, NULL);
|
1996-03-03 01:36:57 +08:00
|
|
|
if (rc == 1) {
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stderr, _("argument is not an RPM package\n"));
|
1996-03-03 01:36:57 +08:00
|
|
|
exit(1);
|
|
|
|
} else if (rc) {
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stderr, _("error reading header from package\n"));
|
1996-03-03 01:36:57 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
stream = gzdopen(fdFileno(fdi), "r");
|
1996-03-03 01:36:57 +08:00
|
|
|
|
1996-06-11 04:47:55 +08:00
|
|
|
while ((ct = gzread(stream, &buffer, 1024)) > 0) {
|
1998-11-19 05:41:05 +08:00
|
|
|
fdWrite(fdo, &buffer, ct);
|
1996-03-03 01:36:57 +08:00
|
|
|
}
|
1996-06-11 04:47:55 +08:00
|
|
|
if (ct < 0){
|
|
|
|
int zerror;
|
|
|
|
|
|
|
|
gzerror (stream, &zerror);
|
|
|
|
if (zerror == Z_ERRNO){
|
|
|
|
perror ("While uncompressing");
|
1996-12-12 11:21:00 +08:00
|
|
|
gzclose(stream);
|
1996-06-11 04:47:55 +08:00
|
|
|
return 1;
|
|
|
|
}
|
1997-08-21 09:20:16 +08:00
|
|
|
fprintf (stderr, "rpm2cpio: zlib: %s error\n", zlib_err [-zerror - 1]);
|
1996-06-11 04:47:55 +08:00
|
|
|
}
|
1996-12-12 11:21:00 +08:00
|
|
|
|
|
|
|
gzclose(stream);
|
|
|
|
|
1996-03-03 01:36:57 +08:00
|
|
|
return 0;
|
|
|
|
}
|