Changeset 1765 in MondoRescue for branches/2.2.5/mindi-busybox/coreutils/env.c


Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/coreutils/env.c

    r821 r1765  
    66 *  The Regents of the University of California.  All rights reserved.
    77 *
    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.
    219 *
    2210 * Original copyright notice is retained at the end of this file.
     
    3927 * - multiple "-u unsetenv" support
    4028 * - GNU long option support
    41  * - use bb_default_error_retval
     29 * - use xfunc_error_retval
    4230 */
    4331
     32#include <getopt.h> /* struct option */
     33extern char **environ;
    4434
    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"
    5236
    5337#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 };
     38static const char env_longopts[] ALIGN1 =
     39    "ignore-environment\0" No_argument       "i"
     40    "unset\0"              Required_argument "u"
     41    ;
    5942#endif
    6043
     44int env_main(int argc, char** argv);
    6145int env_main(int argc, char** argv)
    6246{
    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;
    6452
    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::";
    7154#if ENABLE_FEATURE_ENV_LONG_OPTIONS
    72     bb_applet_long_options = env_long_options;
     55    applet_long_options = env_longopts;
    7356#endif
    74 
    75     opt = bb_getopt_ulflags(argc, argv, "+iu:", &unset_env);
    76 
     57    opt = getopt32(argv, "+iu:", &unset_env);
    7758    argv += optind;
    78     if (*argv && (argv[0][0] == '-') && !argv[0][1]) {
     59    if (*argv && LONE_DASH(argv[0])) {
    7960        opt |= 1;
    8061        ++argv;
    8162    }
    82 
    83     if(opt & 1)
     63    if (opt & 1) {
     64        cleanenv[0] = NULL;
    8465        environ = cleanenv;
    85     else if(opt & 2) {
    86         while(unset_env) {
     66    } else {
     67        while (unset_env) {
    8768            unsetenv(unset_env->data);
    8869            unset_env = unset_env->link;
     
    9071    }
    9172
    92     while (*argv && ((p = strchr(*argv, '=')) != NULL)) {
     73    while (*argv && (strchr(*argv, '=') != NULL)) {
    9374        if (putenv(*argv) < 0) {
    9475            bb_perror_msg_and_die("putenv");
     
    9879
    9980    if (*argv) {
    100         execvp(*argv, argv);
     81        BB_EXECVP(*argv, argv);
    10182        /* SUSv3-mandated exit codes. */
    102         bb_default_error_retval = (errno == ENOENT) ? 127 : 126;
     83        xfunc_error_retval = (errno == ENOENT) ? 127 : 126;
    10384        bb_perror_msg_and_die("%s", *argv);
    10485    }
     
    10889    }
    10990
    110     bb_fflush_stdout_and_exit(0);
     91    fflush_stdout_and_exit(0);
    11192}
    11293
Note: See TracChangeset for help on using the changeset viewer.