diff options
author | Theodore Ts'o <tytso@mit.edu> | 2010-05-15 07:48:25 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2010-05-15 07:48:25 -0400 |
commit | 822c10e84e5f57394bcad921adc560f5b032c03e (patch) | |
tree | 41e5ef9b3ca4cebf6e953798994dd58c151c044c | |
parent | edc1894e60e9aef274408d322ada84729891a2f0 (diff) | |
download | e2fsprogs-822c10e84e5f57394bcad921adc560f5b032c03e.tar.gz |
libcom_err: Only output ^M when tty is in raw mode
This fixes a long-standing botch in the com_err library, and solves a
regression test problem for libss that gets tickled by source code
management systems (like Perforce) that don't preserve CRLF line
endings with fidelity.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r-- | lib/et/com_err.c | 24 | ||||
-rw-r--r-- | lib/ss/test_script_expected | 4 |
2 files changed, 24 insertions, 4 deletions
diff --git a/lib/et/com_err.c b/lib/et/com_err.c index d83d6a92..e5af13cd 100644 --- a/lib/et/com_err.c +++ b/lib/et/com_err.c @@ -12,6 +12,12 @@ */ #include <stdio.h> +#ifdef HAVE_TERMIOS_H +#include <termios.h> +#endif +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif #include "com_err.h" #include "error_table.h" #include "internal.h" @@ -25,6 +31,8 @@ static void default_com_err_proc (const char *whoami, errcode_t code, const char *fmt, va_list args) { + int do_cr = 1, fd = fileno(stderr); + if (whoami) { fputs(whoami, stderr); fputs(": ", stderr); @@ -36,8 +44,20 @@ default_com_err_proc (const char *whoami, errcode_t code, const if (fmt) { vfprintf (stderr, fmt, args); } - /* should output \r only if using a tty in raw mode */ - fputs("\r\n", stderr); + if (!isatty(fd)) + do_cr = 0; +#ifdef HAVE_TERMIOS_H + else { + struct termios t; + + if ((tcgetattr(fd, &t)) == 0 && + (t.c_oflag & OPOST) && (t.c_oflag & ONLCR)) + do_cr = 0; + } +#endif + if (do_cr) + fputc('\r', stderr); + fputc('\n', stderr); fflush(stderr); } diff --git a/lib/ss/test_script_expected b/lib/ss/test_script_expected index 3f61d9a5..543f8289 100644 --- a/lib/ss/test_script_expected +++ b/lib/ss/test_script_expected @@ -10,9 +10,9 @@ test_icount: test bar quux Hello, world! Args: 'bar', 'quux' test_icount: quux bar -test_ss: Command not found quux
+test_ss: Command not found quux test_icount: quux -test_ss: Command not found quux
+test_ss: Command not found quux test_icount: test quux Hello, world! Args: 'quux' |