diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-10 09:56:49 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-10 09:56:49 +0200 |
commit | 3c9b8fe25233dc52bbeec2ab29e49b8f62e4739b (patch) | |
tree | ba194a1dec44cc0bdc272277dc0b5c58933966dd | |
parent | e5650a40d4602c9a4ac7f3007d221bfb97dbf25a (diff) | |
download | busybox-w32-3c9b8fe25233dc52bbeec2ab29e49b8f62e4739b.tar.gz busybox-w32-3c9b8fe25233dc52bbeec2ab29e49b8f62e4739b.tar.bz2 busybox-w32-3c9b8fe25233dc52bbeec2ab29e49b8f62e4739b.zip |
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.c | 54 |
1 files changed, 10 insertions, 44 deletions
diff --git a/archival/rpm.c b/archival/rpm.c index 461e1707f..f46d88b92 100644 --- a/archival/rpm.c +++ b/archival/rpm.c | |||
@@ -124,7 +124,13 @@ static int rpm_gettags(const char *filename) | |||
124 | unsigned pass, idx; | 124 | unsigned pass, idx; |
125 | unsigned storepos; | 125 | unsigned storepos; |
126 | 126 | ||
127 | fd = xopen(filename, O_RDONLY); | 127 | if (!filename) { /* rpm2cpio w/o filename? */ |
128 | filename = bb_msg_standard_output; | ||
129 | fd = 0; | ||
130 | } else { | ||
131 | fd = xopen(filename, O_RDONLY); | ||
132 | } | ||
133 | |||
128 | storepos = xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */ | 134 | storepos = xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */ |
129 | G.tagcount = 0; | 135 | G.tagcount = 0; |
130 | tags = NULL; | 136 | tags = NULL; |
@@ -500,55 +506,15 @@ int rpm_main(int argc, char **argv) | |||
500 | //usage:#define rpm2cpio_full_usage "\n\n" | 506 | //usage:#define rpm2cpio_full_usage "\n\n" |
501 | //usage: "Output a cpio archive of the rpm file" | 507 | //usage: "Output a cpio archive of the rpm file" |
502 | 508 | ||
503 | enum { rpm_fd = STDIN_FILENO }; | ||
504 | |||
505 | static unsigned skip_header(void) | ||
506 | { | ||
507 | struct rpm_header header; | ||
508 | unsigned len; | ||
509 | |||
510 | xread(rpm_fd, &header, sizeof(header)); | ||
511 | // if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC_STR, 3) != 0) { | ||
512 | // bb_error_msg_and_die("invalid RPM header magic"); | ||
513 | // } | ||
514 | // if (header.version != 1) { | ||
515 | // bb_error_msg_and_die("unsupported RPM header version"); | ||
516 | // } | ||
517 | if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER)) { | ||
518 | bb_error_msg_and_die("invalid RPM header magic or unsupported version"); | ||
519 | // ": %x != %x", header.magic_and_ver, htonl(RPM_HEADER_MAGICnVER)); | ||
520 | } | ||
521 | |||
522 | /* Seek past index entries, and past store */ | ||
523 | len = 16 * ntohl(header.entries) + ntohl(header.size); | ||
524 | seek_by_jump(rpm_fd, len); | ||
525 | |||
526 | return sizeof(header) + len; | ||
527 | } | ||
528 | |||
529 | /* No getopt required */ | 509 | /* No getopt required */ |
530 | int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 510 | int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
531 | int rpm2cpio_main(int argc UNUSED_PARAM, char **argv) | 511 | int rpm2cpio_main(int argc UNUSED_PARAM, char **argv) |
532 | { | 512 | { |
533 | struct rpm_lead lead; | 513 | int rpm_fd; |
534 | unsigned pos; | ||
535 | |||
536 | if (argv[1]) { | ||
537 | xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd); | ||
538 | } | ||
539 | xread(rpm_fd, &lead, sizeof(lead)); | ||
540 | 514 | ||
541 | /* Just check the magic, the rest is irrelevant */ | 515 | G.pagesize = getpagesize(); |
542 | if (lead.magic != htonl(RPM_LEAD_MAGIC)) { | ||
543 | bb_error_msg_and_die("invalid RPM magic"); | ||
544 | } | ||
545 | |||
546 | /* Skip the signature header, align to 8 bytes */ | ||
547 | pos = skip_header(); | ||
548 | seek_by_jump(rpm_fd, (-(int)pos) & 7); | ||
549 | 516 | ||
550 | /* Skip the main header */ | 517 | rpm_fd = rpm_gettags(argv[1]); |
551 | skip_header(); | ||
552 | 518 | ||
553 | //if (SEAMLESS_COMPRESSION) - we do this at the end instead. | 519 | //if (SEAMLESS_COMPRESSION) - we do this at the end instead. |
554 | // /* We need to know whether child (gzip/bzip/etc) exits abnormally */ | 520 | // /* We need to know whether child (gzip/bzip/etc) exits abnormally */ |