diff options
author | Ron Yorston <rmy@pobox.com> | 2024-09-30 15:20:54 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2024-09-30 16:08:42 +0100 |
commit | 4be93f32f5bd5ccaac343b4d03fb861a02d6de96 (patch) | |
tree | 32692c33609484e03f9b22ae260c1a6e05a6b96c /libbb/xfuncs.c | |
parent | 431e2704c17d5c0e51a0cbebfb1105bd4962b3f7 (diff) | |
download | busybox-w32-4be93f32f5bd5ccaac343b4d03fb861a02d6de96.tar.gz busybox-w32-4be93f32f5bd5ccaac343b4d03fb861a02d6de96.tar.bz2 busybox-w32-4be93f32f5bd5ccaac343b4d03fb861a02d6de96.zip |
win32: work around problem with stderr in MSVCRT
Try to run a non-existent command with standard error closed:
xyz 2>&-
In recent versions of busybox-w32 this resulted in problems with
moving through history (either using up/down keys or ctrl-r) and
tab completion. In all cases the order of the prompt and the
command were reversed.
Bisection showed the problem was first seen in PRE-5396 which
merged some commits from upstream, including fd47f0567 (lineedit:
print prompt and editing operations to stderr).
This (eventually) called to mind a previous problem with stderr
in xargs which was fixed by commit f192e6539 (xargs: fix 'xargs
-sNUM' tests). In both cases it seemed that mixing calls to
bb_putchar_stderr() and fprintf(stderr, ...) was at fault. The
former uses a file descriptor while the latter uses a stream. It
was almost as if the stream was buffered.
- The problem with xargs affected 32-bit and 64-bit builds with
MSVCRT.
- The problem with '2>&-' only affected 32-bit builds with MSVCRT.
- Neither problem was present with UCRT builds.
As a workaround change bb_putchar_stderr() to use the stderr stream
in builds for MSVCRT.
Saves 16 bytes in the 32-bit build.
(GitHub issue #460)
Diffstat (limited to '')
-rw-r--r-- | libbb/xfuncs.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index c365fb8be..7df1a4cd3 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -221,7 +221,12 @@ off_t FAST_FUNC fdlength(int fd) | |||
221 | 221 | ||
222 | int FAST_FUNC bb_putchar_stderr(char ch) | 222 | int FAST_FUNC bb_putchar_stderr(char ch) |
223 | { | 223 | { |
224 | #if ENABLE_PLATFORM_MINGW32 && !defined(_UCRT) | ||
225 | // Workaround for problems with stderr in MSVCRT | ||
226 | return fputc(ch, stderr); | ||
227 | #else | ||
224 | return write(STDERR_FILENO, &ch, 1); | 228 | return write(STDERR_FILENO, &ch, 1); |
229 | #endif | ||
225 | } | 230 | } |
226 | 231 | ||
227 | ssize_t FAST_FUNC full_write1_str(const char *str) | 232 | ssize_t FAST_FUNC full_write1_str(const char *str) |