OSDN Git Service

"printf %x 64" wasn't working right on 32 bit because a variable type was wrong.
[android-x86/external-toybox.git] / toys / posix / env.c
1 /* env.c - Set the environment for command invocation.
2  *
3  * Copyright 2012 Tryn Mirell <tryn@mirell.org>
4  *
5  * http://opengroup.org/onlinepubs/9699919799/utilities/env.html
6
7 USE_ENV(NEWTOY(env, "^iu*", TOYFLAG_USR|TOYFLAG_BIN))
8
9 config ENV
10   bool "env"
11   default y
12   help
13     usage: env [-i] [-u NAME] [NAME=VALUE...] [command [option...]]
14
15     Set the environment for command invocation.
16
17     -i  Clear existing environment.
18     -u NAME     Remove NAME from the environment
19 */
20
21 #define FOR_env
22 #include "toys.h"
23
24 GLOBALS(
25   struct arg_list *u;
26 );
27
28 extern char **environ;
29
30 void env_main(void)
31 {
32   char **ev;
33
34   if (toys.optflags & FLAG_i) clearenv();
35   while (TT.u) {
36     unsetenv(TT.u->arg);
37     TT.u = TT.u->next;
38   }
39
40   for (ev = toys.optargs; *ev; ev++) {
41     char *name = *ev, *val = strchr(name, '=');
42
43     if (val) {
44       *(val++) = 0;
45       setenv(name, val, 1);
46     } else xexec(ev);
47   }
48
49   if (environ) for (ev = environ; *ev; ev++) xputs(*ev);
50 }