diff options
author | Ron Yorston <rmy@pobox.com> | 2024-04-09 09:51:48 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2024-09-27 19:52:25 +0200 |
commit | dbd14c4a42454b61a5474f6243865a6ec113e60b (patch) | |
tree | cbc5ed7b93192e30fb11424e4b36680f32c1533e /libbb/appletlib.c | |
parent | 2c232f1e60fc42230c4e14bc7c548ac0e6593173 (diff) | |
download | busybox-w32-dbd14c4a42454b61a5474f6243865a6ec113e60b.tar.gz busybox-w32-dbd14c4a42454b61a5474f6243865a6ec113e60b.tar.bz2 busybox-w32-dbd14c4a42454b61a5474f6243865a6ec113e60b.zip |
libbb: send usage messages to correct stream
POSIX generally requires normal output to go to stdout and
diagnostic (i.e. error) output to go to stderr.
When usage messages for BusyBox applets are specifically requested
by the user (e.g. 'find --help') they should go to stdout; when
they're emitted due to an error they should go to stderr.
function old new delta
bb_show_usage 148 146 -2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-2) Total: -2 bytes
Signed-off-by: Avi Halachmi <avihpit@yahoo.com>
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r-- | libbb/appletlib.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index ad373ae1c..d2e5900b5 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -127,17 +127,19 @@ static const char packed_usage[] ALIGN1 = { PACKED_USAGE }; | |||
127 | void FAST_FUNC bb_show_usage(void) | 127 | void FAST_FUNC bb_show_usage(void) |
128 | { | 128 | { |
129 | if (ENABLE_SHOW_USAGE) { | 129 | if (ENABLE_SHOW_USAGE) { |
130 | ssize_t FAST_FUNC (*full_write_fn)(const char *) = | ||
131 | xfunc_error_retval ? full_write2_str : full_write1_str; | ||
130 | #ifdef SINGLE_APPLET_STR | 132 | #ifdef SINGLE_APPLET_STR |
131 | /* Imagine that this applet is "true". Dont link in printf! */ | 133 | /* Imagine that this applet is "true". Dont link in printf! */ |
132 | const char *usage_string = unpack_usage_messages(); | 134 | const char *usage_string = unpack_usage_messages(); |
133 | 135 | ||
134 | if (usage_string) { | 136 | if (usage_string) { |
135 | if (*usage_string == '\b') { | 137 | if (*usage_string == '\b') { |
136 | full_write2_str("No help available\n"); | 138 | full_write_fn("No help available\n"); |
137 | } else { | 139 | } else { |
138 | full_write2_str("Usage: "SINGLE_APPLET_STR" "); | 140 | full_write_fn("Usage: "SINGLE_APPLET_STR" "); |
139 | full_write2_str(usage_string); | 141 | full_write_fn(usage_string); |
140 | full_write2_str("\n"); | 142 | full_write_fn("\n"); |
141 | } | 143 | } |
142 | if (ENABLE_FEATURE_CLEAN_UP) | 144 | if (ENABLE_FEATURE_CLEAN_UP) |
143 | dealloc_usage_messages((char*)usage_string); | 145 | dealloc_usage_messages((char*)usage_string); |
@@ -153,19 +155,19 @@ void FAST_FUNC bb_show_usage(void) | |||
153 | while (*p++) continue; | 155 | while (*p++) continue; |
154 | ap--; | 156 | ap--; |
155 | } | 157 | } |
156 | full_write2_str(bb_banner); | 158 | full_write_fn(bb_banner); |
157 | full_write2_str(" multi-call binary.\n"); /* common string */ | 159 | full_write_fn(" multi-call binary.\n"); /* common string */ |
158 | if (*p == '\b') | 160 | if (*p == '\b') |
159 | full_write2_str("\nNo help available\n"); | 161 | full_write_fn("\nNo help available\n"); |
160 | else { | 162 | else { |
161 | full_write2_str("\nUsage: "); | 163 | full_write_fn("\nUsage: "); |
162 | full_write2_str(applet_name); | 164 | full_write_fn(applet_name); |
163 | if (p[0]) { | 165 | if (p[0]) { |
164 | if (p[0] != '\n') | 166 | if (p[0] != '\n') |
165 | full_write2_str(" "); | 167 | full_write_fn(" "); |
166 | full_write2_str(p); | 168 | full_write_fn(p); |
167 | } | 169 | } |
168 | full_write2_str("\n"); | 170 | full_write_fn("\n"); |
169 | } | 171 | } |
170 | if (ENABLE_FEATURE_CLEAN_UP) | 172 | if (ENABLE_FEATURE_CLEAN_UP) |
171 | dealloc_usage_messages((char*)usage_string); | 173 | dealloc_usage_messages((char*)usage_string); |
@@ -268,8 +270,10 @@ void lbb_prepare(const char *applet | |||
268 | && !(ENABLE_TRUE && strcmp(applet_name, "true") == 0) | 270 | && !(ENABLE_TRUE && strcmp(applet_name, "true") == 0) |
269 | && !(ENABLE_FALSE && strcmp(applet_name, "false") == 0) | 271 | && !(ENABLE_FALSE && strcmp(applet_name, "false") == 0) |
270 | && !(ENABLE_ECHO && strcmp(applet_name, "echo") == 0) | 272 | && !(ENABLE_ECHO && strcmp(applet_name, "echo") == 0) |
271 | ) | 273 | ) { |
274 | xfunc_error_retval = 0; | ||
272 | bb_show_usage(); | 275 | bb_show_usage(); |
276 | } | ||
273 | } | 277 | } |
274 | #endif | 278 | #endif |
275 | } | 279 | } |