diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2009-03-12 10:27:10 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2009-03-12 10:27:10 +0000 |
commit | 4a825d4145f7a4d409f355b478781fa6742fabbf (patch) | |
tree | d3b97a061b009d6b12ca6faa4a2da7b3e859c3c9 /newlib/libc/stdio/vswprintf.c | |
parent | cab0758eb202c7960157803b148cf68e55fa71a5 (diff) | |
download | newlib-4a825d4145f7a4d409f355b478781fa6742fabbf.zip newlib-4a825d4145f7a4d409f355b478781fa6742fabbf.tar.gz newlib-4a825d4145f7a4d409f355b478781fa6742fabbf.tar.bz2 |
* libc/stdio/swprintf.c (_swprintf_r, swprintf):
correct how terminating L'\0' is added;
change return to match standard for when output does not fit;
some corrections and enhancements to the docs.
* libc/stdio/vswprintf.c (_vswprintf_r): ditto, except for docs.
* libc/stdio/vfwprintf.c: some corrections to the docs and some
enhancements to comments. (No code changes.)
* libc/time/strftime.c: Correct some problems that made wcsftime()
not work correctly: work properly with swprintf returns that are
different from snprintf returns, correct test vector lengths for
when sizeof(wchar_t) > 1.
* libc/stdio/sprintf.c: Some documentation and comment corrections and
enhancements to match those done to swprintf.c.
Diffstat (limited to 'newlib/libc/stdio/vswprintf.c')
-rw-r--r-- | newlib/libc/stdio/vswprintf.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/newlib/libc/stdio/vswprintf.c b/newlib/libc/stdio/vswprintf.c index aebb20a..2d9096c 100644 --- a/newlib/libc/stdio/vswprintf.c +++ b/newlib/libc/stdio/vswprintf.c @@ -27,6 +27,7 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #include <limits.h> #include <stdarg.h> #include <errno.h> + #include "local.h" int @@ -42,7 +43,7 @@ _DEFUN(_vswprintf_r, (ptr, str, size, fmt, ap), if (size > INT_MAX / sizeof (wchar_t)) { - ptr->_errno = EOVERFLOW; + ptr->_errno = EOVERFLOW; /* POSIX extension */ return EOF; } f._flags = __SWR | __SSTR; @@ -50,10 +51,19 @@ _DEFUN(_vswprintf_r, (ptr, str, size, fmt, ap), f._bf._size = f._w = (size > 0 ? (size - 1) * sizeof (wchar_t) : 0); f._file = -1; /* No file. */ ret = _svfwprintf_r (ptr, &f, fmt, ap); - if (ret < EOF) - ptr->_errno = EOVERFLOW; - if (size > 0) - *f._p = 0; + /* _svfwprintf_r() does not put in a terminating NUL, so add one if + * appropriate, which is whenever size is > 0. _svfwprintf_r() stops + * after n-1, so always just put at the end. */ + if (size > 0) { + *(wchar_t *)f._p = L'\0'; /* terminate the string */ + } + if(ret >= size) { + /* _svfwprintf_r() returns how many wide characters it would have printed + * if there were enough space. Return an error if too big to fit in str, + * unlike snprintf, which returns the size needed. */ + ptr->_errno = EOVERFLOW; /* POSIX extension */ + ret = -1; + } return ret; } |