diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-03-08 13:23:06 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-03-08 13:23:06 +0100 |
commit | 7798282db22cb60d95d452007cab73f0f5631ce5 (patch) | |
tree | 91218a67cc0299bab4cd5a298c6a1fbc5822606e | |
parent | f7fa8001b7db605b8ab18c688051583f6d5b687f (diff) | |
download | busybox-w32-7798282db22cb60d95d452007cab73f0f5631ce5.tar.gz busybox-w32-7798282db22cb60d95d452007cab73f0f5631ce5.tar.bz2 busybox-w32-7798282db22cb60d95d452007cab73f0f5631ce5.zip |
ipcs: further code shrink
function old new delta
packed_usage 32543 32547 +4
ipcs_main 1014 980 -34
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-34) Total: -30 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/ipcs.c | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/util-linux/ipcs.c b/util-linux/ipcs.c index dc107eb95..4863a5c29 100644 --- a/util-linux/ipcs.c +++ b/util-linux/ipcs.c | |||
@@ -565,7 +565,7 @@ static void print_sem(int semid) | |||
565 | //usage:#define ipcs_trivial_usage | 565 | //usage:#define ipcs_trivial_usage |
566 | //usage: "[[-smq] -i SHMID] | [[-asmq] [-tcplu]]" | 566 | //usage: "[[-smq] -i SHMID] | [[-asmq] [-tcplu]]" |
567 | //usage:#define ipcs_full_usage "\n\n" | 567 | //usage:#define ipcs_full_usage "\n\n" |
568 | //usage: " -i Show specific resource" | 568 | //usage: " -i ID Show specific resource" |
569 | //usage: "\nResource specification:" | 569 | //usage: "\nResource specification:" |
570 | //usage: "\n -m Shared memory segments" | 570 | //usage: "\n -m Shared memory segments" |
571 | //usage: "\n -q Message queues" | 571 | //usage: "\n -q Message queues" |
@@ -582,56 +582,55 @@ int ipcs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | |||
582 | int ipcs_main(int argc UNUSED_PARAM, char **argv) | 582 | int ipcs_main(int argc UNUSED_PARAM, char **argv) |
583 | { | 583 | { |
584 | int format = 0; | 584 | int format = 0; |
585 | unsigned flags = 0; | ||
586 | unsigned opt; | 585 | unsigned opt; |
587 | char *opt_i; | 586 | char *opt_i; |
588 | #define flag_msg (1<<0) | ||
589 | #define flag_sem (1<<1) | ||
590 | #define flag_shm (1<<2) | ||
591 | 587 | ||
592 | opt = getopt32(argv, "i:aqsmtcplu", &opt_i); | 588 | opt = getopt32(argv, "i:aqsmtcplu", &opt_i); |
593 | if (opt & 0x2) flags |= flag_msg | flag_sem | flag_shm; // -a | 589 | #define flag_msg (1<<2) |
594 | if (opt & 0x4) flags |= flag_msg; // -q | 590 | #define flag_sem (1<<3) |
595 | if (opt & 0x8) flags |= flag_sem; // -s | 591 | #define flag_shm (1<<4) |
596 | if (opt & 0x10) flags |= flag_shm; // -m | 592 | if (opt & (1<<5)) format = TIME; // -t |
597 | if (opt & 0x20) format = TIME; // -t | 593 | if (opt & (1<<6)) format = CREATOR; // -c |
598 | if (opt & 0x40) format = CREATOR; // -c | 594 | if (opt & (1<<7)) format = PID; // -p |
599 | if (opt & 0x80) format = PID; // -p | 595 | if (opt & (1<<8)) format = LIMITS; // -l |
600 | if (opt & 0x100) format = LIMITS; // -l | 596 | if (opt & (1<<9)) format = STATUS; // -u |
601 | if (opt & 0x200) format = STATUS; // -u | 597 | |
602 | 598 | if (opt & (1<<0)) { // -i | |
603 | if (opt & 1) { // -i | ||
604 | int id; | 599 | int id; |
605 | 600 | ||
606 | id = xatoi(opt_i); | 601 | id = xatoi(opt_i); |
607 | if (flags & flag_shm) { | 602 | if (opt & flag_shm) { |
608 | print_shm(id); | 603 | print_shm(id); |
609 | fflush_stdout_and_exit(EXIT_SUCCESS); | 604 | fflush_stdout_and_exit(EXIT_SUCCESS); |
610 | } | 605 | } |
611 | if (flags & flag_sem) { | 606 | if (opt & flag_sem) { |
612 | print_sem(id); | 607 | print_sem(id); |
613 | fflush_stdout_and_exit(EXIT_SUCCESS); | 608 | fflush_stdout_and_exit(EXIT_SUCCESS); |
614 | } | 609 | } |
615 | if (flags & flag_msg) { | 610 | if (opt & flag_msg) { |
616 | print_msg(id); | 611 | print_msg(id); |
617 | fflush_stdout_and_exit(EXIT_SUCCESS); | 612 | fflush_stdout_and_exit(EXIT_SUCCESS); |
618 | } | 613 | } |
619 | bb_show_usage(); | 614 | bb_show_usage(); |
620 | } | 615 | } |
621 | 616 | ||
622 | if (!(flags & (flag_shm | flag_msg | flag_sem))) | 617 | if ((opt & (1<<1)) // -a |
623 | flags |= flag_msg | flag_shm | flag_sem; | 618 | || !(opt & (flag_msg | flag_sem | flag_shm)) // none of -q,-s,-m == all |
619 | ) { | ||
620 | opt |= flag_msg | flag_sem | flag_shm; | ||
621 | } | ||
622 | |||
624 | bb_putchar('\n'); | 623 | bb_putchar('\n'); |
625 | 624 | ||
626 | if (flags & flag_msg) { | 625 | if (opt & flag_msg) { |
627 | do_msg(format); | 626 | do_msg(format); |
628 | bb_putchar('\n'); | 627 | bb_putchar('\n'); |
629 | } | 628 | } |
630 | if (flags & flag_shm) { | 629 | if (opt & flag_shm) { |
631 | do_shm(format); | 630 | do_shm(format); |
632 | bb_putchar('\n'); | 631 | bb_putchar('\n'); |
633 | } | 632 | } |
634 | if (flags & flag_sem) { | 633 | if (opt & flag_sem) { |
635 | do_sem(format); | 634 | do_sem(format); |
636 | bb_putchar('\n'); | 635 | bb_putchar('\n'); |
637 | } | 636 | } |