* libc/stdio/vfprintf.c (_VFPRINTF_R): Avoid multibyte when not

_MB_CAPABLE.
This commit is contained in:
Eric Blake 2007-04-24 19:55:28 +00:00
parent 68f2517f72
commit 27e5e9ab05
2 changed files with 22 additions and 14 deletions

View File

@ -1,5 +1,8 @@
2007-04-24 Eric Blake <ebb9@byu.net> 2007-04-24 Eric Blake <ebb9@byu.net>
* libc/stdio/vfprintf.c (_VFPRINTF_R): Avoid multibyte when not
_MB_CAPABLE.
* libc/include/limits.h (NL_ARGMAX): Define a default value. * libc/include/limits.h (NL_ARGMAX): Define a default value.
* libc/stdio/vfprintf.c (MAX_POS_ARGS): Define in terms of * libc/stdio/vfprintf.c (MAX_POS_ARGS): Define in terms of
NL_ARGMAX, if present. NL_ARGMAX, if present.

View File

@ -161,14 +161,14 @@ static char *rcsid = "$Id$";
#include <newlib.h> #include <newlib.h>
#ifdef INTEGER_ONLY #ifdef INTEGER_ONLY
#define VFPRINTF vfiprintf # define VFPRINTF vfiprintf
#define _VFPRINTF_R _vfiprintf_r # define _VFPRINTF_R _vfiprintf_r
#else #else
#define VFPRINTF vfprintf # define VFPRINTF vfprintf
#define _VFPRINTF_R _vfprintf_r # define _VFPRINTF_R _vfprintf_r
#ifndef NO_FLOATING_POINT # ifndef NO_FLOATING_POINT
#define FLOATING_POINT # define FLOATING_POINT
#endif # endif
#endif #endif
#define _NO_POS_ARGS #define _NO_POS_ARGS
@ -821,18 +821,21 @@ reswitch: switch (ch) {
case 'c': case 'c':
case 'C': case 'C':
cp = buf; cp = buf;
#ifdef _MB_CAPABLE
if (ch == 'C' || (flags & LONGINT)) { if (ch == 'C' || (flags & LONGINT)) {
mbstate_t ps; mbstate_t ps;
memset ((_PTR)&ps, '\0', sizeof (mbstate_t)); memset ((_PTR)&ps, '\0', sizeof (mbstate_t));
if ((size = (int)_wcrtomb_r (data, cp, if ((size = (int)_wcrtomb_r (data, cp,
(wchar_t)GET_ARG (N, ap, wint_t), (wchar_t)GET_ARG (N, ap, wint_t),
&ps)) == -1) { &ps)) == -1) {
fp->_flags |= __SERR; fp->_flags |= __SERR;
goto error; goto error;
} }
} }
else { else
#endif /* _MB_CAPABLE */
{
*cp = GET_ARG (N, ap, int); *cp = GET_ARG (N, ap, int);
size = 1; size = 1;
} }
@ -1010,6 +1013,7 @@ reswitch: switch (ch) {
cp = "(null)"; cp = "(null)";
size = 6; size = 6;
} }
#ifdef _MB_CAPABLE
else if (ch == 'S' || (flags & LONGINT)) { else if (ch == 'S' || (flags & LONGINT)) {
mbstate_t ps; mbstate_t ps;
_CONST wchar_t *wcp; _CONST wchar_t *wcp;
@ -1021,7 +1025,7 @@ reswitch: switch (ch) {
/* Count number of bytes needed for multibyte /* Count number of bytes needed for multibyte
string that will be produced from widechar string that will be produced from widechar
string. */ string. */
if (prec >= 0) { if (prec >= 0) {
while (1) { while (1) {
if (wcp[m] == L'\0') if (wcp[m] == L'\0')
break; break;
@ -1066,6 +1070,7 @@ reswitch: switch (ch) {
cp = malloc_buf; cp = malloc_buf;
cp[size] = '\0'; cp[size] = '\0';
} }
#endif /* _MB_CAPABLE */
else if (prec >= 0) { else if (prec >= 0) {
/* /*
* can't use strlen; can only look for the * can't use strlen; can only look for the