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;
|
1998-11-23 03:48:48 +08:00
|
|
|
FD_t gzdi;
|
1996-03-03 01:36:57 +08:00
|
|
|
|
|
|
|
if (argc == 1) {
|
1998-11-20 02:10:28 +08:00
|
|
|
fdi = fdDup(STDIN_FILENO);
|
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");
|
1998-11-21 04:18:22 +08:00
|
|
|
exit(EXIT_FAILURE);
|
1996-03-03 01:36:57 +08:00
|
|
|
}
|
1998-11-20 02:10:28 +08:00
|
|
|
fdo = fdDup(STDOUT_FILENO);
|
1996-03-03 01:36:57 +08:00
|
|
|
|
1998-11-19 05:41:05 +08:00
|
|
|
rc = rpmReadPackageHeader(fdi, &hd, &isSource, NULL, NULL);
|
1998-11-23 03:48:48 +08:00
|
|
|
switch (rc) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stderr, _("argument is not an RPM package\n"));
|
1998-11-21 04:18:22 +08:00
|
|
|
exit(EXIT_FAILURE);
|
1998-11-23 03:48:48 +08:00
|
|
|
break;
|
|
|
|
default:
|
1998-09-28 06:03:52 +08:00
|
|
|
fprintf(stderr, _("error reading header from package\n"));
|
1998-11-21 04:18:22 +08:00
|
|
|
exit(EXIT_FAILURE);
|
1998-11-23 03:48:48 +08:00
|
|
|
break;
|
1996-03-03 01:36:57 +08:00
|
|
|
}
|
|
|
|
|
1998-11-23 03:48:48 +08:00
|
|
|
gzdi = gzdFdopen(fdi, "r"); /* XXX gzdi == fdi */
|
1996-03-03 01:36:57 +08:00
|
|
|
|
1998-11-23 03:48:48 +08:00
|
|
|
while ((ct = gzdRead(gzdi, &buffer, sizeof(buffer))) > 0) {
|
1998-11-19 05:41:05 +08:00
|
|
|
fdWrite(fdo, &buffer, ct);
|
1996-03-03 01:36:57 +08:00
|
|
|
}
|
1998-11-23 03:48:48 +08:00
|
|
|
|
|
|
|
if (ct < 0) {
|
|
|
|
fprintf (stderr, "rpm2cpio: zlib: %s\n", gzdStrerror(gzdi));
|
|
|
|
rc = EXIT_FAILURE;
|
|
|
|
} else {
|
|
|
|
rc = EXIT_SUCCESS;
|
1996-06-11 04:47:55 +08:00
|
|
|
}
|
1996-12-12 11:21:00 +08:00
|
|
|
|
1998-11-25 08:42:36 +08:00
|
|
|
gzdClose(gzdi); /* XXX gzdi == fdi */
|
1996-12-12 11:21:00 +08:00
|
|
|
|
1998-11-23 03:48:48 +08:00
|
|
|
return rc;
|
1996-03-03 01:36:57 +08:00
|
|
|
}
|