diff options
Diffstat (limited to 'newlib/libc')
-rw-r--r-- | newlib/libc/stdio/Makefile.inc | 10 | ||||
-rw-r--r-- | newlib/libc/stdio/sfputs_r.c | 23 | ||||
-rw-r--r-- | newlib/libc/stdio/sfputws_r.c | 24 | ||||
-rw-r--r-- | newlib/libc/stdio/sprint_r.c | 30 | ||||
-rw-r--r-- | newlib/libc/stdio/ssprint_r.c | 36 | ||||
-rw-r--r-- | newlib/libc/stdio/ssputs_r.c | 69 | ||||
-rw-r--r-- | newlib/libc/stdio/ssputws_r.c | 21 | ||||
-rw-r--r-- | newlib/libc/stdio/sswprint_r.c | 38 | ||||
-rw-r--r-- | newlib/libc/stdio/swprint_r.c | 46 | ||||
-rw-r--r-- | newlib/libc/stdio/vfprintf.c | 262 | ||||
-rw-r--r-- | newlib/libc/stdio/vfwprintf.c | 16 |
11 files changed, 312 insertions, 263 deletions
diff --git a/newlib/libc/stdio/Makefile.inc b/newlib/libc/stdio/Makefile.inc index 2126cea..0780e5c 100644 --- a/newlib/libc/stdio/Makefile.inc +++ b/newlib/libc/stdio/Makefile.inc @@ -33,7 +33,15 @@ libc_a_SOURCES += \ %D%/viscanf.c \ %D%/vsiprintf.c \ %D%/vsiscanf.c \ - %D%/vsniprintf.c + %D%/vsniprintf.c \ + %D%/sfputs_r.c \ + %D%/sfputws_r.c \ + %D%/sprint_r.c \ + %D%/swprint_r.c \ + %D%/ssputs_r.c \ + %D%/ssputws_r.c \ + %D%/ssprint_r.c \ + %D%/sswprint_r.c endif libc_a_SOURCES += \ diff --git a/newlib/libc/stdio/sfputs_r.c b/newlib/libc/stdio/sfputs_r.c new file mode 100644 index 0000000..8e5fc06 --- /dev/null +++ b/newlib/libc/stdio/sfputs_r.c @@ -0,0 +1,23 @@ +#include <newlib.h> + +#ifndef _FVWRITE_IN_STREAMIO + +#include <reent.h> +#include <stdio.h> + +int +__sfputs_r (struct _reent *ptr, + FILE *fp, + const char *buf, + size_t len) +{ + register int i; + + for (i = 0; i < len; i++) { + if (_fputc_r (ptr, buf[i], fp) == EOF) + return -1; + } + return (0); +} + +#endif diff --git a/newlib/libc/stdio/sfputws_r.c b/newlib/libc/stdio/sfputws_r.c new file mode 100644 index 0000000..94b0434 --- /dev/null +++ b/newlib/libc/stdio/sfputws_r.c @@ -0,0 +1,24 @@ +#include <newlib.h> + +#ifndef _FVWRITE_IN_STREAMIO + +#include <reent.h> +#include <stdio.h> +#include <wchar.h> + +int +__sfputws_r (struct _reent *ptr, + FILE *fp, + const wchar_t *buf, + size_t len) +{ + register int i; + + for (i = 0; i < len; i++) { + if (_fputwc_r (ptr, buf[i], fp) == WEOF) + return -1; + } + return (0); +} + +#endif diff --git a/newlib/libc/stdio/sprint_r.c b/newlib/libc/stdio/sprint_r.c new file mode 100644 index 0000000..81c7b7f --- /dev/null +++ b/newlib/libc/stdio/sprint_r.c @@ -0,0 +1,30 @@ +#include <newlib.h> + +#ifdef _FVWRITE_IN_STREAMIO + +#include <reent.h> +#include <stdio.h> +#include "fvwrite.h" + +/* + * Flush out all the vectors defined by the given uio, + * then reset it so that it can be reused. + */ +int +__sprint_r (struct _reent *ptr, + FILE *fp, + register struct __suio *uio) +{ + register int err = 0; + + if (uio->uio_resid == 0) { + uio->uio_iovcnt = 0; + return (0); + } + err = __sfvwrite_r(ptr, fp, uio); + uio->uio_resid = 0; + uio->uio_iovcnt = 0; + return (err); +} + +#endif diff --git a/newlib/libc/stdio/ssprint_r.c b/newlib/libc/stdio/ssprint_r.c new file mode 100644 index 0000000..eedbd6a --- /dev/null +++ b/newlib/libc/stdio/ssprint_r.c @@ -0,0 +1,36 @@ +#include <newlib.h> + +#ifdef _FVWRITE_IN_STREAMIO + +#include <reent.h> +#include <stdio.h> +#include "fvwrite.h" + +extern int __ssputs_r (struct _reent *ptr, FILE *fp, const char *buf, + size_t len); + +int +__ssprint_r (struct _reent *ptr, + FILE *fp, + register struct __suio *uio) +{ + register struct __siov *iov = uio->uio_iov; + register size_t len; + int ret = 0; + + while (uio->uio_resid > 0 && uio->uio_iovcnt-- > 0) { + if ((len = iov->iov_len) > 0) { + if (__ssputs_r (ptr, fp, iov->iov_base, len) == EOF) { + ret = EOF; + break; + } + uio->uio_resid -= len; /* pretend we copied all */ + } + iov++; + } + uio->uio_resid = 0; + uio->uio_iovcnt = 0; + return ret; +} + +#endif diff --git a/newlib/libc/stdio/ssputs_r.c b/newlib/libc/stdio/ssputs_r.c new file mode 100644 index 0000000..abd18ef --- /dev/null +++ b/newlib/libc/stdio/ssputs_r.c @@ -0,0 +1,69 @@ +#include <newlib.h> + +#include <reent.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> + +int +__ssputs_r (struct _reent *ptr, + FILE *fp, + const char *buf, + size_t len) +{ + register int w; + + w = fp->_w; + if (len >= w && fp->_flags & (__SMBF | __SOPT)) { + /* must be asprintf family */ + unsigned char *str; + int curpos = (fp->_p - fp->_bf._base); + /* Choose a geometric growth factor to avoid + * quadratic realloc behavior, but use a rate less + * than (1+sqrt(5))/2 to accomodate malloc + * overhead. asprintf EXPECTS us to overallocate, so + * that it can add a trailing \0 without + * reallocating. The new allocation should thus be + * max(prev_size*1.5, curpos+len+1). */ + int newsize = fp->_bf._size * 3 / 2; + if (newsize < curpos + len + 1) + newsize = curpos + len + 1; + if (fp->_flags & __SOPT) + { + /* asnprintf leaves original buffer alone. */ + str = (unsigned char *)_malloc_r (ptr, newsize); + if (!str) + goto err; + memcpy (str, fp->_bf._base, curpos); + fp->_flags = (fp->_flags & ~__SOPT) | __SMBF; + } + else + { + str = (unsigned char *)_realloc_r (ptr, fp->_bf._base, + newsize); + if (!str) { + /* Free unneeded buffer. */ + _free_r (ptr, fp->_bf._base); + goto err; + } + } + fp->_bf._base = str; + fp->_p = str + curpos; + fp->_bf._size = newsize; + w = len; + fp->_w = newsize - curpos; + } + if (len < w) + w = len; + memmove ((void *) fp->_p, (void *) buf, (size_t) (w)); + fp->_w -= w; + fp->_p += w; + + return 0; + +err: + _REENT_ERRNO(ptr) = ENOMEM; + fp->_flags |= __SERR; + return EOF; +} diff --git a/newlib/libc/stdio/ssputws_r.c b/newlib/libc/stdio/ssputws_r.c new file mode 100644 index 0000000..07ceba8 --- /dev/null +++ b/newlib/libc/stdio/ssputws_r.c @@ -0,0 +1,21 @@ +#include <newlib.h> + +#ifndef _FVWRITE_IN_STREAMIO + +#include <reent.h> +#include <stdio.h> +#include <wchar.h> + +extern int __ssputs_r (struct _reent *ptr, FILE *fp, const char *buf, + size_t len); + +int +__ssputws_r (struct _reent *ptr, + FILE *fp, + const wchar_t *buf, + size_t len) +{ + return __ssputs_r (ptr, fp, (const char *) buf, len * sizeof (wchar_t)); +} + +#endif diff --git a/newlib/libc/stdio/sswprint_r.c b/newlib/libc/stdio/sswprint_r.c new file mode 100644 index 0000000..963e31d --- /dev/null +++ b/newlib/libc/stdio/sswprint_r.c @@ -0,0 +1,38 @@ +#include <newlib.h> + +#ifdef _FVWRITE_IN_STREAMIO + +#include <reent.h> +#include <stdio.h> +#include <wchar.h> +#include "fvwrite.h" + +extern int __ssputs_r (struct _reent *ptr, FILE *fp, const char *buf, + size_t len); + +int +__sswprint_r (struct _reent *ptr, + FILE *fp, + register struct __suio *uio) +{ + register struct __siov *iov = uio->uio_iov; + register size_t len; + int ret = 0; + + while (uio->uio_resid > 0 && uio->uio_iovcnt-- > 0) { + if ((len = iov->iov_len) > 0) { + if (__ssputs_r (ptr, fp, iov->iov_base, + len * sizeof (wchar_t)) == EOF) { + ret = -1; + break; + } + uio->uio_resid -= len; /* pretend we copied all */ + } + iov++; + } + uio->uio_resid = 0; + uio->uio_iovcnt = 0; + return ret; +} + +#endif diff --git a/newlib/libc/stdio/swprint_r.c b/newlib/libc/stdio/swprint_r.c new file mode 100644 index 0000000..e4be0c8 --- /dev/null +++ b/newlib/libc/stdio/swprint_r.c @@ -0,0 +1,46 @@ +#include <newlib.h> + +#ifdef _FVWRITE_IN_STREAMIO + +#include <reent.h> +#include <stdio.h> +#include <wchar.h> +#include "fvwrite.h" + +/* + * Flush out all the vectors defined by the given uio, + * then reset it so that it can be reused. + */ +int +__swprint_r (struct _reent *ptr, + FILE *fp, + register struct __suio *uio) +{ + register int err = 0; + struct __siov *iov; + wchar_t *p; + int i, len; + + if (uio->uio_resid == 0) { + uio->uio_iovcnt = 0; + return (0); + } + iov = uio->uio_iov; + for (; uio->uio_resid != 0; + uio->uio_resid -= len, iov++) { + p = (wchar_t *) iov->iov_base; + len = iov->iov_len; + for (i = 0; i < len; i++) { + if (_fputwc_r (ptr, p[i], fp) == WEOF) { + err = -1; + goto out; + } + } + } +out: + uio->uio_resid = 0; + uio->uio_iovcnt = 0; + return (err); +} + +#endif diff --git a/newlib/libc/stdio/vfprintf.c b/newlib/libc/stdio/vfprintf.c index 42272ab..feb1fab 100644 --- a/newlib/libc/stdio/vfprintf.c +++ b/newlib/libc/stdio/vfprintf.c @@ -174,270 +174,24 @@ static char *rcsid = "$Id$"; #endif #ifdef STRING_ONLY + # ifdef _FVWRITE_IN_STREAMIO # define __SPRINT __ssprint_r + int __ssprint_r (struct _reent *, FILE *, register struct __suio *); # else # define __SPRINT __ssputs_r + int __ssputs_r (struct _reent *, FILE *, const char *, size_t); # endif -#else + +#else /* !STRING_ONLY */ + # ifdef _FVWRITE_IN_STREAMIO # define __SPRINT __sprint_r + int __sprint_r (struct _reent *, FILE *, register struct __suio *); # else # define __SPRINT __sfputs_r + int __sfputs_r (struct _reent *, FILE *, const char *buf, size_t); # endif -#endif - -/* The __sprint_r/__ssprint_r functions are shared between all versions of - vfprintf and vfwprintf. They must only be defined once, which we do in - the INTEGER_ONLY versions here. */ -#ifdef STRING_ONLY -#ifdef INTEGER_ONLY -#ifndef _FVWRITE_IN_STREAMIO -int -__ssputs_r (struct _reent *ptr, - FILE *fp, - const char *buf, - size_t len) -{ - register int w; - - w = fp->_w; - if (len >= w && fp->_flags & (__SMBF | __SOPT)) { - /* must be asprintf family */ - unsigned char *str; - int curpos = (fp->_p - fp->_bf._base); - /* Choose a geometric growth factor to avoid - * quadratic realloc behavior, but use a rate less - * than (1+sqrt(5))/2 to accomodate malloc - * overhead. asprintf EXPECTS us to overallocate, so - * that it can add a trailing \0 without - * reallocating. The new allocation should thus be - * max(prev_size*1.5, curpos+len+1). */ - int newsize = fp->_bf._size * 3 / 2; - if (newsize < curpos + len + 1) - newsize = curpos + len + 1; - if (fp->_flags & __SOPT) - { - /* asnprintf leaves original buffer alone. */ - str = (unsigned char *)_malloc_r (ptr, newsize); - if (!str) - { - _REENT_ERRNO(ptr) = ENOMEM; - goto err; - } - memcpy (str, fp->_bf._base, curpos); - fp->_flags = (fp->_flags & ~__SOPT) | __SMBF; - } - else - { - str = (unsigned char *)_realloc_r (ptr, fp->_bf._base, - newsize); - if (!str) { - /* Free unneeded buffer. */ - _free_r (ptr, fp->_bf._base); - /* Ensure correct errno, even if free - * changed it. */ - _REENT_ERRNO(ptr) = ENOMEM; - goto err; - } - } - fp->_bf._base = str; - fp->_p = str + curpos; - fp->_bf._size = newsize; - w = len; - fp->_w = newsize - curpos; - } - if (len < w) - w = len; - (void)memmove ((void *) fp->_p, (void *) buf, (size_t) (w)); - fp->_w -= w; - fp->_p += w; - - return 0; - -err: - fp->_flags |= __SERR; - return EOF; -} -#endif - -int -__ssprint_r (struct _reent *ptr, - FILE *fp, - register struct __suio *uio) -{ - register size_t len; - register int w; - register struct __siov *iov; - register const char *p = NULL; - - iov = uio->uio_iov; - len = 0; - - if (uio->uio_resid == 0) { - uio->uio_iovcnt = 0; - return (0); - } - - do { - while (len == 0) { - p = iov->iov_base; - len = iov->iov_len; - iov++; - } - w = fp->_w; - if (len >= w && fp->_flags & (__SMBF | __SOPT)) { - /* must be asprintf family */ - unsigned char *str; - int curpos = (fp->_p - fp->_bf._base); - /* Choose a geometric growth factor to avoid - * quadratic realloc behavior, but use a rate less - * than (1+sqrt(5))/2 to accomodate malloc - * overhead. asprintf EXPECTS us to overallocate, so - * that it can add a trailing \0 without - * reallocating. The new allocation should thus be - * max(prev_size*1.5, curpos+len+1). */ - int newsize = fp->_bf._size * 3 / 2; - if (newsize < curpos + len + 1) - newsize = curpos + len + 1; - if (fp->_flags & __SOPT) - { - /* asnprintf leaves original buffer alone. */ - str = (unsigned char *)_malloc_r (ptr, newsize); - if (!str) - { - _REENT_ERRNO(ptr) = ENOMEM; - goto err; - } - memcpy (str, fp->_bf._base, curpos); - fp->_flags = (fp->_flags & ~__SOPT) | __SMBF; - } - else - { - str = (unsigned char *)_realloc_r (ptr, fp->_bf._base, - newsize); - if (!str) { - /* Free unneeded buffer. */ - _free_r (ptr, fp->_bf._base); - /* Ensure correct errno, even if free - * changed it. */ - _REENT_ERRNO(ptr) = ENOMEM; - goto err; - } - } - fp->_bf._base = str; - fp->_p = str + curpos; - fp->_bf._size = newsize; - w = len; - fp->_w = newsize - curpos; - } - if (len < w) - w = len; - (void)memmove ((void *) fp->_p, (void *) p, (size_t) (w)); - fp->_w -= w; - fp->_p += w; - w = len; /* pretend we copied all */ - p += w; - len -= w; - } while ((uio->uio_resid -= w) != 0); - - uio->uio_resid = 0; - uio->uio_iovcnt = 0; - return 0; - -err: - fp->_flags |= __SERR; - uio->uio_resid = 0; - uio->uio_iovcnt = 0; - return EOF; -} -#else /* !INTEGER_ONLY */ -#ifndef _FVWRITE_IN_STREAMIO -int __ssputs_r (struct _reent *, FILE *, const char *, size_t); -#endif -int __ssprint_r (struct _reent *, FILE *, register struct __suio *); -#endif /* !INTEGER_ONLY */ - -#else /* !STRING_ONLY */ -#ifdef INTEGER_ONLY - -#ifndef _FVWRITE_IN_STREAMIO -int -__sfputs_r (struct _reent *ptr, - FILE *fp, - const char *buf, - size_t len) -{ - register int i; - -#if defined _WIDE_ORIENT && (!defined _ELIX_LEVEL || _ELIX_LEVEL >= 4) - if (fp->_flags2 & __SWID) { - wchar_t *p; - - p = (wchar_t *) buf; - for (i = 0; i < (len / sizeof (wchar_t)); i++) { - if (_fputwc_r (ptr, p[i], fp) == WEOF) - return -1; - } - } else { -#else - { -#endif - for (i = 0; i < len; i++) { - if (_fputc_r (ptr, buf[i], fp) == EOF) - return -1; - } - } - return (0); -} -#endif -/* - * Flush out all the vectors defined by the given uio, - * then reset it so that it can be reused. - */ -int -__sprint_r (struct _reent *ptr, - FILE *fp, - register struct __suio *uio) -{ - register int err = 0; - - if (uio->uio_resid == 0) { - uio->uio_iovcnt = 0; - return (0); - } -#if defined _WIDE_ORIENT && (!defined _ELIX_LEVEL || _ELIX_LEVEL >= 4) - if (fp->_flags2 & __SWID) { - struct __siov *iov; - wchar_t *p; - int i, len; - - iov = uio->uio_iov; - for (; uio->uio_resid != 0; - uio->uio_resid -= len * sizeof (wchar_t), iov++) { - p = (wchar_t *) iov->iov_base; - len = iov->iov_len / sizeof (wchar_t); - for (i = 0; i < len; i++) { - if (_fputwc_r (ptr, p[i], fp) == WEOF) { - err = -1; - goto out; - } - } - } - } else -#endif - err = __sfvwrite_r(ptr, fp, uio); -out: - uio->uio_resid = 0; - uio->uio_iovcnt = 0; - return (err); -} -#else /* !INTEGER_ONLY */ -#ifndef _FVWRITE_IN_STREAMIO -int __sfputs_r (struct _reent *, FILE *, const char *buf, size_t); -#endif -int __sprint_r (struct _reent *, FILE *, register struct __suio *); -#endif /* !INTEGER_ONLY */ #ifdef _UNBUF_STREAM_OPT /* diff --git a/newlib/libc/stdio/vfwprintf.c b/newlib/libc/stdio/vfwprintf.c index bbabbda..5a5c368 100644 --- a/newlib/libc/stdio/vfwprintf.c +++ b/newlib/libc/stdio/vfwprintf.c @@ -153,18 +153,18 @@ int _VFWPRINTF_R (struct _reent *, FILE *, const wchar_t *, va_list); /* Defined in vfprintf.c. */ #ifdef _FVWRITE_IN_STREAMIO # ifdef STRING_ONLY -# define __SPRINT __ssprint_r +# define __SPRINT __sswprint_r # else -# define __SPRINT __sprint_r +# define __SPRINT __swprint_r # endif int __SPRINT (struct _reent *, FILE *, register struct __suio *); #else # ifdef STRING_ONLY -# define __SPRINT __ssputs_r +# define __SPRINT __ssputws_r # else -# define __SPRINT __sfputs_r +# define __SPRINT __sfputws_r # endif -int __SPRINT (struct _reent *, FILE *, const char *, size_t); +int __SPRINT (struct _reent *, FILE *, const wchar_t *, size_t); #endif #ifndef STRING_ONLY #ifdef _UNBUF_STREAM_OPT @@ -479,8 +479,8 @@ _VFWPRINTF_R (struct _reent *data, #ifdef _FVWRITE_IN_STREAMIO #define PRINT(ptr, len) { \ iovp->iov_base = (char *) (ptr); \ - iovp->iov_len = (len) * sizeof (wchar_t); \ - uio.uio_resid += (len) * sizeof (wchar_t); \ + iovp->iov_len = (len); \ + uio.uio_resid += iovp->iov_len; \ iovp++; \ if (++uio.uio_iovcnt >= NIOV) { \ if (__SPRINT(data, fp, &uio)) \ @@ -513,7 +513,7 @@ _VFWPRINTF_R (struct _reent *data, } #else #define PRINT(ptr, len) { \ - if (__SPRINT (data, fp, (const char *)(ptr), (len) * sizeof (wchar_t)) == EOF) \ + if (__SPRINT (data, fp, (ptr), (len)) == EOF) \ goto error; \ } #define PAD(howmany, with) { \ |