aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-04-02 15:09:47 +0100
committerRon Yorston <rmy@pobox.com>2012-04-02 15:09:47 +0100
commita65c74c163aeccd6bd202954b73bce6142534628 (patch)
tree3fb9c15764b6357c7b9f8a8836f6a69355fdd0aa
parent0ebbd36f808f10b302bef468b71564b8d7b333ec (diff)
downloadbusybox-w32-a65c74c163aeccd6bd202954b73bce6142534628.tar.gz
busybox-w32-a65c74c163aeccd6bd202954b73bce6142534628.tar.bz2
busybox-w32-a65c74c163aeccd6bd202954b73bce6142534628.zip
which: report use of applets in sh standalone mode
-rw-r--r--debianutils/which.c69
1 files changed, 41 insertions, 28 deletions
diff --git a/debianutils/which.c b/debianutils/which.c
index 6e92901bc..72d18332b 100644
--- a/debianutils/which.c
+++ b/debianutils/which.c
@@ -21,6 +21,29 @@
21 21
22#include "libbb.h" 22#include "libbb.h"
23 23
24#if ENABLE_PLATFORM_MINGW32
25static char *win32_execable_file(const char *p)
26{
27 char *path;
28 int len = strlen(p) + 5;
29
30 if ( (path=malloc(len)) != NULL ) {
31 memcpy(path, p, len);
32 memcpy(path+len, ".exe", 5);
33 if (execable_file(path)) {
34 return path;
35 }
36 memcpy(path+len, ".com", 5);
37 if (execable_file(path)) {
38 return path;
39 }
40 free(path);
41 }
42
43 return NULL;
44}
45#endif
46
24int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 47int which_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
25int which_main(int argc UNUSED_PARAM, char **argv) 48int which_main(int argc UNUSED_PARAM, char **argv)
26{ 49{
@@ -43,6 +66,14 @@ int which_main(int argc UNUSED_PARAM, char **argv)
43 } 66 }
44 67
45 do { 68 do {
69#if ENABLE_FEATURE_SH_STANDALONE
70 if ( find_applet_by_name(*argv) >= 0 ) {
71 puts(*argv);
72 IF_DESKTOP(if ( !opt ))
73 continue;
74 }
75#endif
76
46#if ENABLE_DESKTOP 77#if ENABLE_DESKTOP
47/* Much bloat just to support -a */ 78/* Much bloat just to support -a */
48 if (strchr(*argv, '/') || (ENABLE_PLATFORM_MINGW32 && strchr(*argv, '\\'))) { 79 if (strchr(*argv, '/') || (ENABLE_PLATFORM_MINGW32 && strchr(*argv, '\\'))) {
@@ -50,20 +81,11 @@ int which_main(int argc UNUSED_PARAM, char **argv)
50 puts(*argv); 81 puts(*argv);
51 continue; 82 continue;
52 } 83 }
53 else if (ENABLE_PLATFORM_MINGW32) { 84 else if (ENABLE_PLATFORM_MINGW32 &&
54 char path[PATH_MAX]; 85 (p=win32_execable_file(*argv)) != NULL) {
55 int len = strlen(*argv); 86 puts(p);
56 memcpy(path, *argv, len); 87 free(p);
57 memcpy(path+len, ".exe", 5); 88 continue;
58 if (execable_file(path)) {
59 puts(path);
60 continue;
61 }
62 memcpy(path+len, ".com", 5);
63 if (execable_file(path)) {
64 puts(path);
65 continue;
66 }
67 } 89 }
68 status = EXIT_FAILURE; 90 status = EXIT_FAILURE;
69 } else { 91 } else {
@@ -95,20 +117,11 @@ int which_main(int argc UNUSED_PARAM, char **argv)
95 puts(*argv); 117 puts(*argv);
96 continue; 118 continue;
97 } 119 }
98 else if (ENABLE_PLATFORM_MINGW32) { 120 else if (ENABLE_PLATFORM_MINGW32 &&
99 char path[PATH_MAX]; 121 (p=win32_execable_file(*argv)) != NULL) {
100 int len = strlen(*argv); 122 puts(p);
101 memcpy(path, *argv, len); 123 free(p);
102 memcpy(path+len, ".exe", 5); 124 continue;
103 if (execable_file(path)) {
104 puts(path);
105 continue;
106 }
107 memcpy(path+len, ".com", 5);
108 if (execable_file(path)) {
109 puts(path);
110 continue;
111 }
112 } 125 }
113 } else { 126 } else {
114 char *path2 = xstrdup(path); 127 char *path2 = xstrdup(path);