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>
This commit is contained in:
Denys Vlasenko 2021-06-17 13:39:05 +02:00
parent 91bc01c59b
commit c113796884

View File

@ -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);
}
}