From c113796884c972244595040466975c74667d4359 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 17 Jun 2021 13:39:05 +0200 Subject: 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 --- coreutils/env.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/coreutils/env.c b/coreutils/env.c index 4715bf73a..a0ea4dd27 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); } } -- cgit v1.2.3