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 /libbb/getopt_allopts.c | |
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 'libbb/getopt_allopts.c')
-rw-r--r-- | libbb/getopt_allopts.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/libbb/getopt_allopts.c b/libbb/getopt_allopts.c new file mode 100644 index 000000000..a67d2b70e --- /dev/null +++ b/libbb/getopt_allopts.c | |||
@@ -0,0 +1,27 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Copyright (C) 2017 Denys Vlasenko | ||
4 | * | ||
5 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | ||
6 | */ | ||
7 | #include "libbb.h" | ||
8 | |||
9 | //kbuild:lib-y += getopt_allopts.o | ||
10 | |||
11 | void FAST_FUNC make_all_argv_opts(char **argv) | ||
12 | { | ||
13 | /* Note: we skip argv[0] */ | ||
14 | while (*++argv) { | ||
15 | char *p; | ||
16 | |||
17 | if (argv[0][0] == '-') | ||
18 | continue; | ||
19 | /* Neither top nor ps care if "" arg turns into "-" */ | ||
20 | /*if (argv[0][0] == '\0') | ||
21 | continue;*/ | ||
22 | p = xmalloc(strlen(*argv) + 2); | ||
23 | *p = '-'; | ||
24 | strcpy(p + 1, *argv); | ||
25 | *argv = p; | ||
26 | } | ||
27 | } | ||