diff options
author | Denys Vlasenko | 2021-06-17 13:39:05 +0200 |
---|---|---|
committer | Denys Vlasenko | 2021-06-17 13:39:46 +0200 |
commit | c113796884c972244595040466975c74667d4359 (patch) | |
tree | 496c315dff060f8dd29208b574cd5d74f789507b /coreutils/env.c | |
parent | 91bc01c59b1be5c8a198f72078421e0b6e306a18 (diff) | |
download | busybox-c113796884c972244595040466975c74667d4359.zip busybox-c113796884c972244595040466975c74667d4359.tar.gz |
env: implement -0
function old new delta
packed_usage 33590 33618 +28
env_main 187 209 +22
.rodata 103242 103250 +8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/0 up/down: 58/0) Total: 58 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/env.c')
-rw-r--r-- | coreutils/env.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/coreutils/env.c b/coreutils/env.c index 4715bf7..a0ea4dd 100644 --- a/coreutils/env.c +++ b/coreutils/env.c @@ -39,13 +39,14 @@ /* http://www.opengroup.org/onlinepubs/007904975/utilities/env.html */ //usage:#define env_trivial_usage -//usage: "[-i] [-u NAME]... [-] [NAME=VALUE]... [PROG ARGS]" +//usage: "[-i0] [-u NAME]... [-] [NAME=VALUE]... [PROG ARGS]" // The "-" can occur only once (unlike, say, -i): it terminates option processing, // so if it is followed by another "-" arg (or any option-looking arg), // that arg will be taken as PROG (or even as NAME=VALUE, example: "-z=QWE"). //usage:#define env_full_usage "\n\n" //usage: "Print current environment or run PROG after setting up environment\n" //usage: "\n -, -i Start with empty environment" +//usage: "\n -0 NUL terminated output" //usage: "\n -u NAME Remove variable from environment" #include "libbb.h" @@ -56,8 +57,9 @@ int env_main(int argc UNUSED_PARAM, char **argv) unsigned opts; llist_t *unset_env = NULL; - opts = getopt32long(argv, "+iu:*", + opts = getopt32long(argv, "+i0u:*", "ignore-environment\0" No_argument "i" + "null\0" No_argument "0" "unset\0" Required_argument "u" , &unset_env ); @@ -92,8 +94,9 @@ int env_main(int argc UNUSED_PARAM, char **argv) if (environ) { /* clearenv() may set environ == NULL! */ char **ep; + opts = (opts & 2) ? 0 : '\n'; for (ep = environ; *ep; ep++) { - puts(*ep); + printf("%s%c", *ep, opts); } } |