public inbox for newlib-cvs@sourceware.org help / color / mirror / Atom feed
From: Jeff Johnston <jjohnstn@sourceware.org> To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Fix newlib functions perror()/psignal() not to use writev(). Date: Thu, 05 Jul 2018 19:34:00 -0000 [thread overview] Message-ID: <20180705193410.12518.qmail@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=6a3e08a53ec996b37639a18dc98123e23531409c commit 6a3e08a53ec996b37639a18dc98123e23531409c Author: Takashi Yano <takashi.yano@nifty.ne.jp> Date: Thu Jul 5 23:01:26 2018 +0900 Fix newlib functions perror()/psignal() not to use writev(). This fix is for some platforms which do not have writev(). *perror.c: Use _write_r() instead of writev(). *psignal.c: Use write() insetad of writev(). Revise commit: d4f4e7ae1be1bcf8c021f2b0865aafc16b338aa3 Diff: --- newlib/libc/signal/psignal.c | 36 ++++++++++++++++++------------------ newlib/libc/stdio/perror.c | 40 +++++++++++++++++++++------------------- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/newlib/libc/signal/psignal.c b/newlib/libc/signal/psignal.c index 9a58486..f847ab2 100644 --- a/newlib/libc/signal/psignal.c +++ b/newlib/libc/signal/psignal.c @@ -32,37 +32,37 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, #include <_ansi.h> #include <stdio.h> #include <string.h> -#include <sys/uio.h> +#include <unistd.h> -#define ADD(str) \ +#define WRITE_STR(str) \ { \ - v->iov_base = (void *)(str); \ - v->iov_len = strlen (v->iov_base); \ - v ++; \ - iov_cnt ++; \ + const char *p = (str); \ + size_t len = strlen (p); \ + while (len) \ + { \ + ssize_t len1 = write (fileno (stderr), p, len); \ + if (len1 < 0) \ + break; \ + len -= len1; \ + p += len1; \ + } \ } void psignal (int sig, const char *s) { - struct iovec iov[4]; - struct iovec *v = iov; - int iov_cnt = 0; - + fflush (stderr); if (s != NULL && *s != '\0') { - ADD (s); - ADD (": "); + WRITE_STR (s); + WRITE_STR (": "); } - ADD (strsignal (sig)); + WRITE_STR (strsignal (sig)); #ifdef __SCLE - ADD ((stderr->_flags & __SCLE) ? "\r\n" : "\n"); + WRITE_STR ((stderr->_flags & __SCLE) ? "\r\n" : "\n"); #else - ADD ("\n"); + WRITE_STR ("\n"); #endif - - fflush (stderr); - writev (fileno (stderr), iov, iov_cnt); } diff --git a/newlib/libc/stdio/perror.c b/newlib/libc/stdio/perror.c index 831c67e..68d78c2 100644 --- a/newlib/libc/stdio/perror.c +++ b/newlib/libc/stdio/perror.c @@ -56,15 +56,20 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, #include <reent.h> #include <stdio.h> #include <string.h> -#include <sys/uio.h> #include "local.h" -#define ADD(str) \ +#define WRITE_STR(str) \ { \ - v->iov_base = (void *)(str); \ - v->iov_len = strlen (v->iov_base); \ - v ++; \ - iov_cnt ++; \ + const char *p = (str); \ + size_t len = strlen (p); \ + while (len) \ + { \ + ssize_t len1 = _write_r (ptr, fileno (fp), p, len); \ + if (len1 < 0) \ + break; \ + len -= len1; \ + p += len1; \ + } \ } void @@ -73,31 +78,28 @@ _perror_r (struct _reent *ptr, { char *error; int dummy; - struct iovec iov[4]; - struct iovec *v = iov; - int iov_cnt = 0; FILE *fp = _stderr_r (ptr); CHECK_INIT (ptr, fp); + + _newlib_flockfile_start(fp); + _fflush_r (ptr, fp); if (s != NULL && *s != '\0') { - ADD (s); - ADD (": "); + WRITE_STR (s); + WRITE_STR (": "); } if ((error = _strerror_r (ptr, ptr->_errno, 1, &dummy)) != NULL) - ADD (error); + WRITE_STR (error); #ifdef __SCLE - ADD ((fp->_flags & __SCLE) ? "\r\n" : "\n"); + WRITE_STR ((fp->_flags & __SCLE) ? "\r\n" : "\n"); #else - ADD ("\n"); + WRITE_STR ("\n"); #endif - - _newlib_flockfile_start (fp); - fflush (fp); - writev (fileno (fp), iov, iov_cnt); - _newlib_flockfile_end (fp); + fp->_flags &= ~__SOFF; + _newlib_flockfile_end(fp); } #ifndef _REENT_ONLY
reply other threads:[~2018-07-05 19:34 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180705193410.12518.qmail@sourceware.org \ --to=jjohnstn@sourceware.org \ --cc=newlib-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).