Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/coreutils/env.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/coreutils/env.c
r821 r1770 6 6 * The Regents of the University of California. All rights reserved. 7 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 21 9 * 22 10 * Original copyright notice is retained at the end of this file. … … 39 27 * - multiple "-u unsetenv" support 40 28 * - GNU long option support 41 * - use bb_default_error_retval29 * - use xfunc_error_retval 42 30 */ 43 31 32 #include <getopt.h> /* struct option */ 33 extern char **environ; 44 34 45 #include <stdio.h> 46 #include <string.h> 47 #include <stdlib.h> 48 #include <errno.h> 49 #include <unistd.h> 50 #include <getopt.h> /* struct option */ 51 #include "busybox.h" 35 #include "libbb.h" 52 36 53 37 #if ENABLE_FEATURE_ENV_LONG_OPTIONS 54 static const struct option env_long_options[] = { 55 { "ignore-environment", 0, NULL, 'i' }, 56 { "unset", 1, NULL, 'u' }, 57 { 0, 0, 0, 0 } 58 }; 38 static const char env_longopts[] ALIGN1 = 39 "ignore-environment\0" No_argument "i" 40 "unset\0" Required_argument "u" 41 ; 59 42 #endif 60 43 44 int env_main(int argc, char** argv); 61 45 int env_main(int argc, char** argv) 62 46 { 63 static char *cleanenv[1] = { NULL }; 47 /* cleanenv was static - why? */ 48 char *cleanenv[1]; 49 char **ep; 50 unsigned opt; 51 llist_t *unset_env = NULL; 64 52 65 char **ep, *p; 66 unsigned long opt; 67 llist_t *unset_env = NULL; 68 extern char **environ; 69 70 bb_opt_complementally = "u::"; 53 opt_complementary = "u::"; 71 54 #if ENABLE_FEATURE_ENV_LONG_OPTIONS 72 bb_applet_long_options = env_long_options;55 applet_long_options = env_longopts; 73 56 #endif 74 75 opt = bb_getopt_ulflags(argc, argv, "+iu:", &unset_env); 76 57 opt = getopt32(argv, "+iu:", &unset_env); 77 58 argv += optind; 78 if (*argv && (argv[0][0] == '-') && !argv[0][1]) {59 if (*argv && LONE_DASH(argv[0])) { 79 60 opt |= 1; 80 61 ++argv; 81 62 } 82 83 if(opt & 1)63 if (opt & 1) { 64 cleanenv[0] = NULL; 84 65 environ = cleanenv; 85 else if(opt & 2){86 while (unset_env) {66 } else { 67 while (unset_env) { 87 68 unsetenv(unset_env->data); 88 69 unset_env = unset_env->link; … … 90 71 } 91 72 92 while (*argv && ( (p = strchr(*argv, '=')) != NULL)) {73 while (*argv && (strchr(*argv, '=') != NULL)) { 93 74 if (putenv(*argv) < 0) { 94 75 bb_perror_msg_and_die("putenv"); … … 98 79 99 80 if (*argv) { 100 execvp(*argv, argv);81 BB_EXECVP(*argv, argv); 101 82 /* SUSv3-mandated exit codes. */ 102 bb_default_error_retval = (errno == ENOENT) ? 127 : 126;83 xfunc_error_retval = (errno == ENOENT) ? 127 : 126; 103 84 bb_perror_msg_and_die("%s", *argv); 104 85 } … … 108 89 } 109 90 110 bb_fflush_stdout_and_exit(0);91 fflush_stdout_and_exit(0); 111 92 } 112 93
Note:
See TracChangeset
for help on using the changeset viewer.