Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/debianutils/which.c

    r3232 r3621  
    11/* vi: set sw=4 ts=4: */
    22/*
    3  * Which implementation for busybox
    4  *
    53 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
    64 * Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu>
    75 *
    86 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    9  *
    10  * Based on which from debianutils
    117 */
     8//config:config WHICH
     9//config:   bool "which"
     10//config:   default y
     11//config:   help
     12//config:     which is used to find programs in your PATH and
     13//config:     print out their pathnames.
     14
     15//applet:IF_WHICH(APPLET(which, BB_DIR_USR_BIN, BB_SUID_DROP))
     16
     17//kbuild:lib-$(CONFIG_WHICH) += which.o
    1218
    1319//usage:#define which_trivial_usage
     
    2531int which_main(int argc UNUSED_PARAM, char **argv)
    2632{
    27     IF_DESKTOP(int opt;)
    28     int status = EXIT_SUCCESS;
    29     char *path;
    30     char *p;
     33    const char *env_path;
     34    int status = 0;
     35
     36    env_path = getenv("PATH");
     37    if (!env_path)
     38        env_path = bb_default_root_path;
    3139
    3240    opt_complementary = "-1"; /* at least one argument */
    33     IF_DESKTOP(opt =) getopt32(argv, "a");
     41    getopt32(argv, "a");
    3442    argv += optind;
    3543
    36     /* This matches what is seen on e.g. ubuntu.
    37      * "which" there is a shell script. */
    38     path = getenv("PATH");
    39     if (!path) {
    40         path = (char*)bb_PATH_root_path;
    41         putenv(path);
    42         path += 5; /* skip "PATH=" */
    43     }
     44    do {
     45        int missing = 1;
    4446
    45     do {
    46 #if ENABLE_DESKTOP
    47 /* Much bloat just to support -a */
     47        /* If file contains a slash don't use PATH */
    4848        if (strchr(*argv, '/')) {
    49             if (execable_file(*argv)) {
     49            if (file_is_executable(*argv)) {
     50                missing = 0;
    5051                puts(*argv);
    51                 continue;
    5252            }
    53             status = EXIT_FAILURE;
    5453        } else {
    55             char *path2 = xstrdup(path);
    56             char *tmp = path2;
     54            char *path;
     55            char *tmp;
     56            char *p;
    5757
    58             p = find_execable(*argv, &tmp);
    59             if (!p)
    60                 status = EXIT_FAILURE;
    61             else {
    62  print:
     58            path = tmp = xstrdup(env_path);
     59            while ((p = find_executable(*argv, &tmp)) != NULL) {
     60                missing = 0;
    6361                puts(p);
    6462                free(p);
    65                 if (opt) {
    66                     /* -a: show matches in all PATH components */
    67                     if (tmp) {
    68                         p = find_execable(*argv, &tmp);
    69                         if (p)
    70                             goto print;
    71                     }
    72                 }
     63                if (!option_mask32) /* -a not set */
     64                    break;
    7365            }
    74             free(path2);
     66            free(path);
    7567        }
    76 #else
    77 /* Just ignoring -a */
    78         if (strchr(*argv, '/')) {
    79             if (execable_file(*argv)) {
    80                 puts(*argv);
    81                 continue;
    82             }
    83         } else {
    84             char *path2 = xstrdup(path);
    85             char *tmp = path2;
    86             p = find_execable(*argv, &tmp);
    87             free(path2);
    88             if (p) {
    89                 puts(p);
    90                 free(p);
    91                 continue;
    92             }
    93         }
    94         status = EXIT_FAILURE;
    95 #endif
    96     } while (*(++argv) != NULL);
     68        status |= missing;
     69    } while (*++argv);
    9770
    98     fflush_stdout_and_exit(status);
     71    return status;
    9972}
Note: See TracChangeset for help on using the changeset viewer.