summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2017-08-10 09:56:49 +0200
committerDenys Vlasenko2017-08-10 09:56:49 +0200
commit3c9b8fe25233dc52bbeec2ab29e49b8f62e4739b (patch)
treeba194a1dec44cc0bdc272277dc0b5c58933966dd
parente5650a40d4602c9a4ac7f3007d221bfb97dbf25a (diff)
downloadbusybox-3c9b8fe25233dc52bbeec2ab29e49b8f62e4739b.zip
busybox-3c9b8fe25233dc52bbeec2ab29e49b8f62e4739b.tar.gz
rpm2cpio: use rpm_gettags
function old new delta rpm_gettags - 451 +451 rpm2cpio_main 140 78 -62 skip_header 92 - -92 rpm_main 1477 1049 -428 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/2 up/down: 451/-582) Total: -131 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/rpm.c54
1 files changed, 10 insertions, 44 deletions
diff --git a/archival/rpm.c b/archival/rpm.c
index 461e170..f46d88b 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -124,7 +124,13 @@ static int rpm_gettags(const char *filename)
unsigned pass, idx;
unsigned storepos;
- fd = xopen(filename, O_RDONLY);
+ if (!filename) { /* rpm2cpio w/o filename? */
+ filename = bb_msg_standard_output;
+ fd = 0;
+ } else {
+ fd = xopen(filename, O_RDONLY);
+ }
+
storepos = xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
G.tagcount = 0;
tags = NULL;
@@ -500,55 +506,15 @@ int rpm_main(int argc, char **argv)
//usage:#define rpm2cpio_full_usage "\n\n"
//usage: "Output a cpio archive of the rpm file"
-enum { rpm_fd = STDIN_FILENO };
-
-static unsigned skip_header(void)
-{
- struct rpm_header header;
- unsigned len;
-
- xread(rpm_fd, &header, sizeof(header));
-// if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC_STR, 3) != 0) {
-// bb_error_msg_and_die("invalid RPM header magic");
-// }
-// if (header.version != 1) {
-// bb_error_msg_and_die("unsupported RPM header version");
-// }
- if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER)) {
- bb_error_msg_and_die("invalid RPM header magic or unsupported version");
- // ": %x != %x", header.magic_and_ver, htonl(RPM_HEADER_MAGICnVER));
- }
-
- /* Seek past index entries, and past store */
- len = 16 * ntohl(header.entries) + ntohl(header.size);
- seek_by_jump(rpm_fd, len);
-
- return sizeof(header) + len;
-}
-
/* No getopt required */
int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
{
- struct rpm_lead lead;
- unsigned pos;
-
- if (argv[1]) {
- xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd);
- }
- xread(rpm_fd, &lead, sizeof(lead));
+ int rpm_fd;
- /* Just check the magic, the rest is irrelevant */
- if (lead.magic != htonl(RPM_LEAD_MAGIC)) {
- bb_error_msg_and_die("invalid RPM magic");
- }
-
- /* Skip the signature header, align to 8 bytes */
- pos = skip_header();
- seek_by_jump(rpm_fd, (-(int)pos) & 7);
+ G.pagesize = getpagesize();
- /* Skip the main header */
- skip_header();
+ rpm_fd = rpm_gettags(argv[1]);
//if (SEAMLESS_COMPRESSION) - we do this at the end instead.
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */