diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-04 16:23:42 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-04 16:33:23 +0200 |
commit | 727948e585cb133c32c8d42570e5524c58190307 (patch) | |
tree | f2beb48ded47f9d8ebef707516e7bbb00335b1a8 /procps | |
parent | 7f9d62d7f5b67b6b1cc7e0b94826ba2a6e193586 (diff) | |
download | busybox-w32-727948e585cb133c32c8d42570e5524c58190307.tar.gz busybox-w32-727948e585cb133c32c8d42570e5524c58190307.tar.bz2 busybox-w32-727948e585cb133c32c8d42570e5524c58190307.zip |
getopt32: factor out code to treat all args as options
Working towards making getopt32() xmalloc-free
function old new delta
make_all_argv_opts - 58 +58
top_main 914 912 -2
getopt32 1517 1458 -59
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 0/2 up/down: 58/-61) Total: -3 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'procps')
-rw-r--r-- | procps/ps.c | 5 | ||||
-rw-r--r-- | procps/top.c | 5 |
2 files changed, 5 insertions, 5 deletions
diff --git a/procps/ps.c b/procps/ps.c index eb1946d27..081479b33 100644 --- a/procps/ps.c +++ b/procps/ps.c | |||
@@ -715,7 +715,8 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
715 | # if ENABLE_FEATURE_PS_WIDE | 715 | # if ENABLE_FEATURE_PS_WIDE |
716 | /* -w is a bit complicated */ | 716 | /* -w is a bit complicated */ |
717 | int w_count = 0; | 717 | int w_count = 0; |
718 | opt_complementary = "-:ww"; | 718 | make_all_argv_opts(argv); |
719 | opt_complementary = "ww"; | ||
719 | opts = getopt32(argv, IF_SELINUX("Z")IF_FEATURE_SHOW_THREADS("T")IF_FEATURE_PS_LONG("l") | 720 | opts = getopt32(argv, IF_SELINUX("Z")IF_FEATURE_SHOW_THREADS("T")IF_FEATURE_PS_LONG("l") |
720 | "w", &w_count); | 721 | "w", &w_count); |
721 | /* if w is given once, GNU ps sets the width to 132, | 722 | /* if w is given once, GNU ps sets the width to 132, |
@@ -731,7 +732,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
731 | } | 732 | } |
732 | # else | 733 | # else |
733 | /* -w is not supported, only -Z and/or -T */ | 734 | /* -w is not supported, only -Z and/or -T */ |
734 | opt_complementary = "-"; | 735 | make_all_argv_opts(argv); |
735 | opts = getopt32(argv, IF_SELINUX("Z")IF_FEATURE_SHOW_THREADS("T")IF_FEATURE_PS_LONG("l")); | 736 | opts = getopt32(argv, IF_SELINUX("Z")IF_FEATURE_SHOW_THREADS("T")IF_FEATURE_PS_LONG("l")); |
736 | # endif | 737 | # endif |
737 | 738 | ||
diff --git a/procps/top.c b/procps/top.c index 015d1ab74..1bc432fc9 100644 --- a/procps/top.c +++ b/procps/top.c | |||
@@ -1110,15 +1110,14 @@ int top_main(int argc UNUSED_PARAM, char **argv) | |||
1110 | #endif | 1110 | #endif |
1111 | 1111 | ||
1112 | /* all args are options; -n NUM */ | 1112 | /* all args are options; -n NUM */ |
1113 | opt_complementary = "-"; /* options can be specified w/o dash */ | 1113 | make_all_argv_opts(argv); /* options can be specified w/o dash */ |
1114 | col = getopt32(argv, "d:n:b"IF_FEATURE_TOPMEM("m"), &str_interval, &str_iterations); | 1114 | col = getopt32(argv, "d:n:b"IF_FEATURE_TOPMEM("m"), &str_interval, &str_iterations); |
1115 | #if ENABLE_FEATURE_TOPMEM | 1115 | #if ENABLE_FEATURE_TOPMEM |
1116 | if (col & OPT_m) /* -m (busybox specific) */ | 1116 | if (col & OPT_m) /* -m (busybox specific) */ |
1117 | scan_mask = TOPMEM_MASK; | 1117 | scan_mask = TOPMEM_MASK; |
1118 | #endif | 1118 | #endif |
1119 | if (col & OPT_d) { | 1119 | if (col & OPT_d) { |
1120 | /* work around for "-d 1" -> "-d -1" done by getopt32 | 1120 | /* work around for "-d 1" -> "-d -1" done by make_all_argv_opts() */ |
1121 | * (opt_complementary == "-" does this) */ | ||
1122 | if (str_interval[0] == '-') | 1121 | if (str_interval[0] == '-') |
1123 | str_interval++; | 1122 | str_interval++; |
1124 | /* Need to limit it to not overflow poll timeout */ | 1123 | /* Need to limit it to not overflow poll timeout */ |