Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

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

    r1765 r2725  
    66 * Copyright (C) 2006 Gabriel Somlo <somlo at cmu.edu>
    77 *
    8  * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
     8 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    99 *
    1010 * Based on which from debianutils
     
    1313#include "libbb.h"
    1414
    15 int which_main(int argc, char **argv);
    16 int which_main(int argc, char **argv)
     15int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     16int which_main(int argc UNUSED_PARAM, char **argv)
    1717{
     18    IF_DESKTOP(int opt;)
    1819    int status = EXIT_SUCCESS;
     20    char *path;
    1921    char *p;
    2022
    21     if (argc <= 1 || argv[1][0] == '-') {
    22         bb_show_usage();
     23    opt_complementary = "-1"; /* at least one argument */
     24    IF_DESKTOP(opt =) getopt32(argv, "a");
     25    argv += optind;
     26
     27    /* This matches what is seen on e.g. ubuntu.
     28     * "which" there is a shell script. */
     29    path = getenv("PATH");
     30    if (!path) {
     31        path = (char*)bb_PATH_root_path;
     32        putenv(path);
     33        path += 5; /* skip "PATH=" */
    2334    }
    2435
    25 /* We shouldn't do this. Ever. Not our business.
    26     if (!getenv("PATH")) {
    27         putenv((char*)bb_PATH_root_path);
    28     }
    29 */
     36    do {
     37#if ENABLE_DESKTOP
     38/* Much bloat just to support -a */
     39        if (strchr(*argv, '/')) {
     40            if (execable_file(*argv)) {
     41                puts(*argv);
     42                continue;
     43            }
     44            status = EXIT_FAILURE;
     45        } else {
     46            char *path2 = xstrdup(path);
     47            char *tmp = path2;
    3048
    31     while (--argc > 0) {
    32         argv++;
     49            p = find_execable(*argv, &tmp);
     50            if (!p)
     51                status = EXIT_FAILURE;
     52            else {
     53 print:
     54                puts(p);
     55                free(p);
     56                if (opt) {
     57                    /* -a: show matches in all PATH components */
     58                    if (tmp) {
     59                        p = find_execable(*argv, &tmp);
     60                        if (p)
     61                            goto print;
     62                    }
     63                }
     64            }
     65            free(path2);
     66        }
     67#else
     68/* Just ignoring -a */
    3369        if (strchr(*argv, '/')) {
    3470            if (execable_file(*argv)) {
     
    3773            }
    3874        } else {
    39             p = find_execable(*argv);
     75            char *path2 = xstrdup(path);
     76            char *tmp = path2;
     77            p = find_execable(*argv, &tmp);
     78            free(path2);
    4079            if (p) {
    4180                puts(p);
     
    4584        }
    4685        status = EXIT_FAILURE;
    47     }
     86#endif
     87    } while (*(++argv) != NULL);
    4888
    4989    fflush_stdout_and_exit(status);
Note: See TracChangeset for help on using the changeset viewer.