Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/coreutils/env.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/coreutils/env.c
r1765 r2725 4 4 * 5 5 * Copyright (c) 1988, 1993, 1994 6 * 6 * The Regents of the University of California. All rights reserved. 7 7 * 8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.8 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 9 9 * 10 10 * Original copyright notice is retained at the end of this file. … … 30 30 */ 31 31 32 #include <getopt.h> /* struct option */ 33 extern char **environ; 32 /* This is a NOEXEC applet. Be very careful! */ 34 33 35 34 #include "libbb.h" … … 42 41 #endif 43 42 44 int env_main(int argc, char ** argv);45 int env_main(int argc , char**argv)43 int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 44 int env_main(int argc UNUSED_PARAM, char **argv) 46 45 { 47 /* cleanenv was static - why? */ 48 char *cleanenv[1]; 49 char **ep; 50 unsigned opt; 46 unsigned opts; 51 47 llist_t *unset_env = NULL; 52 48 … … 55 51 applet_long_options = env_longopts; 56 52 #endif 57 opt = getopt32(argv, "+iu:", &unset_env);53 opts = getopt32(argv, "+iu:", &unset_env); 58 54 argv += optind; 59 if ( *argv&& LONE_DASH(argv[0])) {60 opt |= 1;55 if (argv[0] && LONE_DASH(argv[0])) { 56 opts |= 1; 61 57 ++argv; 62 58 } 63 if (opt & 1) { 64 cleanenv[0] = NULL; 65 environ = cleanenv; 66 } else { 67 while (unset_env) { 68 unsetenv(unset_env->data); 69 unset_env = unset_env->link; 70 } 59 if (opts & 1) { 60 clearenv(); 61 } 62 while (unset_env) { 63 char *var = llist_pop(&unset_env); 64 /* This does not handle -uVAR=VAL 65 * (coreutils _sets_ the variable in that case): */ 66 /*unsetenv(var);*/ 67 /* This does, but uses somewhan undocumented feature that 68 * putenv("name_without_equal_sign") unsets the variable: */ 69 putenv(var); 71 70 } 72 71 … … 78 77 } 79 78 80 if (*argv) { 81 BB_EXECVP(*argv, argv); 82 /* SUSv3-mandated exit codes. */ 83 xfunc_error_retval = (errno == ENOENT) ? 127 : 126; 84 bb_perror_msg_and_die("%s", *argv); 79 if (argv[0]) { 80 BB_EXECVP_or_die(argv); 85 81 } 86 82 87 for (ep = environ; *ep; ep++) { 88 puts(*ep); 83 if (environ) { /* clearenv() may set environ == NULL! */ 84 char **ep; 85 for (ep = environ; *ep; ep++) { 86 puts(*ep); 87 } 89 88 } 90 89 91 fflush_stdout_and_exit( 0);90 fflush_stdout_and_exit(EXIT_SUCCESS); 92 91 } 93 92 … … 105 104 * documentation and/or other materials provided with the distribution. 106 105 * 107 * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change108 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>106 * 3. BSD Advertising Clause omitted per the July 22, 1999 licensing change 107 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change 109 108 * 110 109 * 4. Neither the name of the University nor the names of its contributors … … 124 123 * SUCH DAMAGE. 125 124 */ 126 127
Note:
See TracChangeset
for help on using the changeset viewer.