diff options
author | Takashi Yano <takashi.yano@nifty.ne.jp> | 2018-07-03 19:09:48 +0900 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2018-07-03 15:38:47 +0200 |
commit | 1c1cec9cdff8e71deabb896081215b58ca8b16b6 (patch) | |
tree | 87e4da9572a807f1661e75ea5895fa7956818fe5 /winsup/cygwin | |
parent | 3127effc6710e6233cf5b533a38e129610143242 (diff) | |
download | newlib-1c1cec9cdff8e71deabb896081215b58ca8b16b6.zip newlib-1c1cec9cdff8e71deabb896081215b58ca8b16b6.tar.gz newlib-1c1cec9cdff8e71deabb896081215b58ca8b16b6.tar.bz2 |
Fix a bug of psiginfo() that changes the orientation of stderr.
* strsig.cc (psiginfo): Fix the problem that psiginfo() changes
the orientation of stderr to byte-oriented mode if stderr is
not oriented yet.
Diffstat (limited to 'winsup/cygwin')
-rw-r--r-- | winsup/cygwin/strsig.cc | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/winsup/cygwin/strsig.cc b/winsup/cygwin/strsig.cc index 6501c27..6c7bdd3 100644 --- a/winsup/cygwin/strsig.cc +++ b/winsup/cygwin/strsig.cc @@ -10,6 +10,7 @@ details. */ #include <cygtls.h> #include <stdio.h> #include <string.h> +#include <sys/uio.h> struct sigdesc { @@ -149,13 +150,29 @@ strtosigno (const char *name) return 0; } +#define ADD(str) \ +{ \ + v->iov_base = (void *)(str); \ + v->iov_len = strlen ((char *)v->iov_base); \ + v ++; \ + iov_cnt ++; \ +} + extern "C" void psiginfo (const siginfo_t *info, const char *s) { + struct iovec iov[5]; + struct iovec *v = iov; + int iov_cnt = 0; + char buf[64]; + if (s != NULL && *s != '\0') - fprintf (stderr, "%s: ", s); + { + ADD (s); + ADD (": "); + } - fprintf (stderr, "%s", strsignal (info->si_signo)); + ADD (strsignal (info->si_signo)); if (info->si_signo > 0 && info->si_signo < NSIG) { @@ -165,10 +182,12 @@ psiginfo (const siginfo_t *info, const char *s) case SIGBUS: case SIGFPE: case SIGSEGV: - fprintf (stderr, " (%d [%p])", info->si_code, info->si_addr); + snprintf (buf, sizeof(buf), + " (%d [%p])", info->si_code, info->si_addr); break; case SIGCHLD: - fprintf (stderr, " (%d %d %d %u)", info->si_code, info->si_pid, + snprintf (buf, sizeof(buf), + " (%d %d %d %u)", info->si_code, info->si_pid, info->si_status, info->si_uid); break; /* FIXME: implement si_band @@ -177,9 +196,19 @@ psiginfo (const siginfo_t *info, const char *s) break; */ default: - fprintf (stderr, " (%d %d %u)", info->si_code, info->si_pid, info->si_uid); + snprintf (buf, sizeof(buf), + " (%d %d %u)", info->si_code, info->si_pid, + info->si_uid); } + ADD (buf); } - fprintf (stderr, "\n"); +#ifdef __SCLE + ADD ((stderr->_flags & __SCLE) ? "\r\n" : "\n"); +#else + ADD ("\n"); +#endif + + fflush (stderr); + writev (fileno (stderr), iov, iov_cnt); } |