diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-05 21:10:53 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-05 21:10:53 +0000 |
commit | 01c27fc5ac89b07821a5430880d771e3c993c1c1 (patch) | |
tree | 818dc4f8d44b4986c1c41d72b054c035e605b503 | |
parent | a3310527db919eeffcd106324fedf41c04b71707 (diff) | |
download | busybox-w32-01c27fc5ac89b07821a5430880d771e3c993c1c1.tar.gz busybox-w32-01c27fc5ac89b07821a5430880d771e3c993c1c1.tar.bz2 busybox-w32-01c27fc5ac89b07821a5430880d771e3c993c1c1.zip |
which: -84 bytes
-rw-r--r-- | applets/busybox.c | 8 | ||||
-rw-r--r-- | debianutils/which.c | 69 |
2 files changed, 27 insertions, 50 deletions
diff --git a/applets/busybox.c b/applets/busybox.c index 625a492f2..9f2eddebd 100644 --- a/applets/busybox.c +++ b/applets/busybox.c | |||
@@ -116,12 +116,12 @@ int busybox_main(int argc, char **argv) | |||
116 | /* Obtain the terminal width. */ | 116 | /* Obtain the terminal width. */ |
117 | get_terminal_width_height(0, &output_width, NULL); | 117 | get_terminal_width_height(0, &output_width, NULL); |
118 | /* leading tab and room to wrap */ | 118 | /* leading tab and room to wrap */ |
119 | output_width -= 20; | 119 | output_width -= sizeof("start-stop-daemon, ") + 8; |
120 | } else output_width = 60; | 120 | } else output_width = 80 - sizeof("start-stop-daemon, ") - 8; |
121 | 121 | ||
122 | printf("%s\n" | 122 | printf("%s\n" |
123 | "Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others.\n" | 123 | "Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others.\n" |
124 | "Licensed under GPLv2. See source distribution for full notice.\n\n" | 124 | "Licensed under GPLv2. See source distribution for full notice.\n\n" |
125 | "Usage: busybox [function] [arguments]...\n" | 125 | "Usage: busybox [function] [arguments]...\n" |
126 | " or: [function] [arguments]...\n\n" | 126 | " or: [function] [arguments]...\n\n" |
127 | "\tBusyBox is a multi-call binary that combines many common Unix\n" | 127 | "\tBusyBox is a multi-call binary that combines many common Unix\n" |
diff --git a/debianutils/which.c b/debianutils/which.c index db28f7803..583d94613 100644 --- a/debianutils/which.c +++ b/debianutils/which.c | |||
@@ -26,43 +26,20 @@ int which_main(int argc, char **argv) | |||
26 | { | 26 | { |
27 | int status; | 27 | int status; |
28 | size_t i, count; | 28 | size_t i, count; |
29 | char *path_list; | 29 | char *path_list, *p; |
30 | 30 | ||
31 | if (argc <= 1 || **(argv + 1) == '-') { | 31 | if (argc <= 1 || argv[1][0] == '-') { |
32 | bb_show_usage(); | 32 | bb_show_usage(); |
33 | } | 33 | } |
34 | argc--; | 34 | argc--; |
35 | 35 | ||
36 | path_list = getenv("PATH"); | 36 | path_list = getenv("PATH"); |
37 | if (path_list != NULL) { | 37 | if (path_list != NULL) { |
38 | size_t path_len = strlen(path_list); | ||
39 | char *new_list = NULL; | ||
40 | count = 1; | 38 | count = 1; |
41 | 39 | p = path_list; | |
42 | for (i = 0; i <= path_len; i++) { | 40 | while ((p = strchr(p, ':')) != NULL) { |
43 | char *this_i = &path_list[i]; | 41 | *p++ = 0; |
44 | if (*this_i == ':') { | 42 | count++; |
45 | /* ^::[^:] == \.: */ | ||
46 | if (!i && (*(this_i + 1) == ':')) { | ||
47 | *this_i = '.'; | ||
48 | continue; | ||
49 | } | ||
50 | *this_i = 0; | ||
51 | count++; | ||
52 | /* ^:[^:] == \.0 and [^:]::[^:] == 0\.0 and [^:]:$ == 0\.0 */ | ||
53 | if (!i || (*(this_i + 1) == ':') || (i == path_len-1)) { | ||
54 | new_list = xrealloc(new_list, path_len += 1); | ||
55 | if (i) { | ||
56 | memmove(&new_list[i+2], &path_list[i+1], path_len-i); | ||
57 | new_list[i+1] = '.'; | ||
58 | memmove(new_list, path_list, i); | ||
59 | } else { | ||
60 | memmove(&new_list[i+1], &path_list[i], path_len-i); | ||
61 | new_list[i] = '.'; | ||
62 | } | ||
63 | path_list = new_list; | ||
64 | } | ||
65 | } | ||
66 | } | 43 | } |
67 | } else { | 44 | } else { |
68 | path_list = "/bin\0/sbin\0/usr/bin\0/usr/sbin\0/usr/local/bin"; | 45 | path_list = "/bin\0/sbin\0/usr/bin\0/usr/sbin\0/usr/local/bin"; |
@@ -73,34 +50,34 @@ int which_main(int argc, char **argv) | |||
73 | while (argc-- > 0) { | 50 | while (argc-- > 0) { |
74 | struct stat stat_b; | 51 | struct stat stat_b; |
75 | char *buf; | 52 | char *buf; |
76 | char *path_n; | ||
77 | int found = 0; | ||
78 | 53 | ||
79 | argv++; | 54 | argv++; |
80 | path_n = path_list; | 55 | buf = argv[0]; |
81 | buf = *argv; | ||
82 | 56 | ||
83 | /* if filename is either absolute or contains slashes, | 57 | /* If filename is either absolute or contains slashes, |
84 | * stat it */ | 58 | * stat it */ |
85 | if (strchr(buf, '/') != NULL && is_executable_file(buf, &stat_b)) { | 59 | if (strchr(buf, '/')) { |
86 | found++; | 60 | if (is_executable_file(buf, &stat_b)) { |
61 | puts(buf); | ||
62 | goto next; | ||
63 | } | ||
87 | } else { | 64 | } else { |
88 | /* Couldn't access file and file doesn't contain slashes */ | 65 | /* File doesn't contain slashes */ |
66 | p = path_list; | ||
89 | for (i = 0; i < count; i++) { | 67 | for (i = 0; i < count; i++) { |
90 | buf = concat_path_file(path_n, *argv); | 68 | /* Empty component in PATH is treated as . */ |
69 | buf = concat_path_file(p[0] ? p : ".", argv[0]); | ||
91 | if (is_executable_file(buf, &stat_b)) { | 70 | if (is_executable_file(buf, &stat_b)) { |
92 | found++; | 71 | puts(buf); |
93 | break; | 72 | free(buf); |
73 | goto next; | ||
94 | } | 74 | } |
95 | free(buf); | 75 | free(buf); |
96 | path_n += (strlen(path_n) + 1); | 76 | p += strlen(p) + 1; |
97 | } | 77 | } |
98 | } | 78 | } |
99 | if (found) { | 79 | status = EXIT_FAILURE; |
100 | puts(buf); | 80 | next: /* nothing */; |
101 | } else { | ||
102 | status = EXIT_FAILURE; | ||
103 | } | ||
104 | } | 81 | } |
105 | bb_fflush_stdout_and_exit(status); | 82 | bb_fflush_stdout_and_exit(status); |
106 | } | 83 | } |