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: d4f4e7ae1b
This commit is contained in:
Takashi Yano 2018-07-05 23:01:26 +09:00 committed by Jeff Johnston
parent 0ce27ecd08
commit 6a3e08a53e
2 changed files with 39 additions and 37 deletions

View File

@ -32,37 +32,37 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
#include <_ansi.h> #include <_ansi.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/uio.h> #include <unistd.h>
#define ADD(str) \ #define WRITE_STR(str) \
{ \ { \
v->iov_base = (void *)(str); \ const char *p = (str); \
v->iov_len = strlen (v->iov_base); \ size_t len = strlen (p); \
v ++; \ while (len) \
iov_cnt ++; \ { \
ssize_t len1 = write (fileno (stderr), p, len); \
if (len1 < 0) \
break; \
len -= len1; \
p += len1; \
} \
} }
void void
psignal (int sig, psignal (int sig,
const char *s) const char *s)
{ {
struct iovec iov[4]; fflush (stderr);
struct iovec *v = iov;
int iov_cnt = 0;
if (s != NULL && *s != '\0') if (s != NULL && *s != '\0')
{ {
ADD (s); WRITE_STR (s);
ADD (": "); WRITE_STR (": ");
} }
ADD (strsignal (sig)); WRITE_STR (strsignal (sig));
#ifdef __SCLE #ifdef __SCLE
ADD ((stderr->_flags & __SCLE) ? "\r\n" : "\n"); WRITE_STR ((stderr->_flags & __SCLE) ? "\r\n" : "\n");
#else #else
ADD ("\n"); WRITE_STR ("\n");
#endif #endif
fflush (stderr);
writev (fileno (stderr), iov, iov_cnt);
} }

View File

@ -56,15 +56,20 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
#include <reent.h> #include <reent.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/uio.h>
#include "local.h" #include "local.h"
#define ADD(str) \ #define WRITE_STR(str) \
{ \ { \
v->iov_base = (void *)(str); \ const char *p = (str); \
v->iov_len = strlen (v->iov_base); \ size_t len = strlen (p); \
v ++; \ while (len) \
iov_cnt ++; \ { \
ssize_t len1 = _write_r (ptr, fileno (fp), p, len); \
if (len1 < 0) \
break; \
len -= len1; \
p += len1; \
} \
} }
void void
@ -73,31 +78,28 @@ _perror_r (struct _reent *ptr,
{ {
char *error; char *error;
int dummy; int dummy;
struct iovec iov[4];
struct iovec *v = iov;
int iov_cnt = 0;
FILE *fp = _stderr_r (ptr); FILE *fp = _stderr_r (ptr);
CHECK_INIT (ptr, fp); CHECK_INIT (ptr, fp);
_newlib_flockfile_start(fp);
_fflush_r (ptr, fp);
if (s != NULL && *s != '\0') if (s != NULL && *s != '\0')
{ {
ADD (s); WRITE_STR (s);
ADD (": "); WRITE_STR (": ");
} }
if ((error = _strerror_r (ptr, ptr->_errno, 1, &dummy)) != NULL) if ((error = _strerror_r (ptr, ptr->_errno, 1, &dummy)) != NULL)
ADD (error); WRITE_STR (error);
#ifdef __SCLE #ifdef __SCLE
ADD ((fp->_flags & __SCLE) ? "\r\n" : "\n"); WRITE_STR ((fp->_flags & __SCLE) ? "\r\n" : "\n");
#else #else
ADD ("\n"); WRITE_STR ("\n");
#endif #endif
fp->_flags &= ~__SOFF;
_newlib_flockfile_start (fp); _newlib_flockfile_end(fp);
fflush (fp);
writev (fileno (fp), iov, iov_cnt);
_newlib_flockfile_end (fp);
} }
#ifndef _REENT_ONLY #ifndef _REENT_ONLY