OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [stdio/] [vfprintf.c] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
/*
/*
 * Copyright (c) 1990 The Regents of the University of California.
 * Copyright (c) 1990 The Regents of the University of California.
 * All rights reserved.
 * All rights reserved.
 *
 *
 * This code is derived from software contributed to Berkeley by
 * This code is derived from software contributed to Berkeley by
 * Chris Torek.
 * Chris Torek.
 *
 *
 * Redistribution and use in source and binary forms, with or without
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * modification, are permitted provided that the following conditions
 * are met:
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *    must display the following acknowledgement:
 *      This product includes software developed by the University of
 *      This product includes software developed by the University of
 *      California, Berkeley and its contributors.
 *      California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *    without specific prior written permission.
 *
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * SUCH DAMAGE.
 */
 */
 
 
/*
/*
FUNCTION
FUNCTION
<<vfprintf>>, <<vprintf>>, <<vsprintf>>, <<vsnprintf>>, <<vasprintf>>, <<vasnprintf>>---format argument list
<<vfprintf>>, <<vprintf>>, <<vsprintf>>, <<vsnprintf>>, <<vasprintf>>, <<vasnprintf>>---format argument list
 
 
INDEX
INDEX
        vfprintf
        vfprintf
INDEX
INDEX
        _vfprintf_r
        _vfprintf_r
INDEX
INDEX
        vprintf
        vprintf
INDEX
INDEX
        _vprintf_r
        _vprintf_r
INDEX
INDEX
        vsprintf
        vsprintf
INDEX
INDEX
        _vsprintf_r
        _vsprintf_r
INDEX
INDEX
        vsnprintf
        vsnprintf
INDEX
INDEX
        _vsnprintf_r
        _vsnprintf_r
INDEX
INDEX
        vasprintf
        vasprintf
INDEX
INDEX
        _vasprintf_r
        _vasprintf_r
INDEX
INDEX
        vasnprintf
        vasnprintf
INDEX
INDEX
        _vasnprintf_r
        _vasnprintf_r
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <stdio.h>
        #include <stdio.h>
        #include <stdarg.h>
        #include <stdarg.h>
        int vprintf(const char *<[fmt]>, va_list <[list]>);
        int vprintf(const char *<[fmt]>, va_list <[list]>);
        int vfprintf(FILE *<[fp]>, const char *<[fmt]>, va_list <[list]>);
        int vfprintf(FILE *<[fp]>, const char *<[fmt]>, va_list <[list]>);
        int vsprintf(char *<[str]>, const char *<[fmt]>, va_list <[list]>);
        int vsprintf(char *<[str]>, const char *<[fmt]>, va_list <[list]>);
        int vsnprintf(char *<[str]>, size_t <[size]>, const char *<[fmt]>,
        int vsnprintf(char *<[str]>, size_t <[size]>, const char *<[fmt]>,
                      va_list <[list]>);
                      va_list <[list]>);
        int vasprintf(char **<[strp]>, const char *<[fmt]>, va_list <[list]>);
        int vasprintf(char **<[strp]>, const char *<[fmt]>, va_list <[list]>);
        char *vasnprintf(char *<[str]>, size_t *<[size]>, const char *<[fmt]>,
        char *vasnprintf(char *<[str]>, size_t *<[size]>, const char *<[fmt]>,
                         va_list <[list]>);
                         va_list <[list]>);
 
 
        int _vprintf_r(struct _reent *<[reent]>, const char *<[fmt]>,
        int _vprintf_r(struct _reent *<[reent]>, const char *<[fmt]>,
                        va_list <[list]>);
                        va_list <[list]>);
        int _vfprintf_r(struct _reent *<[reent]>, FILE *<[fp]>,
        int _vfprintf_r(struct _reent *<[reent]>, FILE *<[fp]>,
                        const char *<[fmt]>, va_list <[list]>);
                        const char *<[fmt]>, va_list <[list]>);
        int _vsprintf_r(struct _reent *<[reent]>, char *<[str]>,
        int _vsprintf_r(struct _reent *<[reent]>, char *<[str]>,
                        const char *<[fmt]>, va_list <[list]>);
                        const char *<[fmt]>, va_list <[list]>);
        int _vasprintf_r(struct _reent *<[reent]>, char **<[str]>,
        int _vasprintf_r(struct _reent *<[reent]>, char **<[str]>,
                         const char *<[fmt]>, va_list <[list]>);
                         const char *<[fmt]>, va_list <[list]>);
        int _vsnprintf_r(struct _reent *<[reent]>, char *<[str]>,
        int _vsnprintf_r(struct _reent *<[reent]>, char *<[str]>,
                         size_t <[size]>, const char *<[fmt]>, va_list <[list]>);
                         size_t <[size]>, const char *<[fmt]>, va_list <[list]>);
        char *_vasnprintf_r(struct _reent *<[reent]>, char *<[str]>,
        char *_vasnprintf_r(struct _reent *<[reent]>, char *<[str]>,
                            size_t *<[size]>, const char *<[fmt]>, va_list <[list]>);
                            size_t *<[size]>, const char *<[fmt]>, va_list <[list]>);
 
 
DESCRIPTION
DESCRIPTION
<<vprintf>>, <<vfprintf>>, <<vasprintf>>, <<vsprintf>>, <<vsnprintf>>,
<<vprintf>>, <<vfprintf>>, <<vasprintf>>, <<vsprintf>>, <<vsnprintf>>,
and <<vasnprintf>> are (respectively) variants of <<printf>>,
and <<vasnprintf>> are (respectively) variants of <<printf>>,
<<fprintf>>, <<asprintf>>, <<sprintf>>, <<snprintf>>, and
<<fprintf>>, <<asprintf>>, <<sprintf>>, <<snprintf>>, and
<<asnprintf>>.  They differ only in allowing their caller to pass the
<<asnprintf>>.  They differ only in allowing their caller to pass the
variable argument list as a <<va_list>> object (initialized by
variable argument list as a <<va_list>> object (initialized by
<<va_start>>) rather than directly accepting a variable number of
<<va_start>>) rather than directly accepting a variable number of
arguments.  The caller is responsible for calling <<va_end>>.
arguments.  The caller is responsible for calling <<va_end>>.
 
 
<<_vprintf_r>>, <<_vfprintf_r>>, <<_vasprintf_r>>, <<_vsprintf_r>>,
<<_vprintf_r>>, <<_vfprintf_r>>, <<_vasprintf_r>>, <<_vsprintf_r>>,
<<_vsnprintf_r>>, and <<_vasnprintf_r>> are reentrant versions of the
<<_vsnprintf_r>>, and <<_vasnprintf_r>> are reentrant versions of the
above.
above.
 
 
RETURNS
RETURNS
The return values are consistent with the corresponding functions.
The return values are consistent with the corresponding functions.
 
 
PORTABILITY
PORTABILITY
ANSI C requires <<vprintf>>, <<vfprintf>>, <<vsprintf>>, and
ANSI C requires <<vprintf>>, <<vfprintf>>, <<vsprintf>>, and
<<vsnprintf>>.  The remaining functions are newlib extensions.
<<vsnprintf>>.  The remaining functions are newlib extensions.
 
 
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
*/
 
 
#if defined(LIBC_SCCS) && !defined(lint)
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)vfprintf.c   5.50 (Berkeley) 12/16/92";*/
/*static char *sccsid = "from: @(#)vfprintf.c   5.50 (Berkeley) 12/16/92";*/
static char *rcsid = "$Id: vfprintf.c 207 2010-07-19 17:43:24Z jeremybennett $";
static char *rcsid = "$Id: vfprintf.c 207 2010-07-19 17:43:24Z jeremybennett $";
#endif /* LIBC_SCCS and not lint */
#endif /* LIBC_SCCS and not lint */
 
 
/*
/*
 * Actual printf innards.
 * Actual printf innards.
 *
 *
 * This code is large and complicated...
 * This code is large and complicated...
 */
 */
#include <newlib.h>
#include <newlib.h>
 
 
#ifdef INTEGER_ONLY
#ifdef INTEGER_ONLY
# define VFPRINTF vfiprintf
# define VFPRINTF vfiprintf
# ifdef STRING_ONLY
# ifdef STRING_ONLY
#   define _VFPRINTF_R _svfiprintf_r
#   define _VFPRINTF_R _svfiprintf_r
# else
# else
#   define _VFPRINTF_R _vfiprintf_r
#   define _VFPRINTF_R _vfiprintf_r
# endif
# endif
#else
#else
# define VFPRINTF vfprintf
# define VFPRINTF vfprintf
# ifdef STRING_ONLY
# ifdef STRING_ONLY
#   define _VFPRINTF_R _svfprintf_r
#   define _VFPRINTF_R _svfprintf_r
# else
# else
#   define _VFPRINTF_R _vfprintf_r
#   define _VFPRINTF_R _vfprintf_r
# endif
# endif
# 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
#ifdef _WANT_IO_POS_ARGS
#ifdef _WANT_IO_POS_ARGS
# undef _NO_POS_ARGS
# undef _NO_POS_ARGS
#endif
#endif
 
 
#include <_ansi.h>
#include <_ansi.h>
#include <reent.h>
#include <reent.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <limits.h>
#include <limits.h>
#include <stdint.h>
#include <stdint.h>
#include <wchar.h>
#include <wchar.h>
#include <sys/lock.h>
#include <sys/lock.h>
#include <stdarg.h>
#include <stdarg.h>
#include "local.h"
#include "local.h"
#include "../stdlib/local.h"
#include "../stdlib/local.h"
#include "fvwrite.h"
#include "fvwrite.h"
#include "vfieeefp.h"
#include "vfieeefp.h"
 
 
/* Currently a test is made to see if long double processing is warranted.
/* Currently a test is made to see if long double processing is warranted.
   This could be changed in the future should the _ldtoa_r code be
   This could be changed in the future should the _ldtoa_r code be
   preferred over _dtoa_r.  */
   preferred over _dtoa_r.  */
#define _NO_LONGDBL
#define _NO_LONGDBL
#if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG)
#if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG)
#undef _NO_LONGDBL
#undef _NO_LONGDBL
#endif
#endif
 
 
#define _NO_LONGLONG
#define _NO_LONGLONG
#if defined _WANT_IO_LONG_LONG \
#if defined _WANT_IO_LONG_LONG \
        && (defined __GNUC__ || __STDC_VERSION__ >= 199901L)
        && (defined __GNUC__ || __STDC_VERSION__ >= 199901L)
# undef _NO_LONGLONG
# undef _NO_LONGLONG
#endif
#endif
 
 
#ifdef STRING_ONLY
#ifdef STRING_ONLY
#define __SPRINT __ssprint_r
#define __SPRINT __ssprint_r
#else
#else
#define __SPRINT __sprint_r
#define __SPRINT __sprint_r
#endif
#endif
 
 
/* The __sprint_r/__ssprint_r functions are shared between all versions of
/* 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
   vfprintf and vfwprintf.  They must only be defined once, which we do in
   the INTEGER_ONLY versions here. */
   the INTEGER_ONLY versions here. */
#ifdef STRING_ONLY
#ifdef STRING_ONLY
#ifdef INTEGER_ONLY
#ifdef INTEGER_ONLY
int
int
_DEFUN(__ssprint_r, (ptr, fp, uio),
_DEFUN(__ssprint_r, (ptr, fp, uio),
       struct _reent *ptr _AND
       struct _reent *ptr _AND
       FILE *fp _AND
       FILE *fp _AND
       register struct __suio *uio)
       register struct __suio *uio)
{
{
        register size_t len;
        register size_t len;
        register int w;
        register int w;
        register struct __siov *iov;
        register struct __siov *iov;
        register _CONST char *p = NULL;
        register _CONST char *p = NULL;
 
 
        iov = uio->uio_iov;
        iov = uio->uio_iov;
        len = 0;
        len = 0;
 
 
        if (uio->uio_resid == 0) {
        if (uio->uio_resid == 0) {
                uio->uio_iovcnt = 0;
                uio->uio_iovcnt = 0;
                return (0);
                return (0);
        }
        }
 
 
        do {
        do {
                while (len == 0) {
                while (len == 0) {
                        p = iov->iov_base;
                        p = iov->iov_base;
                        len = iov->iov_len;
                        len = iov->iov_len;
                        iov++;
                        iov++;
                }
                }
                w = fp->_w;
                w = fp->_w;
                if (len >= w && fp->_flags & (__SMBF | __SOPT)) {
                if (len >= w && fp->_flags & (__SMBF | __SOPT)) {
                        /* must be asprintf family */
                        /* must be asprintf family */
                        unsigned char *str;
                        unsigned char *str;
                        int curpos = (fp->_p - fp->_bf._base);
                        int curpos = (fp->_p - fp->_bf._base);
                        /* Choose a geometric growth factor to avoid
                        /* Choose a geometric growth factor to avoid
                         * quadratic realloc behavior, but use a rate less
                         * quadratic realloc behavior, but use a rate less
                         * than (1+sqrt(5))/2 to accomodate malloc
                         * than (1+sqrt(5))/2 to accomodate malloc
                         * overhead. asprintf EXPECTS us to overallocate, so
                         * overhead. asprintf EXPECTS us to overallocate, so
                         * that it can add a trailing \0 without
                         * that it can add a trailing \0 without
                         * reallocating.  The new allocation should thus be
                         * reallocating.  The new allocation should thus be
                         * max(prev_size*1.5, curpos+len+1). */
                         * max(prev_size*1.5, curpos+len+1). */
                        int newsize = fp->_bf._size * 3 / 2;
                        int newsize = fp->_bf._size * 3 / 2;
                        if (newsize < curpos + len + 1)
                        if (newsize < curpos + len + 1)
                                newsize = curpos + len + 1;
                                newsize = curpos + len + 1;
                        if (fp->_flags & __SOPT)
                        if (fp->_flags & __SOPT)
                        {
                        {
                                /* asnprintf leaves original buffer alone.  */
                                /* asnprintf leaves original buffer alone.  */
                                str = (unsigned char *)_malloc_r (ptr, newsize);
                                str = (unsigned char *)_malloc_r (ptr, newsize);
                                if (!str)
                                if (!str)
                                {
                                {
                                        ptr->_errno = ENOMEM;
                                        ptr->_errno = ENOMEM;
                                        goto err;
                                        goto err;
                                }
                                }
                                memcpy (str, fp->_bf._base, curpos);
                                memcpy (str, fp->_bf._base, curpos);
                                fp->_flags = (fp->_flags & ~__SOPT) | __SMBF;
                                fp->_flags = (fp->_flags & ~__SOPT) | __SMBF;
                        }
                        }
                        else
                        else
                        {
                        {
                                str = (unsigned char *)_realloc_r (ptr, fp->_bf._base,
                                str = (unsigned char *)_realloc_r (ptr, fp->_bf._base,
                                                newsize);
                                                newsize);
                                if (!str) {
                                if (!str) {
                                        /* Free unneeded buffer.  */
                                        /* Free unneeded buffer.  */
                                        _free_r (ptr, fp->_bf._base);
                                        _free_r (ptr, fp->_bf._base);
                                        /* Ensure correct errno, even if free
                                        /* Ensure correct errno, even if free
                                         * changed it.  */
                                         * changed it.  */
                                        ptr->_errno = ENOMEM;
                                        ptr->_errno = ENOMEM;
                                        goto err;
                                        goto err;
                                }
                                }
                        }
                        }
                        fp->_bf._base = str;
                        fp->_bf._base = str;
                        fp->_p = str + curpos;
                        fp->_p = str + curpos;
                        fp->_bf._size = newsize;
                        fp->_bf._size = newsize;
                        w = len;
                        w = len;
                        fp->_w = newsize - curpos;
                        fp->_w = newsize - curpos;
                }
                }
                if (len < w)
                if (len < w)
                        w = len;
                        w = len;
                (void)memmove ((_PTR) fp->_p, (_PTR) p, (size_t) (w));
                (void)memmove ((_PTR) fp->_p, (_PTR) p, (size_t) (w));
                fp->_w -= w;
                fp->_w -= w;
                fp->_p += w;
                fp->_p += w;
                w = len;          /* pretend we copied all */
                w = len;          /* pretend we copied all */
                p += w;
                p += w;
                len -= w;
                len -= w;
        } while ((uio->uio_resid -= w) != 0);
        } while ((uio->uio_resid -= w) != 0);
 
 
        uio->uio_resid = 0;
        uio->uio_resid = 0;
        uio->uio_iovcnt = 0;
        uio->uio_iovcnt = 0;
        return 0;
        return 0;
 
 
err:
err:
  fp->_flags |= __SERR;
  fp->_flags |= __SERR;
  uio->uio_resid = 0;
  uio->uio_resid = 0;
  uio->uio_iovcnt = 0;
  uio->uio_iovcnt = 0;
  return EOF;
  return EOF;
}
}
#else /* !INTEGER_ONLY */
#else /* !INTEGER_ONLY */
int __ssprint_r (struct _reent *, FILE *, register struct __suio *);
int __ssprint_r (struct _reent *, FILE *, register struct __suio *);
#endif /* !INTEGER_ONLY */
#endif /* !INTEGER_ONLY */
 
 
#else /* !STRING_ONLY */
#else /* !STRING_ONLY */
#ifdef INTEGER_ONLY
#ifdef INTEGER_ONLY
/*
/*
 * Flush out all the vectors defined by the given uio,
 * Flush out all the vectors defined by the given uio,
 * then reset it so that it can be reused.
 * then reset it so that it can be reused.
 */
 */
int
int
_DEFUN(__sprint_r, (ptr, fp, uio),
_DEFUN(__sprint_r, (ptr, fp, uio),
       struct _reent *ptr _AND
       struct _reent *ptr _AND
       FILE *fp _AND
       FILE *fp _AND
       register struct __suio *uio)
       register struct __suio *uio)
{
{
        register int err = 0;
        register int err = 0;
 
 
        if (uio->uio_resid == 0) {
        if (uio->uio_resid == 0) {
                uio->uio_iovcnt = 0;
                uio->uio_iovcnt = 0;
                return (0);
                return (0);
        }
        }
        if (fp->_flags2 & __SWID) {
        if (fp->_flags2 & __SWID) {
                struct __siov *iov;
                struct __siov *iov;
                wchar_t *p;
                wchar_t *p;
                int i, len;
                int i, len;
 
 
                iov = uio->uio_iov;
                iov = uio->uio_iov;
                for (; uio->uio_resid != 0;
                for (; uio->uio_resid != 0;
                     uio->uio_resid -= len * sizeof (wchar_t), iov++) {
                     uio->uio_resid -= len * sizeof (wchar_t), iov++) {
                        p = (wchar_t *) iov->iov_base;
                        p = (wchar_t *) iov->iov_base;
                        len = iov->iov_len / sizeof (wchar_t);
                        len = iov->iov_len / sizeof (wchar_t);
                        for (i = 0; i < len; i++) {
                        for (i = 0; i < len; i++) {
                                if (_fputwc_r (ptr, p[i], fp) == WEOF) {
                                if (_fputwc_r (ptr, p[i], fp) == WEOF) {
                                        err = -1;
                                        err = -1;
                                        goto out;
                                        goto out;
                                }
                                }
                        }
                        }
                }
                }
        } else
        } else
                err = __sfvwrite_r(ptr, fp, uio);
                err = __sfvwrite_r(ptr, fp, uio);
out:
out:
        uio->uio_resid = 0;
        uio->uio_resid = 0;
        uio->uio_iovcnt = 0;
        uio->uio_iovcnt = 0;
        return (err);
        return (err);
}
}
#else /* !INTEGER_ONLY */
#else /* !INTEGER_ONLY */
int __sprint_r (struct _reent *, FILE *, register struct __suio *);
int __sprint_r (struct _reent *, FILE *, register struct __suio *);
#endif /* !INTEGER_ONLY */
#endif /* !INTEGER_ONLY */
 
 
/*
/*
 * Helper function for `fprintf to unbuffered unix file': creates a
 * Helper function for `fprintf to unbuffered unix file': creates a
 * temporary buffer.  We only work on write-only files; this avoids
 * temporary buffer.  We only work on write-only files; this avoids
 * worries about ungetc buffers and so forth.
 * worries about ungetc buffers and so forth.
 */
 */
static int
static int
_DEFUN(__sbprintf, (rptr, fp, fmt, ap),
_DEFUN(__sbprintf, (rptr, fp, fmt, ap),
       struct _reent *rptr _AND
       struct _reent *rptr _AND
       register FILE *fp   _AND
       register FILE *fp   _AND
       _CONST char *fmt  _AND
       _CONST char *fmt  _AND
       va_list ap)
       va_list ap)
{
{
        int ret;
        int ret;
        FILE fake;
        FILE fake;
        unsigned char buf[BUFSIZ];
        unsigned char buf[BUFSIZ];
 
 
        /* copy the important variables */
        /* copy the important variables */
        fake._flags = fp->_flags & ~__SNBF;
        fake._flags = fp->_flags & ~__SNBF;
        fake._flags2 = fp->_flags2;
        fake._flags2 = fp->_flags2;
        fake._file = fp->_file;
        fake._file = fp->_file;
        fake._cookie = fp->_cookie;
        fake._cookie = fp->_cookie;
        fake._write = fp->_write;
        fake._write = fp->_write;
 
 
        /* set up the buffer */
        /* set up the buffer */
        fake._bf._base = fake._p = buf;
        fake._bf._base = fake._p = buf;
        fake._bf._size = fake._w = sizeof (buf);
        fake._bf._size = fake._w = sizeof (buf);
        fake._lbfsize = 0;       /* not actually used, but Just In Case */
        fake._lbfsize = 0;       /* not actually used, but Just In Case */
#ifndef __SINGLE_THREAD__
#ifndef __SINGLE_THREAD__
        __lock_init_recursive (fake._lock);
        __lock_init_recursive (fake._lock);
#endif
#endif
 
 
        /* do the work, then copy any error status */
        /* do the work, then copy any error status */
        ret = _VFPRINTF_R (rptr, &fake, fmt, ap);
        ret = _VFPRINTF_R (rptr, &fake, fmt, ap);
        if (ret >= 0 && _fflush_r (rptr, &fake))
        if (ret >= 0 && _fflush_r (rptr, &fake))
                ret = EOF;
                ret = EOF;
        if (fake._flags & __SERR)
        if (fake._flags & __SERR)
                fp->_flags |= __SERR;
                fp->_flags |= __SERR;
 
 
#ifndef __SINGLE_THREAD__
#ifndef __SINGLE_THREAD__
        __lock_close_recursive (fake._lock);
        __lock_close_recursive (fake._lock);
#endif
#endif
        return (ret);
        return (ret);
}
}
#endif /* !STRING_ONLY */
#endif /* !STRING_ONLY */
 
 
 
 
#ifdef FLOATING_POINT
#ifdef FLOATING_POINT
# include <locale.h>
# include <locale.h>
# include <math.h>
# include <math.h>
 
 
/* For %La, an exponent of 15 bits occupies the exponent character, a
/* For %La, an exponent of 15 bits occupies the exponent character, a
   sign, and up to 5 digits.  */
   sign, and up to 5 digits.  */
# define MAXEXPLEN              7
# define MAXEXPLEN              7
# define DEFPREC                6
# define DEFPREC                6
 
 
# ifdef _NO_LONGDBL
# ifdef _NO_LONGDBL
 
 
extern char *_dtoa_r _PARAMS((struct _reent *, double, int,
extern char *_dtoa_r _PARAMS((struct _reent *, double, int,
                              int, int *, int *, char **));
                              int, int *, int *, char **));
 
 
#  define _PRINTF_FLOAT_TYPE double
#  define _PRINTF_FLOAT_TYPE double
#  define _DTOA_R _dtoa_r
#  define _DTOA_R _dtoa_r
#  define FREXP frexp
#  define FREXP frexp
 
 
# else /* !_NO_LONGDBL */
# else /* !_NO_LONGDBL */
 
 
extern char *_ldtoa_r _PARAMS((struct _reent *, _LONG_DOUBLE, int,
extern char *_ldtoa_r _PARAMS((struct _reent *, _LONG_DOUBLE, int,
                              int, int *, int *, char **));
                              int, int *, int *, char **));
 
 
extern int _EXFUN(_ldcheck,(_LONG_DOUBLE *));
extern int _EXFUN(_ldcheck,(_LONG_DOUBLE *));
 
 
#  define _PRINTF_FLOAT_TYPE _LONG_DOUBLE
#  define _PRINTF_FLOAT_TYPE _LONG_DOUBLE
#  define _DTOA_R _ldtoa_r
#  define _DTOA_R _ldtoa_r
/* FIXME - frexpl is not yet supported; and cvt infloops if (double)f
/* FIXME - frexpl is not yet supported; and cvt infloops if (double)f
   converts a finite value into infinity.  */
   converts a finite value into infinity.  */
/* #  define FREXP frexpl */
/* #  define FREXP frexpl */
#  define FREXP(f,e) ((_LONG_DOUBLE) frexp ((double)f, e))
#  define FREXP(f,e) ((_LONG_DOUBLE) frexp ((double)f, e))
# endif /* !_NO_LONGDBL */
# endif /* !_NO_LONGDBL */
 
 
static char *cvt(struct _reent *, _PRINTF_FLOAT_TYPE, int, int, char *, int *,
static char *cvt(struct _reent *, _PRINTF_FLOAT_TYPE, int, int, char *, int *,
                 int, int *, char *);
                 int, int *, char *);
 
 
static int exponent(char *, int, int);
static int exponent(char *, int, int);
 
 
#endif /* FLOATING_POINT */
#endif /* FLOATING_POINT */
 
 
/* BUF must be big enough for the maximum %#llo (assuming long long is
/* BUF must be big enough for the maximum %#llo (assuming long long is
   at most 64 bits, this would be 23 characters), the maximum
   at most 64 bits, this would be 23 characters), the maximum
   multibyte character %C, and the maximum default precision of %La
   multibyte character %C, and the maximum default precision of %La
   (assuming long double is at most 128 bits with 113 bits of
   (assuming long double is at most 128 bits with 113 bits of
   mantissa, this would be 29 characters).  %e, %f, and %g use
   mantissa, this would be 29 characters).  %e, %f, and %g use
   reentrant storage shared with mprec.  All other formats that use
   reentrant storage shared with mprec.  All other formats that use
   buf get by with fewer characters.  Making BUF slightly bigger
   buf get by with fewer characters.  Making BUF slightly bigger
   reduces the need for malloc in %.*a and %S, when large precision or
   reduces the need for malloc in %.*a and %S, when large precision or
   long strings are processed.  */
   long strings are processed.  */
#define BUF             40
#define BUF             40
#if defined _MB_CAPABLE && MB_LEN_MAX > BUF
#if defined _MB_CAPABLE && MB_LEN_MAX > BUF
# undef BUF
# undef BUF
# define BUF MB_LEN_MAX
# define BUF MB_LEN_MAX
#endif
#endif
 
 
#ifndef _NO_LONGLONG
#ifndef _NO_LONGLONG
# define quad_t long long
# define quad_t long long
# define u_quad_t unsigned long long
# define u_quad_t unsigned long long
#else
#else
# define quad_t long
# define quad_t long
# define u_quad_t unsigned long
# define u_quad_t unsigned long
#endif
#endif
 
 
typedef quad_t * quad_ptr_t;
typedef quad_t * quad_ptr_t;
typedef _PTR     void_ptr_t;
typedef _PTR     void_ptr_t;
typedef char *   char_ptr_t;
typedef char *   char_ptr_t;
typedef long *   long_ptr_t;
typedef long *   long_ptr_t;
typedef int  *   int_ptr_t;
typedef int  *   int_ptr_t;
typedef short *  short_ptr_t;
typedef short *  short_ptr_t;
 
 
#ifndef _NO_POS_ARGS
#ifndef _NO_POS_ARGS
# ifdef NL_ARGMAX
# ifdef NL_ARGMAX
#  define MAX_POS_ARGS NL_ARGMAX
#  define MAX_POS_ARGS NL_ARGMAX
# else
# else
#  define MAX_POS_ARGS 32
#  define MAX_POS_ARGS 32
# endif
# endif
 
 
union arg_val
union arg_val
{
{
  int val_int;
  int val_int;
  u_int val_u_int;
  u_int val_u_int;
  long val_long;
  long val_long;
  u_long val_u_long;
  u_long val_u_long;
  float val_float;
  float val_float;
  double val_double;
  double val_double;
  _LONG_DOUBLE val__LONG_DOUBLE;
  _LONG_DOUBLE val__LONG_DOUBLE;
  int_ptr_t val_int_ptr_t;
  int_ptr_t val_int_ptr_t;
  short_ptr_t val_short_ptr_t;
  short_ptr_t val_short_ptr_t;
  long_ptr_t val_long_ptr_t;
  long_ptr_t val_long_ptr_t;
  char_ptr_t val_char_ptr_t;
  char_ptr_t val_char_ptr_t;
  quad_ptr_t val_quad_ptr_t;
  quad_ptr_t val_quad_ptr_t;
  void_ptr_t val_void_ptr_t;
  void_ptr_t val_void_ptr_t;
  quad_t val_quad_t;
  quad_t val_quad_t;
  u_quad_t val_u_quad_t;
  u_quad_t val_u_quad_t;
  wint_t val_wint_t;
  wint_t val_wint_t;
};
};
 
 
static union arg_val *
static union arg_val *
_EXFUN(get_arg, (struct _reent *data, int n, char *fmt,
_EXFUN(get_arg, (struct _reent *data, int n, char *fmt,
                 va_list *ap, int *numargs, union arg_val *args,
                 va_list *ap, int *numargs, union arg_val *args,
                 int *arg_type, char **last_fmt));
                 int *arg_type, char **last_fmt));
#endif /* !_NO_POS_ARGS */
#endif /* !_NO_POS_ARGS */
 
 
/*
/*
 * Macros for converting digits to letters and vice versa
 * Macros for converting digits to letters and vice versa
 */
 */
#define to_digit(c)     ((c) - '0')
#define to_digit(c)     ((c) - '0')
#define is_digit(c)     ((unsigned)to_digit (c) <= 9)
#define is_digit(c)     ((unsigned)to_digit (c) <= 9)
#define to_char(n)      ((n) + '0')
#define to_char(n)      ((n) + '0')
 
 
/*
/*
 * Flags used during conversion.
 * Flags used during conversion.
 */
 */
#define ALT             0x001           /* alternate form */
#define ALT             0x001           /* alternate form */
#define HEXPREFIX       0x002           /* add 0x or 0X prefix */
#define HEXPREFIX       0x002           /* add 0x or 0X prefix */
#define LADJUST         0x004           /* left adjustment */
#define LADJUST         0x004           /* left adjustment */
#define LONGDBL         0x008           /* long double */
#define LONGDBL         0x008           /* long double */
#define LONGINT         0x010           /* long integer */
#define LONGINT         0x010           /* long integer */
#ifndef _NO_LONGLONG
#ifndef _NO_LONGLONG
# define QUADINT        0x020           /* quad integer */
# define QUADINT        0x020           /* quad integer */
#else /* ifdef _NO_LONGLONG, make QUADINT equivalent to LONGINT, so
#else /* ifdef _NO_LONGLONG, make QUADINT equivalent to LONGINT, so
         that %lld behaves the same as %ld, not as %d, as expected if:
         that %lld behaves the same as %ld, not as %d, as expected if:
         sizeof (long long) = sizeof long > sizeof int  */
         sizeof (long long) = sizeof long > sizeof int  */
# define QUADINT        LONGINT
# define QUADINT        LONGINT
#endif
#endif
#define SHORTINT        0x040           /* short integer */
#define SHORTINT        0x040           /* short integer */
#define ZEROPAD         0x080           /* zero (as opposed to blank) pad */
#define ZEROPAD         0x080           /* zero (as opposed to blank) pad */
#define FPT             0x100           /* Floating point number */
#define FPT             0x100           /* Floating point number */
#ifdef _WANT_IO_C99_FORMATS
#ifdef _WANT_IO_C99_FORMATS
# define CHARINT        0x200           /* char as integer */
# define CHARINT        0x200           /* char as integer */
#else /* define as 0, to make SARG and UARG occupy fewer instructions  */
#else /* define as 0, to make SARG and UARG occupy fewer instructions  */
# define CHARINT        0
# define CHARINT        0
#endif
#endif
 
 
int _EXFUN(_VFPRINTF_R, (struct _reent *, FILE *, _CONST char *, va_list));
int _EXFUN(_VFPRINTF_R, (struct _reent *, FILE *, _CONST char *, va_list));
 
 
#ifndef STRING_ONLY
#ifndef STRING_ONLY
int
int
_DEFUN(VFPRINTF, (fp, fmt0, ap),
_DEFUN(VFPRINTF, (fp, fmt0, ap),
       FILE * fp         _AND
       FILE * fp         _AND
       _CONST char *fmt0 _AND
       _CONST char *fmt0 _AND
       va_list ap)
       va_list ap)
{
{
  int result;
  int result;
  result = _VFPRINTF_R (_REENT, fp, fmt0, ap);
  result = _VFPRINTF_R (_REENT, fp, fmt0, ap);
  return result;
  return result;
}
}
#endif /* STRING_ONLY */
#endif /* STRING_ONLY */
 
 
int
int
_DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap),
_DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap),
       struct _reent *data _AND
       struct _reent *data _AND
       FILE * fp           _AND
       FILE * fp           _AND
       _CONST char *fmt0   _AND
       _CONST char *fmt0   _AND
       va_list ap)
       va_list ap)
{
{
        register char *fmt;     /* format string */
        register char *fmt;     /* format string */
        register int ch;        /* character from fmt */
        register int ch;        /* character from fmt */
        register int n, m;      /* handy integers (short term usage) */
        register int n, m;      /* handy integers (short term usage) */
        register char *cp;      /* handy char pointer (short term usage) */
        register char *cp;      /* handy char pointer (short term usage) */
        register struct __siov *iovp;/* for PRINT macro */
        register struct __siov *iovp;/* for PRINT macro */
        register int flags;     /* flags as above */
        register int flags;     /* flags as above */
        char *fmt_anchor;       /* current format spec being processed */
        char *fmt_anchor;       /* current format spec being processed */
#ifndef _NO_POS_ARGS
#ifndef _NO_POS_ARGS
        int N;                  /* arg number */
        int N;                  /* arg number */
        int arg_index;          /* index into args processed directly */
        int arg_index;          /* index into args processed directly */
        int numargs;            /* number of varargs read */
        int numargs;            /* number of varargs read */
        char *saved_fmt;        /* saved fmt pointer */
        char *saved_fmt;        /* saved fmt pointer */
        union arg_val args[MAX_POS_ARGS];
        union arg_val args[MAX_POS_ARGS];
        int arg_type[MAX_POS_ARGS];
        int arg_type[MAX_POS_ARGS];
        int is_pos_arg;         /* is current format positional? */
        int is_pos_arg;         /* is current format positional? */
        int old_is_pos_arg;     /* is current format positional? */
        int old_is_pos_arg;     /* is current format positional? */
#endif
#endif
        int ret;                /* return value accumulator */
        int ret;                /* return value accumulator */
        int width;              /* width from format (%8d), or 0 */
        int width;              /* width from format (%8d), or 0 */
        int prec;               /* precision from format (%.3d), or -1 */
        int prec;               /* precision from format (%.3d), or -1 */
        char sign;              /* sign prefix (' ', '+', '-', or \0) */
        char sign;              /* sign prefix (' ', '+', '-', or \0) */
#ifdef FLOATING_POINT
#ifdef FLOATING_POINT
        char *decimal_point = _localeconv_r (data)->decimal_point;
        char *decimal_point = _localeconv_r (data)->decimal_point;
        size_t decp_len = strlen (decimal_point);
        size_t decp_len = strlen (decimal_point);
        char softsign;          /* temporary negative sign for floats */
        char softsign;          /* temporary negative sign for floats */
        union { int i; _PRINTF_FLOAT_TYPE fp; } _double_ = {0};
        union { int i; _PRINTF_FLOAT_TYPE fp; } _double_ = {0};
# define _fpvalue (_double_.fp)
# define _fpvalue (_double_.fp)
        int expt;               /* integer value of exponent */
        int expt;               /* integer value of exponent */
        int expsize = 0; /* character count for expstr */
        int expsize = 0; /* character count for expstr */
        int ndig = 0;            /* actual number of digits returned by cvt */
        int ndig = 0;            /* actual number of digits returned by cvt */
        char expstr[MAXEXPLEN]; /* buffer for exponent string */
        char expstr[MAXEXPLEN]; /* buffer for exponent string */
#endif /* FLOATING_POINT */
#endif /* FLOATING_POINT */
        u_quad_t _uquad;        /* integer arguments %[diouxX] */
        u_quad_t _uquad;        /* integer arguments %[diouxX] */
        enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */
        enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */
        int dprec;              /* a copy of prec if [diouxX], 0 otherwise */
        int dprec;              /* a copy of prec if [diouxX], 0 otherwise */
        int realsz;             /* field size expanded by dprec */
        int realsz;             /* field size expanded by dprec */
        int size;               /* size of converted field or string */
        int size;               /* size of converted field or string */
        char *xdigs = NULL;     /* digits for [xX] conversion */
        char *xdigs = NULL;     /* digits for [xX] conversion */
#define NIOV 8
#define NIOV 8
        struct __suio uio;      /* output information: summary */
        struct __suio uio;      /* output information: summary */
        struct __siov iov[NIOV];/* ... and individual io vectors */
        struct __siov iov[NIOV];/* ... and individual io vectors */
        char buf[BUF];          /* space for %c, %S, %[diouxX], %[aA] */
        char buf[BUF];          /* space for %c, %S, %[diouxX], %[aA] */
        char ox[2];             /* space for 0x hex-prefix */
        char ox[2];             /* space for 0x hex-prefix */
#ifdef _MB_CAPABLE
#ifdef _MB_CAPABLE
        wchar_t wc;
        wchar_t wc;
        mbstate_t state;        /* mbtowc calls from library must not change state */
        mbstate_t state;        /* mbtowc calls from library must not change state */
#endif
#endif
        char *malloc_buf = NULL;/* handy pointer for malloced buffers */
        char *malloc_buf = NULL;/* handy pointer for malloced buffers */
 
 
        /*
        /*
         * Choose PADSIZE to trade efficiency vs. size.  If larger printf
         * Choose PADSIZE to trade efficiency vs. size.  If larger printf
         * fields occur frequently, increase PADSIZE and make the initialisers
         * fields occur frequently, increase PADSIZE and make the initialisers
         * below longer.
         * below longer.
         */
         */
#define PADSIZE 16              /* pad chunk size */
#define PADSIZE 16              /* pad chunk size */
        static _CONST char blanks[PADSIZE] =
        static _CONST char blanks[PADSIZE] =
         {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
         {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
        static _CONST char zeroes[PADSIZE] =
        static _CONST char zeroes[PADSIZE] =
         {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
         {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'};
 
 
#ifdef _MB_CAPABLE
#ifdef _MB_CAPABLE
        memset (&state, '\0', sizeof (state));
        memset (&state, '\0', sizeof (state));
#endif
#endif
        /*
        /*
         * BEWARE, these `goto error' on error, and PAD uses `n'.
         * BEWARE, these `goto error' on error, and PAD uses `n'.
         */
         */
#define PRINT(ptr, len) { \
#define PRINT(ptr, len) { \
        iovp->iov_base = (ptr); \
        iovp->iov_base = (ptr); \
        iovp->iov_len = (len); \
        iovp->iov_len = (len); \
        uio.uio_resid += (len); \
        uio.uio_resid += (len); \
        iovp++; \
        iovp++; \
        if (++uio.uio_iovcnt >= NIOV) { \
        if (++uio.uio_iovcnt >= NIOV) { \
                if (__SPRINT(data, fp, &uio)) \
                if (__SPRINT(data, fp, &uio)) \
                        goto error; \
                        goto error; \
                iovp = iov; \
                iovp = iov; \
        } \
        } \
}
}
#define PAD(howmany, with) { \
#define PAD(howmany, with) { \
        if ((n = (howmany)) > 0) { \
        if ((n = (howmany)) > 0) { \
                while (n > PADSIZE) { \
                while (n > PADSIZE) { \
                        PRINT (with, PADSIZE); \
                        PRINT (with, PADSIZE); \
                        n -= PADSIZE; \
                        n -= PADSIZE; \
                } \
                } \
                PRINT (with, n); \
                PRINT (with, n); \
        } \
        } \
}
}
#define FLUSH() { \
#define FLUSH() { \
        if (uio.uio_resid && __SPRINT(data, fp, &uio)) \
        if (uio.uio_resid && __SPRINT(data, fp, &uio)) \
                goto error; \
                goto error; \
        uio.uio_iovcnt = 0; \
        uio.uio_iovcnt = 0; \
        iovp = iov; \
        iovp = iov; \
}
}
 
 
        /* Macros to support positional arguments */
        /* Macros to support positional arguments */
#ifndef _NO_POS_ARGS
#ifndef _NO_POS_ARGS
# define GET_ARG(n, ap, type)                                           \
# define GET_ARG(n, ap, type)                                           \
        (is_pos_arg                                                     \
        (is_pos_arg                                                     \
         ? (n < numargs                                                 \
         ? (n < numargs                                                 \
            ? args[n].val_##type                                        \
            ? args[n].val_##type                                        \
            : get_arg (data, n, fmt_anchor, &ap, &numargs, args,        \
            : get_arg (data, n, fmt_anchor, &ap, &numargs, args,        \
                       arg_type, &saved_fmt)->val_##type)               \
                       arg_type, &saved_fmt)->val_##type)               \
         : (arg_index++ < numargs                                       \
         : (arg_index++ < numargs                                       \
            ? args[n].val_##type                                        \
            ? args[n].val_##type                                        \
            : (numargs < MAX_POS_ARGS                                   \
            : (numargs < MAX_POS_ARGS                                   \
               ? args[numargs++].val_##type = va_arg (ap, type)         \
               ? args[numargs++].val_##type = va_arg (ap, type)         \
               : va_arg (ap, type))))
               : va_arg (ap, type))))
#else
#else
# define GET_ARG(n, ap, type) (va_arg (ap, type))
# define GET_ARG(n, ap, type) (va_arg (ap, type))
#endif
#endif
 
 
        /*
        /*
         * To extend shorts properly, we need both signed and unsigned
         * To extend shorts properly, we need both signed and unsigned
         * argument extraction methods.
         * argument extraction methods.
         */
         */
#ifndef _NO_LONGLONG
#ifndef _NO_LONGLONG
#define SARG() \
#define SARG() \
        (flags&QUADINT ? GET_ARG (N, ap, quad_t) : \
        (flags&QUADINT ? GET_ARG (N, ap, quad_t) : \
            flags&LONGINT ? GET_ARG (N, ap, long) : \
            flags&LONGINT ? GET_ARG (N, ap, long) : \
            flags&SHORTINT ? (long)(short)GET_ARG (N, ap, int) : \
            flags&SHORTINT ? (long)(short)GET_ARG (N, ap, int) : \
            flags&CHARINT ? (long)(signed char)GET_ARG (N, ap, int) : \
            flags&CHARINT ? (long)(signed char)GET_ARG (N, ap, int) : \
            (long)GET_ARG (N, ap, int))
            (long)GET_ARG (N, ap, int))
#define UARG() \
#define UARG() \
        (flags&QUADINT ? GET_ARG (N, ap, u_quad_t) : \
        (flags&QUADINT ? GET_ARG (N, ap, u_quad_t) : \
            flags&LONGINT ? GET_ARG (N, ap, u_long) : \
            flags&LONGINT ? GET_ARG (N, ap, u_long) : \
            flags&SHORTINT ? (u_long)(u_short)GET_ARG (N, ap, int) : \
            flags&SHORTINT ? (u_long)(u_short)GET_ARG (N, ap, int) : \
            flags&CHARINT ? (u_long)(unsigned char)GET_ARG (N, ap, int) : \
            flags&CHARINT ? (u_long)(unsigned char)GET_ARG (N, ap, int) : \
            (u_long)GET_ARG (N, ap, u_int))
            (u_long)GET_ARG (N, ap, u_int))
#else
#else
#define SARG() \
#define SARG() \
        (flags&LONGINT ? GET_ARG (N, ap, long) : \
        (flags&LONGINT ? GET_ARG (N, ap, long) : \
            flags&SHORTINT ? (long)(short)GET_ARG (N, ap, int) : \
            flags&SHORTINT ? (long)(short)GET_ARG (N, ap, int) : \
            flags&CHARINT ? (long)(signed char)GET_ARG (N, ap, int) : \
            flags&CHARINT ? (long)(signed char)GET_ARG (N, ap, int) : \
            (long)GET_ARG (N, ap, int))
            (long)GET_ARG (N, ap, int))
#define UARG() \
#define UARG() \
        (flags&LONGINT ? GET_ARG (N, ap, u_long) : \
        (flags&LONGINT ? GET_ARG (N, ap, u_long) : \
            flags&SHORTINT ? (u_long)(u_short)GET_ARG (N, ap, int) : \
            flags&SHORTINT ? (u_long)(u_short)GET_ARG (N, ap, int) : \
            flags&CHARINT ? (u_long)(unsigned char)GET_ARG (N, ap, int) : \
            flags&CHARINT ? (u_long)(unsigned char)GET_ARG (N, ap, int) : \
            (u_long)GET_ARG (N, ap, u_int))
            (u_long)GET_ARG (N, ap, u_int))
#endif
#endif
 
 
#ifndef STRING_ONLY
#ifndef STRING_ONLY
        /* Initialize std streams if not dealing with sprintf family.  */
        /* Initialize std streams if not dealing with sprintf family.  */
        CHECK_INIT (data, fp);
        CHECK_INIT (data, fp);
        _flockfile (fp);
        _flockfile (fp);
 
 
        ORIENT(fp, -1);
        ORIENT(fp, -1);
 
 
        /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
        /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
        if (cantwrite (data, fp)) {
        if (cantwrite (data, fp)) {
                _funlockfile (fp);
                _funlockfile (fp);
                return (EOF);
                return (EOF);
        }
        }
 
 
        /* optimise fprintf(stderr) (and other unbuffered Unix files) */
        /* optimise fprintf(stderr) (and other unbuffered Unix files) */
        if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
        if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
            fp->_file >= 0) {
            fp->_file >= 0) {
                _funlockfile (fp);
                _funlockfile (fp);
                return (__sbprintf (data, fp, fmt0, ap));
                return (__sbprintf (data, fp, fmt0, ap));
        }
        }
#else /* STRING_ONLY */
#else /* STRING_ONLY */
        /* Create initial buffer if we are called by asprintf family.  */
        /* Create initial buffer if we are called by asprintf family.  */
        if (fp->_flags & __SMBF && !fp->_bf._base)
        if (fp->_flags & __SMBF && !fp->_bf._base)
        {
        {
                fp->_bf._base = fp->_p = _malloc_r (data, 64);
                fp->_bf._base = fp->_p = _malloc_r (data, 64);
                if (!fp->_p)
                if (!fp->_p)
                {
                {
                        data->_errno = ENOMEM;
                        data->_errno = ENOMEM;
                        return EOF;
                        return EOF;
                }
                }
                fp->_bf._size = 64;
                fp->_bf._size = 64;
        }
        }
#endif /* STRING_ONLY */
#endif /* STRING_ONLY */
 
 
        fmt = (char *)fmt0;
        fmt = (char *)fmt0;
        uio.uio_iov = iovp = iov;
        uio.uio_iov = iovp = iov;
        uio.uio_resid = 0;
        uio.uio_resid = 0;
        uio.uio_iovcnt = 0;
        uio.uio_iovcnt = 0;
        ret = 0;
        ret = 0;
#ifndef _NO_POS_ARGS
#ifndef _NO_POS_ARGS
        arg_index = 0;
        arg_index = 0;
        saved_fmt = NULL;
        saved_fmt = NULL;
        arg_type[0] = -1;
        arg_type[0] = -1;
        numargs = 0;
        numargs = 0;
        is_pos_arg = 0;
        is_pos_arg = 0;
#endif
#endif
 
 
        /*
        /*
         * Scan the format for conversions (`%' character).
         * Scan the format for conversions (`%' character).
         */
         */
        for (;;) {
        for (;;) {
                cp = fmt;
                cp = fmt;
#ifdef _MB_CAPABLE
#ifdef _MB_CAPABLE
                while ((n = __mbtowc (data, &wc, fmt, MB_CUR_MAX,
                while ((n = __mbtowc (data, &wc, fmt, MB_CUR_MAX,
                                      __locale_charset (), &state)) > 0) {
                                      __locale_charset (), &state)) > 0) {
                    if (wc == '%')
                    if (wc == '%')
                        break;
                        break;
                    fmt += n;
                    fmt += n;
                }
                }
#else
#else
                while (*fmt != '\0' && *fmt != '%')
                while (*fmt != '\0' && *fmt != '%')
                    fmt += 1;
                    fmt += 1;
#endif
#endif
                if ((m = fmt - cp) != 0) {
                if ((m = fmt - cp) != 0) {
                        PRINT (cp, m);
                        PRINT (cp, m);
                        ret += m;
                        ret += m;
                }
                }
#ifdef _MB_CAPABLE
#ifdef _MB_CAPABLE
                if (n <= 0)
                if (n <= 0)
                    goto done;
                    goto done;
#else
#else
                if (*fmt == '\0')
                if (*fmt == '\0')
                    goto done;
                    goto done;
#endif
#endif
                fmt_anchor = fmt;
                fmt_anchor = fmt;
                fmt++;          /* skip over '%' */
                fmt++;          /* skip over '%' */
 
 
                flags = 0;
                flags = 0;
                dprec = 0;
                dprec = 0;
                width = 0;
                width = 0;
                prec = -1;
                prec = -1;
                sign = '\0';
                sign = '\0';
#ifndef _NO_POS_ARGS
#ifndef _NO_POS_ARGS
                N = arg_index;
                N = arg_index;
                is_pos_arg = 0;
                is_pos_arg = 0;
#endif
#endif
 
 
rflag:          ch = *fmt++;
rflag:          ch = *fmt++;
reswitch:       switch (ch) {
reswitch:       switch (ch) {
#ifdef _WANT_IO_C99_FORMATS
#ifdef _WANT_IO_C99_FORMATS
                case '\'':
                case '\'':
                  /* The ' flag is required by POSIX, but not C99.
                  /* The ' flag is required by POSIX, but not C99.
                     In the C locale, LC_NUMERIC requires
                     In the C locale, LC_NUMERIC requires
                     thousands_sep to be the empty string.  And since
                     thousands_sep to be the empty string.  And since
                     no other locales are supported (yet), this flag
                     no other locales are supported (yet), this flag
                     is currently a no-op.  */
                     is currently a no-op.  */
                  goto rflag;
                  goto rflag;
#endif
#endif
                case ' ':
                case ' ':
                        /*
                        /*
                         * ``If the space and + flags both appear, the space
                         * ``If the space and + flags both appear, the space
                         * flag will be ignored.''
                         * flag will be ignored.''
                         *      -- ANSI X3J11
                         *      -- ANSI X3J11
                         */
                         */
                        if (!sign)
                        if (!sign)
                                sign = ' ';
                                sign = ' ';
                        goto rflag;
                        goto rflag;
                case '#':
                case '#':
                        flags |= ALT;
                        flags |= ALT;
                        goto rflag;
                        goto rflag;
                case '*':
                case '*':
#ifndef _NO_POS_ARGS
#ifndef _NO_POS_ARGS
                        /* we must check for positional arg used for dynamic width */
                        /* we must check for positional arg used for dynamic width */
                        n = N;
                        n = N;
                        old_is_pos_arg = is_pos_arg;
                        old_is_pos_arg = is_pos_arg;
                        is_pos_arg = 0;
                        is_pos_arg = 0;
                        if (is_digit (*fmt)) {
                        if (is_digit (*fmt)) {
                                char *old_fmt = fmt;
                                char *old_fmt = fmt;
 
 
                                n = 0;
                                n = 0;
                                ch = *fmt++;
                                ch = *fmt++;
                                do {
                                do {
                                        n = 10 * n + to_digit (ch);
                                        n = 10 * n + to_digit (ch);
                                        ch = *fmt++;
                                        ch = *fmt++;
                                } while (is_digit (ch));
                                } while (is_digit (ch));
 
 
                                if (ch == '$') {
                                if (ch == '$') {
                                        if (n <= MAX_POS_ARGS) {
                                        if (n <= MAX_POS_ARGS) {
                                                n -= 1;
                                                n -= 1;
                                                is_pos_arg = 1;
                                                is_pos_arg = 1;
                                        }
                                        }
                                        else
                                        else
                                                goto error;
                                                goto error;
                                }
                                }
                                else {
                                else {
                                        fmt = old_fmt;
                                        fmt = old_fmt;
                                        goto rflag;
                                        goto rflag;
                                }
                                }
                        }
                        }
#endif /* !_NO_POS_ARGS */
#endif /* !_NO_POS_ARGS */
 
 
                        /*
                        /*
                         * ``A negative field width argument is taken as a
                         * ``A negative field width argument is taken as a
                         * - flag followed by a positive field width.''
                         * - flag followed by a positive field width.''
                         *      -- ANSI X3J11
                         *      -- ANSI X3J11
                         * They don't exclude field widths read from args.
                         * They don't exclude field widths read from args.
                         */
                         */
                        width = GET_ARG (n, ap, int);
                        width = GET_ARG (n, ap, int);
#ifndef _NO_POS_ARGS
#ifndef _NO_POS_ARGS
                        is_pos_arg = old_is_pos_arg;
                        is_pos_arg = old_is_pos_arg;
#endif
#endif
                        if (width >= 0)
                        if (width >= 0)
                                goto rflag;
                                goto rflag;
                        width = -width;
                        width = -width;
                        /* FALLTHROUGH */
                        /* FALLTHROUGH */
                case '-':
                case '-':
                        flags |= LADJUST;
                        flags |= LADJUST;
                        goto rflag;
                        goto rflag;
                case '+':
                case '+':
                        sign = '+';
                        sign = '+';
                        goto rflag;
                        goto rflag;
                case '.':
                case '.':
                        if ((ch = *fmt++) == '*') {
                        if ((ch = *fmt++) == '*') {
#ifndef _NO_POS_ARGS
#ifndef _NO_POS_ARGS
                                /* we must check for positional arg used for dynamic width */
                                /* we must check for positional arg used for dynamic width */
                                n = N;
                                n = N;
                                old_is_pos_arg = is_pos_arg;
                                old_is_pos_arg = is_pos_arg;
                                is_pos_arg = 0;
                                is_pos_arg = 0;
                                if (is_digit (*fmt)) {
                                if (is_digit (*fmt)) {
                                        char *old_fmt = fmt;
                                        char *old_fmt = fmt;
 
 
                                        n = 0;
                                        n = 0;
                                        ch = *fmt++;
                                        ch = *fmt++;
                                        do {
                                        do {
                                                n = 10 * n + to_digit (ch);
                                                n = 10 * n + to_digit (ch);
                                                ch = *fmt++;
                                                ch = *fmt++;
                                        } while (is_digit (ch));
                                        } while (is_digit (ch));
 
 
                                        if (ch == '$') {
                                        if (ch == '$') {
                                                if (n <= MAX_POS_ARGS) {
                                                if (n <= MAX_POS_ARGS) {
                                                        n -= 1;
                                                        n -= 1;
                                                        is_pos_arg = 1;
                                                        is_pos_arg = 1;
                                                }
                                                }
                                                else
                                                else
                                                        goto error;
                                                        goto error;
                                        }
                                        }
                                        else {
                                        else {
                                                fmt = old_fmt;
                                                fmt = old_fmt;
                                                goto rflag;
                                                goto rflag;
                                        }
                                        }
                                }
                                }
#endif /* !_NO_POS_ARGS */
#endif /* !_NO_POS_ARGS */
                                prec = GET_ARG (n, ap, int);
                                prec = GET_ARG (n, ap, int);
#ifndef _NO_POS_ARGS
#ifndef _NO_POS_ARGS
                                is_pos_arg = old_is_pos_arg;
                                is_pos_arg = old_is_pos_arg;
#endif
#endif
                                if (prec < 0)
                                if (prec < 0)
                                        prec = -1;
                                        prec = -1;
                                goto rflag;
                                goto rflag;
                        }
                        }
                        n = 0;
                        n = 0;
                        while (is_digit (ch)) {
                        while (is_digit (ch)) {
                                n = 10 * n + to_digit (ch);
                                n = 10 * n + to_digit (ch);
                                ch = *fmt++;
                                ch = *fmt++;
                        }
                        }
                        prec = n < 0 ? -1 : n;
                        prec = n < 0 ? -1 : n;
                        goto reswitch;
                        goto reswitch;
                case '0':
                case '0':
                        /*
                        /*
                         * ``Note that 0 is taken as a flag, not as the
                         * ``Note that 0 is taken as a flag, not as the
                         * beginning of a field width.''
                         * beginning of a field width.''
                         *      -- ANSI X3J11
                         *      -- ANSI X3J11
                         */
                         */
                        flags |= ZEROPAD;
                        flags |= ZEROPAD;
                        goto rflag;
                        goto rflag;
                case '1': case '2': case '3': case '4':
                case '1': case '2': case '3': case '4':
                case '5': case '6': case '7': case '8': case '9':
                case '5': case '6': case '7': case '8': case '9':
                        n = 0;
                        n = 0;
                        do {
                        do {
                                n = 10 * n + to_digit (ch);
                                n = 10 * n + to_digit (ch);
                                ch = *fmt++;
                                ch = *fmt++;
                        } while (is_digit (ch));
                        } while (is_digit (ch));
#ifndef _NO_POS_ARGS
#ifndef _NO_POS_ARGS
                        if (ch == '$') {
                        if (ch == '$') {
                                if (n <= MAX_POS_ARGS) {
                                if (n <= MAX_POS_ARGS) {
                                        N = n - 1;
                                        N = n - 1;
                                        is_pos_arg = 1;
                                        is_pos_arg = 1;
                                        goto rflag;
                                        goto rflag;
                                }
                                }
                                else
                                else
                                        goto error;
                                        goto error;
                        }
                        }
#endif /* !_NO_POS_ARGS */
#endif /* !_NO_POS_ARGS */
                        width = n;
                        width = n;
                        goto reswitch;
                        goto reswitch;
#ifdef FLOATING_POINT
#ifdef FLOATING_POINT
                case 'L':
                case 'L':
                        flags |= LONGDBL;
                        flags |= LONGDBL;
                        goto rflag;
                        goto rflag;
#endif
#endif
                case 'h':
                case 'h':
#ifdef _WANT_IO_C99_FORMATS
#ifdef _WANT_IO_C99_FORMATS
                        if (*fmt == 'h') {
                        if (*fmt == 'h') {
                                fmt++;
                                fmt++;
                                flags |= CHARINT;
                                flags |= CHARINT;
                        } else
                        } else
#endif
#endif
                                flags |= SHORTINT;
                                flags |= SHORTINT;
                        goto rflag;
                        goto rflag;
                case 'l':
                case 'l':
#if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG
#if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG
                        if (*fmt == 'l') {
                        if (*fmt == 'l') {
                                fmt++;
                                fmt++;
                                flags |= QUADINT;
                                flags |= QUADINT;
                        } else
                        } else
#endif
#endif
                                flags |= LONGINT;
                                flags |= LONGINT;
                        goto rflag;
                        goto rflag;
                case 'q': /* extension */
                case 'q': /* extension */
                        flags |= QUADINT;
                        flags |= QUADINT;
                        goto rflag;
                        goto rflag;
#ifdef _WANT_IO_C99_FORMATS
#ifdef _WANT_IO_C99_FORMATS
                case 'j':
                case 'j':
                  if (sizeof (intmax_t) == sizeof (long))
                  if (sizeof (intmax_t) == sizeof (long))
                    flags |= LONGINT;
                    flags |= LONGINT;
                  else
                  else
                    flags |= QUADINT;
                    flags |= QUADINT;
                  goto rflag;
                  goto rflag;
                case 'z':
                case 'z':
                  if (sizeof (size_t) < sizeof (int))
                  if (sizeof (size_t) < sizeof (int))
                    /* POSIX states size_t is 16 or more bits, as is short.  */
                    /* POSIX states size_t is 16 or more bits, as is short.  */
                    flags |= SHORTINT;
                    flags |= SHORTINT;
                  else if (sizeof (size_t) == sizeof (int))
                  else if (sizeof (size_t) == sizeof (int))
                    /* no flag needed */;
                    /* no flag needed */;
                  else if (sizeof (size_t) <= sizeof (long))
                  else if (sizeof (size_t) <= sizeof (long))
                    flags |= LONGINT;
                    flags |= LONGINT;
                  else
                  else
                    /* POSIX states that at least one programming
                    /* POSIX states that at least one programming
                       environment must support size_t no wider than
                       environment must support size_t no wider than
                       long, but that means other environments can
                       long, but that means other environments can
                       have size_t as wide as long long.  */
                       have size_t as wide as long long.  */
                    flags |= QUADINT;
                    flags |= QUADINT;
                  goto rflag;
                  goto rflag;
                case 't':
                case 't':
                  if (sizeof (ptrdiff_t) < sizeof (int))
                  if (sizeof (ptrdiff_t) < sizeof (int))
                    /* POSIX states ptrdiff_t is 16 or more bits, as
                    /* POSIX states ptrdiff_t is 16 or more bits, as
                       is short.  */
                       is short.  */
                    flags |= SHORTINT;
                    flags |= SHORTINT;
                  else if (sizeof (ptrdiff_t) == sizeof (int))
                  else if (sizeof (ptrdiff_t) == sizeof (int))
                    /* no flag needed */;
                    /* no flag needed */;
                  else if (sizeof (ptrdiff_t) <= sizeof (long))
                  else if (sizeof (ptrdiff_t) <= sizeof (long))
                    flags |= LONGINT;
                    flags |= LONGINT;
                  else
                  else
                    /* POSIX states that at least one programming
                    /* POSIX states that at least one programming
                       environment must support ptrdiff_t no wider than
                       environment must support ptrdiff_t no wider than
                       long, but that means other environments can
                       long, but that means other environments can
                       have ptrdiff_t as wide as long long.  */
                       have ptrdiff_t as wide as long long.  */
                    flags |= QUADINT;
                    flags |= QUADINT;
                  goto rflag;
                  goto rflag;
                case 'C':
                case 'C':
#endif /* _WANT_IO_C99_FORMATS */
#endif /* _WANT_IO_C99_FORMATS */
                case 'c':
                case 'c':
                        cp = buf;
                        cp = buf;
#ifdef _MB_CAPABLE
#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 */
#endif /* _MB_CAPABLE */
                        {
                        {
                                *cp = GET_ARG (N, ap, int);
                                *cp = GET_ARG (N, ap, int);
                                size = 1;
                                size = 1;
                        }
                        }
                        sign = '\0';
                        sign = '\0';
                        break;
                        break;
                case 'D':  /* extension */
                case 'D':  /* extension */
                        flags |= LONGINT;
                        flags |= LONGINT;
                        /*FALLTHROUGH*/
                        /*FALLTHROUGH*/
                case 'd':
                case 'd':
                case 'i':
                case 'i':
                        _uquad = SARG ();
                        _uquad = SARG ();
#ifndef _NO_LONGLONG
#ifndef _NO_LONGLONG
                        if ((quad_t)_uquad < 0)
                        if ((quad_t)_uquad < 0)
#else
#else
                        if ((long) _uquad < 0)
                        if ((long) _uquad < 0)
#endif
#endif
                        {
                        {
 
 
                                _uquad = -_uquad;
                                _uquad = -_uquad;
                                sign = '-';
                                sign = '-';
                        }
                        }
                        base = DEC;
                        base = DEC;
                        goto number;
                        goto number;
#ifdef FLOATING_POINT
#ifdef FLOATING_POINT
# ifdef _WANT_IO_C99_FORMATS
# ifdef _WANT_IO_C99_FORMATS
                case 'a':
                case 'a':
                case 'A':
                case 'A':
                case 'F':
                case 'F':
# endif
# endif
                case 'e':
                case 'e':
                case 'E':
                case 'E':
                case 'f':
                case 'f':
                case 'g':
                case 'g':
                case 'G':
                case 'G':
# ifdef _NO_LONGDBL
# ifdef _NO_LONGDBL
                        if (flags & LONGDBL) {
                        if (flags & LONGDBL) {
                                _fpvalue = (double) GET_ARG (N, ap, _LONG_DOUBLE);
                                _fpvalue = (double) GET_ARG (N, ap, _LONG_DOUBLE);
                        } else {
                        } else {
                                _fpvalue = GET_ARG (N, ap, double);
                                _fpvalue = GET_ARG (N, ap, double);
                        }
                        }
 
 
                        /* do this before tricky precision changes
                        /* do this before tricky precision changes
 
 
                           If the output is infinite or NaN, leading
                           If the output is infinite or NaN, leading
                           zeros are not permitted.  Otherwise, scanf
                           zeros are not permitted.  Otherwise, scanf
                           could not read what printf wrote.
                           could not read what printf wrote.
                         */
                         */
                        if (isinf (_fpvalue)) {
                        if (isinf (_fpvalue)) {
                                if (_fpvalue < 0)
                                if (_fpvalue < 0)
                                        sign = '-';
                                        sign = '-';
                                if (ch <= 'G') /* 'A', 'E', 'F', or 'G' */
                                if (ch <= 'G') /* 'A', 'E', 'F', or 'G' */
                                        cp = "INF";
                                        cp = "INF";
                                else
                                else
                                        cp = "inf";
                                        cp = "inf";
                                size = 3;
                                size = 3;
                                flags &= ~ZEROPAD;
                                flags &= ~ZEROPAD;
                                break;
                                break;
                        }
                        }
                        if (isnan (_fpvalue)) {
                        if (isnan (_fpvalue)) {
                                if (ch <= 'G') /* 'A', 'E', 'F', or 'G' */
                                if (ch <= 'G') /* 'A', 'E', 'F', or 'G' */
                                        cp = "NAN";
                                        cp = "NAN";
                                else
                                else
                                        cp = "nan";
                                        cp = "nan";
                                size = 3;
                                size = 3;
                                flags &= ~ZEROPAD;
                                flags &= ~ZEROPAD;
                                break;
                                break;
                        }
                        }
 
 
# else /* !_NO_LONGDBL */
# else /* !_NO_LONGDBL */
 
 
                        if (flags & LONGDBL) {
                        if (flags & LONGDBL) {
                                _fpvalue = GET_ARG (N, ap, _LONG_DOUBLE);
                                _fpvalue = GET_ARG (N, ap, _LONG_DOUBLE);
                        } else {
                        } else {
                                _fpvalue = (_LONG_DOUBLE)GET_ARG (N, ap, double);
                                _fpvalue = (_LONG_DOUBLE)GET_ARG (N, ap, double);
                        }
                        }
 
 
                        /* do this before tricky precision changes */
                        /* do this before tricky precision changes */
                        expt = _ldcheck (&_fpvalue);
                        expt = _ldcheck (&_fpvalue);
                        if (expt == 2) {
                        if (expt == 2) {
                                if (_fpvalue < 0)
                                if (_fpvalue < 0)
                                        sign = '-';
                                        sign = '-';
                                if (ch <= 'G') /* 'A', 'E', 'F', or 'G' */
                                if (ch <= 'G') /* 'A', 'E', 'F', or 'G' */
                                        cp = "INF";
                                        cp = "INF";
                                else
                                else
                                        cp = "inf";
                                        cp = "inf";
                                size = 3;
                                size = 3;
                                flags &= ~ZEROPAD;
                                flags &= ~ZEROPAD;
                                break;
                                break;
                        }
                        }
                        if (expt == 1) {
                        if (expt == 1) {
                                if (ch <= 'G') /* 'A', 'E', 'F', or 'G' */
                                if (ch <= 'G') /* 'A', 'E', 'F', or 'G' */
                                        cp = "NAN";
                                        cp = "NAN";
                                else
                                else
                                        cp = "nan";
                                        cp = "nan";
                                size = 3;
                                size = 3;
                                flags &= ~ZEROPAD;
                                flags &= ~ZEROPAD;
                                break;
                                break;
                        }
                        }
# endif /* !_NO_LONGDBL */
# endif /* !_NO_LONGDBL */
 
 
# ifdef _WANT_IO_C99_FORMATS
# ifdef _WANT_IO_C99_FORMATS
                        if (ch == 'a' || ch == 'A') {
                        if (ch == 'a' || ch == 'A') {
                                ox[0] = '0';
                                ox[0] = '0';
                                ox[1] = ch == 'a' ? 'x' : 'X';
                                ox[1] = ch == 'a' ? 'x' : 'X';
                                flags |= HEXPREFIX;
                                flags |= HEXPREFIX;
                                if (prec >= BUF)
                                if (prec >= BUF)
                                  {
                                  {
                                    if ((malloc_buf =
                                    if ((malloc_buf =
                                         (char *)_malloc_r (data, prec + 1))
                                         (char *)_malloc_r (data, prec + 1))
                                        == NULL)
                                        == NULL)
                                      {
                                      {
                                        fp->_flags |= __SERR;
                                        fp->_flags |= __SERR;
                                        goto error;
                                        goto error;
                                      }
                                      }
                                    cp = malloc_buf;
                                    cp = malloc_buf;
                                  }
                                  }
                                else
                                else
                                  cp = buf;
                                  cp = buf;
                        } else
                        } else
# endif /* _WANT_IO_C99_FORMATS */
# endif /* _WANT_IO_C99_FORMATS */
                        if (prec == -1) {
                        if (prec == -1) {
                                prec = DEFPREC;
                                prec = DEFPREC;
                        } else if ((ch == 'g' || ch == 'G') && prec == 0) {
                        } else if ((ch == 'g' || ch == 'G') && prec == 0) {
                                prec = 1;
                                prec = 1;
                        }
                        }
 
 
                        flags |= FPT;
                        flags |= FPT;
 
 
                        cp = cvt (data, _fpvalue, prec, flags, &softsign,
                        cp = cvt (data, _fpvalue, prec, flags, &softsign,
                                  &expt, ch, &ndig, cp);
                                  &expt, ch, &ndig, cp);
 
 
                        if (ch == 'g' || ch == 'G') {
                        if (ch == 'g' || ch == 'G') {
                                if (expt <= -4 || expt > prec)
                                if (expt <= -4 || expt > prec)
                                        ch -= 2; /* 'e' or 'E' */
                                        ch -= 2; /* 'e' or 'E' */
                                else
                                else
                                        ch = 'g';
                                        ch = 'g';
                        }
                        }
# ifdef _WANT_IO_C99_FORMATS
# ifdef _WANT_IO_C99_FORMATS
                        else if (ch == 'F')
                        else if (ch == 'F')
                                ch = 'f';
                                ch = 'f';
# endif
# endif
                        if (ch <= 'e') {        /* 'a', 'A', 'e', or 'E' fmt */
                        if (ch <= 'e') {        /* 'a', 'A', 'e', or 'E' fmt */
                                --expt;
                                --expt;
                                expsize = exponent (expstr, expt, ch);
                                expsize = exponent (expstr, expt, ch);
                                size = expsize + ndig;
                                size = expsize + ndig;
                                if (ndig > 1 || flags & ALT)
                                if (ndig > 1 || flags & ALT)
                                        ++size;
                                        ++size;
                        } else if (ch == 'f') {         /* f fmt */
                        } else if (ch == 'f') {         /* f fmt */
                                if (expt > 0) {
                                if (expt > 0) {
                                        size = expt;
                                        size = expt;
                                        if (prec || flags & ALT)
                                        if (prec || flags & ALT)
                                                size += prec + 1;
                                                size += prec + 1;
                                } else  /* "0.X" */
                                } else  /* "0.X" */
                                        size = (prec || flags & ALT)
                                        size = (prec || flags & ALT)
                                                  ? prec + 2
                                                  ? prec + 2
                                                  : 1;
                                                  : 1;
                        } else if (expt >= ndig) {      /* fixed g fmt */
                        } else if (expt >= ndig) {      /* fixed g fmt */
                                size = expt;
                                size = expt;
                                if (flags & ALT)
                                if (flags & ALT)
                                        ++size;
                                        ++size;
                        } else
                        } else
                                size = ndig + (expt > 0 ?
                                size = ndig + (expt > 0 ?
                                        1 : 2 - expt);
                                        1 : 2 - expt);
 
 
                        if (softsign)
                        if (softsign)
                                sign = '-';
                                sign = '-';
                        break;
                        break;
#endif /* FLOATING_POINT */
#endif /* FLOATING_POINT */
                case 'n':
                case 'n':
#ifndef _NO_LONGLONG
#ifndef _NO_LONGLONG
                        if (flags & QUADINT)
                        if (flags & QUADINT)
                                *GET_ARG (N, ap, quad_ptr_t) = ret;
                                *GET_ARG (N, ap, quad_ptr_t) = ret;
                        else
                        else
#endif
#endif
                        if (flags & LONGINT)
                        if (flags & LONGINT)
                                *GET_ARG (N, ap, long_ptr_t) = ret;
                                *GET_ARG (N, ap, long_ptr_t) = ret;
                        else if (flags & SHORTINT)
                        else if (flags & SHORTINT)
                                *GET_ARG (N, ap, short_ptr_t) = ret;
                                *GET_ARG (N, ap, short_ptr_t) = ret;
#ifdef _WANT_IO_C99_FORMATS
#ifdef _WANT_IO_C99_FORMATS
                        else if (flags & CHARINT)
                        else if (flags & CHARINT)
                                *GET_ARG (N, ap, char_ptr_t) = ret;
                                *GET_ARG (N, ap, char_ptr_t) = ret;
#endif
#endif
                        else
                        else
                                *GET_ARG (N, ap, int_ptr_t) = ret;
                                *GET_ARG (N, ap, int_ptr_t) = ret;
                        continue;       /* no output */
                        continue;       /* no output */
                case 'O': /* extension */
                case 'O': /* extension */
                        flags |= LONGINT;
                        flags |= LONGINT;
                        /*FALLTHROUGH*/
                        /*FALLTHROUGH*/
                case 'o':
                case 'o':
                        _uquad = UARG ();
                        _uquad = UARG ();
                        base = OCT;
                        base = OCT;
                        goto nosign;
                        goto nosign;
                case 'p':
                case 'p':
                        /*
                        /*
                         * ``The argument shall be a pointer to void.  The
                         * ``The argument shall be a pointer to void.  The
                         * value of the pointer is converted to a sequence
                         * value of the pointer is converted to a sequence
                         * of printable characters, in an implementation-
                         * of printable characters, in an implementation-
                         * defined manner.''
                         * defined manner.''
                         *      -- ANSI X3J11
                         *      -- ANSI X3J11
                         */
                         */
                        /* NOSTRICT */
                        /* NOSTRICT */
                        _uquad = (uintptr_t) GET_ARG (N, ap, void_ptr_t);
                        _uquad = (uintptr_t) GET_ARG (N, ap, void_ptr_t);
                        base = HEX;
                        base = HEX;
                        xdigs = "0123456789abcdef";
                        xdigs = "0123456789abcdef";
                        flags |= HEXPREFIX;
                        flags |= HEXPREFIX;
                        ox[0] = '0';
                        ox[0] = '0';
                        ox[1] = ch = 'x';
                        ox[1] = ch = 'x';
                        goto nosign;
                        goto nosign;
                case 's':
                case 's':
#ifdef _WANT_IO_C99_FORMATS
#ifdef _WANT_IO_C99_FORMATS
                case 'S':
                case 'S':
#endif
#endif
                        sign = '\0';
                        sign = '\0';
                        cp = GET_ARG (N, ap, char_ptr_t);
                        cp = GET_ARG (N, ap, char_ptr_t);
#ifndef __OPTIMIZE_SIZE__
#ifndef __OPTIMIZE_SIZE__
                        /* Behavior is undefined if the user passed a
                        /* Behavior is undefined if the user passed a
                           NULL string when precision is not 0.
                           NULL string when precision is not 0.
                           However, if we are not optimizing for size,
                           However, if we are not optimizing for size,
                           we might as well mirror glibc behavior.  */
                           we might as well mirror glibc behavior.  */
                        if (cp == NULL) {
                        if (cp == NULL) {
                                cp = "(null)";
                                cp = "(null)";
                                size = ((unsigned) prec > 6U) ? 6 : prec;
                                size = ((unsigned) prec > 6U) ? 6 : prec;
                        }
                        }
                        else
                        else
#endif /* __OPTIMIZE_SIZE__ */
#endif /* __OPTIMIZE_SIZE__ */
#ifdef _MB_CAPABLE
#ifdef _MB_CAPABLE
                        if (ch == 'S' || (flags & LONGINT)) {
                        if (ch == 'S' || (flags & LONGINT)) {
                                mbstate_t ps;
                                mbstate_t ps;
                                _CONST wchar_t *wcp;
                                _CONST wchar_t *wcp;
 
 
                                wcp = (_CONST wchar_t *)cp;
                                wcp = (_CONST wchar_t *)cp;
                                size = m = 0;
                                size = m = 0;
                                memset ((_PTR)&ps, '\0', sizeof (mbstate_t));
                                memset ((_PTR)&ps, '\0', sizeof (mbstate_t));
 
 
                                /* 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;
                                                if ((n = (int)_wcrtomb_r (data,
                                                if ((n = (int)_wcrtomb_r (data,
                                                     buf, wcp[m], &ps)) == -1) {
                                                     buf, wcp[m], &ps)) == -1) {
                                                        fp->_flags |= __SERR;
                                                        fp->_flags |= __SERR;
                                                        goto error;
                                                        goto error;
                                                }
                                                }
                                                if (n + size > prec)
                                                if (n + size > prec)
                                                        break;
                                                        break;
                                                m += 1;
                                                m += 1;
                                                size += n;
                                                size += n;
                                                if (size == prec)
                                                if (size == prec)
                                                        break;
                                                        break;
                                        }
                                        }
                                }
                                }
                                else {
                                else {
                                        if ((size = (int)_wcsrtombs_r (data,
                                        if ((size = (int)_wcsrtombs_r (data,
                                                   NULL, &wcp, 0, &ps)) == -1) {
                                                   NULL, &wcp, 0, &ps)) == -1) {
                                                fp->_flags |= __SERR;
                                                fp->_flags |= __SERR;
                                                goto error;
                                                goto error;
                                        }
                                        }
                                        wcp = (_CONST wchar_t *)cp;
                                        wcp = (_CONST wchar_t *)cp;
                                }
                                }
 
 
                                if (size == 0)
                                if (size == 0)
                                        break;
                                        break;
 
 
                                if (size >= BUF) {
                                if (size >= BUF) {
                                        if ((malloc_buf =
                                        if ((malloc_buf =
                                             (char *)_malloc_r (data, size + 1))
                                             (char *)_malloc_r (data, size + 1))
                                            == NULL) {
                                            == NULL) {
                                                fp->_flags |= __SERR;
                                                fp->_flags |= __SERR;
                                                goto error;
                                                goto error;
                                        }
                                        }
                                        cp = malloc_buf;
                                        cp = malloc_buf;
                                } else
                                } else
                                        cp = buf;
                                        cp = buf;
 
 
                                /* Convert widechar string to multibyte string. */
                                /* Convert widechar string to multibyte string. */
                                memset ((_PTR)&ps, '\0', sizeof (mbstate_t));
                                memset ((_PTR)&ps, '\0', sizeof (mbstate_t));
                                if (_wcsrtombs_r (data, cp, &wcp, size, &ps)
                                if (_wcsrtombs_r (data, cp, &wcp, size, &ps)
                                    != size) {
                                    != size) {
                                        fp->_flags |= __SERR;
                                        fp->_flags |= __SERR;
                                        goto error;
                                        goto error;
                                }
                                }
                                cp[size] = '\0';
                                cp[size] = '\0';
                        }
                        }
                        else
                        else
#endif /* _MB_CAPABLE */
#endif /* _MB_CAPABLE */
                        if (prec >= 0) {
                        if (prec >= 0) {
                                /*
                                /*
                                 * can't use strlen; can only look for the
                                 * can't use strlen; can only look for the
                                 * NUL in the first `prec' characters, and
                                 * NUL in the first `prec' characters, and
                                 * strlen () will go further.
                                 * strlen () will go further.
                                 */
                                 */
                                char *p = memchr (cp, 0, prec);
                                char *p = memchr (cp, 0, prec);
 
 
                                if (p != NULL) {
                                if (p != NULL) {
                                        size = p - cp;
                                        size = p - cp;
                                        if (size > prec)
                                        if (size > prec)
                                                size = prec;
                                                size = prec;
                                } else
                                } else
                                        size = prec;
                                        size = prec;
                        } else
                        } else
                                size = strlen (cp);
                                size = strlen (cp);
 
 
                        break;
                        break;
                case 'U': /* extension */
                case 'U': /* extension */
                        flags |= LONGINT;
                        flags |= LONGINT;
                        /*FALLTHROUGH*/
                        /*FALLTHROUGH*/
                case 'u':
                case 'u':
                        _uquad = UARG ();
                        _uquad = UARG ();
                        base = DEC;
                        base = DEC;
                        goto nosign;
                        goto nosign;
                case 'X':
                case 'X':
                        xdigs = "0123456789ABCDEF";
                        xdigs = "0123456789ABCDEF";
                        goto hex;
                        goto hex;
                case 'x':
                case 'x':
                        xdigs = "0123456789abcdef";
                        xdigs = "0123456789abcdef";
hex:                    _uquad = UARG ();
hex:                    _uquad = UARG ();
                        base = HEX;
                        base = HEX;
                        /* leading 0x/X only if non-zero */
                        /* leading 0x/X only if non-zero */
                        if (flags & ALT && _uquad != 0) {
                        if (flags & ALT && _uquad != 0) {
                                ox[0] = '0';
                                ox[0] = '0';
                                ox[1] = ch;
                                ox[1] = ch;
                                flags |= HEXPREFIX;
                                flags |= HEXPREFIX;
                        }
                        }
 
 
                        /* unsigned conversions */
                        /* unsigned conversions */
nosign:                 sign = '\0';
nosign:                 sign = '\0';
                        /*
                        /*
                         * ``... diouXx conversions ... if a precision is
                         * ``... diouXx conversions ... if a precision is
                         * specified, the 0 flag will be ignored.''
                         * specified, the 0 flag will be ignored.''
                         *      -- ANSI X3J11
                         *      -- ANSI X3J11
                         */
                         */
number:                 if ((dprec = prec) >= 0)
number:                 if ((dprec = prec) >= 0)
                                flags &= ~ZEROPAD;
                                flags &= ~ZEROPAD;
 
 
                        /*
                        /*
                         * ``The result of converting a zero value with an
                         * ``The result of converting a zero value with an
                         * explicit precision of zero is no characters.''
                         * explicit precision of zero is no characters.''
                         *      -- ANSI X3J11
                         *      -- ANSI X3J11
                         */
                         */
                        cp = buf + BUF;
                        cp = buf + BUF;
                        if (_uquad != 0 || prec != 0) {
                        if (_uquad != 0 || prec != 0) {
                                /*
                                /*
                                 * Unsigned mod is hard, and unsigned mod
                                 * Unsigned mod is hard, and unsigned mod
                                 * by a constant is easier than that by
                                 * by a constant is easier than that by
                                 * a variable; hence this switch.
                                 * a variable; hence this switch.
                                 */
                                 */
                                switch (base) {
                                switch (base) {
                                case OCT:
                                case OCT:
                                        do {
                                        do {
                                                *--cp = to_char (_uquad & 7);
                                                *--cp = to_char (_uquad & 7);
                                                _uquad >>= 3;
                                                _uquad >>= 3;
                                        } while (_uquad);
                                        } while (_uquad);
                                        /* handle octal leading 0 */
                                        /* handle octal leading 0 */
                                        if (flags & ALT && *cp != '0')
                                        if (flags & ALT && *cp != '0')
                                                *--cp = '0';
                                                *--cp = '0';
                                        break;
                                        break;
 
 
                                case DEC:
                                case DEC:
                                        /* many numbers are 1 digit */
                                        /* many numbers are 1 digit */
                                        while (_uquad >= 10) {
                                        while (_uquad >= 10) {
                                                *--cp = to_char (_uquad % 10);
                                                *--cp = to_char (_uquad % 10);
                                                _uquad /= 10;
                                                _uquad /= 10;
                                        }
                                        }
                                        *--cp = to_char (_uquad);
                                        *--cp = to_char (_uquad);
                                        break;
                                        break;
 
 
                                case HEX:
                                case HEX:
                                        do {
                                        do {
                                                *--cp = xdigs[_uquad & 15];
                                                *--cp = xdigs[_uquad & 15];
                                                _uquad >>= 4;
                                                _uquad >>= 4;
                                        } while (_uquad);
                                        } while (_uquad);
                                        break;
                                        break;
 
 
                                default:
                                default:
                                        cp = "bug in vfprintf: bad base";
                                        cp = "bug in vfprintf: bad base";
                                        size = strlen (cp);
                                        size = strlen (cp);
                                        goto skipsize;
                                        goto skipsize;
                                }
                                }
                        }
                        }
                       /*
                       /*
                        * ...result is to be converted to an 'alternate form'.
                        * ...result is to be converted to an 'alternate form'.
                        * For o conversion, it increases the precision to force
                        * For o conversion, it increases the precision to force
                        * the first digit of the result to be a zero."
                        * the first digit of the result to be a zero."
                        *     -- ANSI X3J11
                        *     -- ANSI X3J11
                        *
                        *
                        * To demonstrate this case, compile and run:
                        * To demonstrate this case, compile and run:
                        *    printf ("%#.0o",0);
                        *    printf ("%#.0o",0);
                        */
                        */
                       else if (base == OCT && (flags & ALT))
                       else if (base == OCT && (flags & ALT))
                         *--cp = '0';
                         *--cp = '0';
 
 
                        size = buf + BUF - cp;
                        size = buf + BUF - cp;
                skipsize:
                skipsize:
                        break;
                        break;
                default:        /* "%?" prints ?, unless ? is NUL */
                default:        /* "%?" prints ?, unless ? is NUL */
                        if (ch == '\0')
                        if (ch == '\0')
                                goto done;
                                goto done;
                        /* pretend it was %c with argument ch */
                        /* pretend it was %c with argument ch */
                        cp = buf;
                        cp = buf;
                        *cp = ch;
                        *cp = ch;
                        size = 1;
                        size = 1;
                        sign = '\0';
                        sign = '\0';
                        break;
                        break;
                }
                }
 
 
                /*
                /*
                 * All reasonable formats wind up here.  At this point, `cp'
                 * All reasonable formats wind up here.  At this point, `cp'
                 * points to a string which (if not flags&LADJUST) should be
                 * points to a string which (if not flags&LADJUST) should be
                 * padded out to `width' places.  If flags&ZEROPAD, it should
                 * padded out to `width' places.  If flags&ZEROPAD, it should
                 * first be prefixed by any sign or other prefix; otherwise,
                 * first be prefixed by any sign or other prefix; otherwise,
                 * it should be blank padded before the prefix is emitted.
                 * it should be blank padded before the prefix is emitted.
                 * After any left-hand padding and prefixing, emit zeroes
                 * After any left-hand padding and prefixing, emit zeroes
                 * required by a decimal [diouxX] precision, then print the
                 * required by a decimal [diouxX] precision, then print the
                 * string proper, then emit zeroes required by any leftover
                 * string proper, then emit zeroes required by any leftover
                 * floating precision; finally, if LADJUST, pad with blanks.
                 * floating precision; finally, if LADJUST, pad with blanks.
                 * If flags&FPT, ch must be in [aAeEfg].
                 * If flags&FPT, ch must be in [aAeEfg].
                 *
                 *
                 * Compute actual size, so we know how much to pad.
                 * Compute actual size, so we know how much to pad.
                 * size excludes decimal prec; realsz includes it.
                 * size excludes decimal prec; realsz includes it.
                 */
                 */
                realsz = dprec > size ? dprec : size;
                realsz = dprec > size ? dprec : size;
                if (sign)
                if (sign)
                        realsz++;
                        realsz++;
                if (flags & HEXPREFIX)
                if (flags & HEXPREFIX)
                        realsz+= 2;
                        realsz+= 2;
 
 
                /* right-adjusting blank padding */
                /* right-adjusting blank padding */
                if ((flags & (LADJUST|ZEROPAD)) == 0)
                if ((flags & (LADJUST|ZEROPAD)) == 0)
                        PAD (width - realsz, blanks);
                        PAD (width - realsz, blanks);
 
 
                /* prefix */
                /* prefix */
                if (sign)
                if (sign)
                        PRINT (&sign, 1);
                        PRINT (&sign, 1);
                if (flags & HEXPREFIX)
                if (flags & HEXPREFIX)
                        PRINT (ox, 2);
                        PRINT (ox, 2);
 
 
                /* right-adjusting zero padding */
                /* right-adjusting zero padding */
                if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
                if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
                        PAD (width - realsz, zeroes);
                        PAD (width - realsz, zeroes);
 
 
                /* leading zeroes from decimal precision */
                /* leading zeroes from decimal precision */
                PAD (dprec - size, zeroes);
                PAD (dprec - size, zeroes);
 
 
                /* the string or number proper */
                /* the string or number proper */
#ifdef FLOATING_POINT
#ifdef FLOATING_POINT
                if ((flags & FPT) == 0) {
                if ((flags & FPT) == 0) {
                        PRINT (cp, size);
                        PRINT (cp, size);
                } else {        /* glue together f_p fragments */
                } else {        /* glue together f_p fragments */
                        if (ch >= 'f') {        /* 'f' or 'g' */
                        if (ch >= 'f') {        /* 'f' or 'g' */
                                if (_fpvalue == 0) {
                                if (_fpvalue == 0) {
                                        /* kludge for __dtoa irregularity */
                                        /* kludge for __dtoa irregularity */
                                        PRINT ("0", 1);
                                        PRINT ("0", 1);
                                        if (expt < ndig || flags & ALT) {
                                        if (expt < ndig || flags & ALT) {
                                                PRINT (decimal_point, decp_len);
                                                PRINT (decimal_point, decp_len);
                                                PAD (ndig - 1, zeroes);
                                                PAD (ndig - 1, zeroes);
                                        }
                                        }
                                } else if (expt <= 0) {
                                } else if (expt <= 0) {
                                        PRINT ("0", 1);
                                        PRINT ("0", 1);
                                        if (expt || ndig || flags & ALT) {
                                        if (expt || ndig || flags & ALT) {
                                                PRINT (decimal_point, decp_len);
                                                PRINT (decimal_point, decp_len);
                                                PAD (-expt, zeroes);
                                                PAD (-expt, zeroes);
                                                PRINT (cp, ndig);
                                                PRINT (cp, ndig);
                                        }
                                        }
                                } else if (expt >= ndig) {
                                } else if (expt >= ndig) {
                                        PRINT (cp, ndig);
                                        PRINT (cp, ndig);
                                        PAD (expt - ndig, zeroes);
                                        PAD (expt - ndig, zeroes);
                                        if (flags & ALT)
                                        if (flags & ALT)
                                                PRINT (decimal_point, decp_len);
                                                PRINT (decimal_point, decp_len);
                                } else {
                                } else {
                                        PRINT (cp, expt);
                                        PRINT (cp, expt);
                                        cp += expt;
                                        cp += expt;
                                        PRINT (decimal_point, decp_len);
                                        PRINT (decimal_point, decp_len);
                                        PRINT (cp, ndig - expt);
                                        PRINT (cp, ndig - expt);
                                }
                                }
                        } else {        /* 'a', 'A', 'e', or 'E' */
                        } else {        /* 'a', 'A', 'e', or 'E' */
                                if (ndig > 1 || flags & ALT) {
                                if (ndig > 1 || flags & ALT) {
                                        PRINT (cp, 1);
                                        PRINT (cp, 1);
                                        cp++;
                                        cp++;
                                        PRINT (decimal_point, decp_len);
                                        PRINT (decimal_point, decp_len);
                                        if (_fpvalue) {
                                        if (_fpvalue) {
                                                PRINT (cp, ndig - 1);
                                                PRINT (cp, ndig - 1);
                                        } else  /* 0.[0..] */
                                        } else  /* 0.[0..] */
                                                /* __dtoa irregularity */
                                                /* __dtoa irregularity */
                                                PAD (ndig - 1, zeroes);
                                                PAD (ndig - 1, zeroes);
                                } else  /* XeYYY */
                                } else  /* XeYYY */
                                        PRINT (cp, 1);
                                        PRINT (cp, 1);
                                PRINT (expstr, expsize);
                                PRINT (expstr, expsize);
                        }
                        }
                }
                }
#else /* !FLOATING_POINT */
#else /* !FLOATING_POINT */
                PRINT (cp, size);
                PRINT (cp, size);
#endif
#endif
                /* left-adjusting padding (always blank) */
                /* left-adjusting padding (always blank) */
                if (flags & LADJUST)
                if (flags & LADJUST)
                        PAD (width - realsz, blanks);
                        PAD (width - realsz, blanks);
 
 
                /* finally, adjust ret */
                /* finally, adjust ret */
                ret += width > realsz ? width : realsz;
                ret += width > realsz ? width : realsz;
 
 
                FLUSH ();       /* copy out the I/O vectors */
                FLUSH ();       /* copy out the I/O vectors */
 
 
                if (malloc_buf != NULL) {
                if (malloc_buf != NULL) {
                        _free_r (data, malloc_buf);
                        _free_r (data, malloc_buf);
                        malloc_buf = NULL;
                        malloc_buf = NULL;
                }
                }
        }
        }
done:
done:
        FLUSH ();
        FLUSH ();
error:
error:
        if (malloc_buf != NULL)
        if (malloc_buf != NULL)
                _free_r (data, malloc_buf);
                _free_r (data, malloc_buf);
#ifndef STRING_ONLY
#ifndef STRING_ONLY
        _funlockfile (fp);
        _funlockfile (fp);
#endif
#endif
        return (__sferror (fp) ? EOF : ret);
        return (__sferror (fp) ? EOF : ret);
        /* NOTREACHED */
        /* NOTREACHED */
}
}
 
 
#ifdef FLOATING_POINT
#ifdef FLOATING_POINT
 
 
/* Using reentrant DATA, convert finite VALUE into a string of digits
/* Using reentrant DATA, convert finite VALUE into a string of digits
   with no decimal point, using NDIGITS precision and FLAGS as guides
   with no decimal point, using NDIGITS precision and FLAGS as guides
   to whether trailing zeros must be included.  Set *SIGN to nonzero
   to whether trailing zeros must be included.  Set *SIGN to nonzero
   if VALUE was negative.  Set *DECPT to the exponent plus one.  Set
   if VALUE was negative.  Set *DECPT to the exponent plus one.  Set
   *LENGTH to the length of the returned string.  CH must be one of
   *LENGTH to the length of the returned string.  CH must be one of
   [aAeEfFgG]; if it is [aA], then the return string lives in BUF,
   [aAeEfFgG]; if it is [aA], then the return string lives in BUF,
   otherwise the return value shares the mprec reentrant storage.  */
   otherwise the return value shares the mprec reentrant storage.  */
static char *
static char *
cvt(struct _reent *data, _PRINTF_FLOAT_TYPE value, int ndigits, int flags,
cvt(struct _reent *data, _PRINTF_FLOAT_TYPE value, int ndigits, int flags,
    char *sign, int *decpt, int ch, int *length, char *buf)
    char *sign, int *decpt, int ch, int *length, char *buf)
{
{
        int mode, dsgn;
        int mode, dsgn;
        char *digits, *bp, *rve;
        char *digits, *bp, *rve;
# ifdef _NO_LONGDBL
# ifdef _NO_LONGDBL
        union double_union tmp;
        union double_union tmp;
 
 
        tmp.d = value;
        tmp.d = value;
        if (word0 (tmp) & Sign_bit) { /* this will check for < 0 and -0.0 */
        if (word0 (tmp) & Sign_bit) { /* this will check for < 0 and -0.0 */
                value = -value;
                value = -value;
                *sign = '-';
                *sign = '-';
        } else
        } else
                *sign = '\000';
                *sign = '\000';
# else /* !_NO_LONGDBL */
# else /* !_NO_LONGDBL */
        union
        union
        {
        {
          struct ldieee ieee;
          struct ldieee ieee;
          _LONG_DOUBLE val;
          _LONG_DOUBLE val;
        } ld;
        } ld;
 
 
        ld.val = value;
        ld.val = value;
        if (ld.ieee.sign) { /* this will check for < 0 and -0.0 */
        if (ld.ieee.sign) { /* this will check for < 0 and -0.0 */
                value = -value;
                value = -value;
                *sign = '-';
                *sign = '-';
        } else
        } else
                *sign = '\000';
                *sign = '\000';
# endif /* !_NO_LONGDBL */
# endif /* !_NO_LONGDBL */
 
 
# ifdef _WANT_IO_C99_FORMATS
# ifdef _WANT_IO_C99_FORMATS
        if (ch == 'a' || ch == 'A') {
        if (ch == 'a' || ch == 'A') {
                /* This code assumes FLT_RADIX is a power of 2.  The initial
                /* This code assumes FLT_RADIX is a power of 2.  The initial
                   division ensures the digit before the decimal will be less
                   division ensures the digit before the decimal will be less
                   than FLT_RADIX (unless it is rounded later).  There is no
                   than FLT_RADIX (unless it is rounded later).  There is no
                   loss of precision in these calculations.  */
                   loss of precision in these calculations.  */
                value = FREXP (value, decpt) / 8;
                value = FREXP (value, decpt) / 8;
                if (!value)
                if (!value)
                        *decpt = 1;
                        *decpt = 1;
                digits = ch == 'a' ? "0123456789abcdef" : "0123456789ABCDEF";
                digits = ch == 'a' ? "0123456789abcdef" : "0123456789ABCDEF";
                bp = buf;
                bp = buf;
                do {
                do {
                        value *= 16;
                        value *= 16;
                        mode = (int) value;
                        mode = (int) value;
                        value -= mode;
                        value -= mode;
                        *bp++ = digits[mode];
                        *bp++ = digits[mode];
                } while (ndigits-- && value);
                } while (ndigits-- && value);
                if (value > 0.5 || (value == 0.5 && mode & 1)) {
                if (value > 0.5 || (value == 0.5 && mode & 1)) {
                        /* round to even */
                        /* round to even */
                        rve = bp;
                        rve = bp;
                        while (*--rve == digits[0xf]) {
                        while (*--rve == digits[0xf]) {
                                *rve = '0';
                                *rve = '0';
                        }
                        }
                        *rve = *rve == '9' ? digits[0xa] : *rve + 1;
                        *rve = *rve == '9' ? digits[0xa] : *rve + 1;
                } else {
                } else {
                        while (ndigits-- >= 0) {
                        while (ndigits-- >= 0) {
                                *bp++ = '0';
                                *bp++ = '0';
                        }
                        }
                }
                }
                *length = bp - buf;
                *length = bp - buf;
                return buf;
                return buf;
        }
        }
# endif /* _WANT_IO_C99_FORMATS */
# endif /* _WANT_IO_C99_FORMATS */
        if (ch == 'f' || ch == 'F') {
        if (ch == 'f' || ch == 'F') {
                mode = 3;               /* ndigits after the decimal point */
                mode = 3;               /* ndigits after the decimal point */
        } else {
        } else {
                /* To obtain ndigits after the decimal point for the 'e'
                /* To obtain ndigits after the decimal point for the 'e'
                 * and 'E' formats, round to ndigits + 1 significant
                 * and 'E' formats, round to ndigits + 1 significant
                 * figures.
                 * figures.
                 */
                 */
                if (ch == 'e' || ch == 'E') {
                if (ch == 'e' || ch == 'E') {
                        ndigits++;
                        ndigits++;
                }
                }
                mode = 2;               /* ndigits significant digits */
                mode = 2;               /* ndigits significant digits */
        }
        }
 
 
        digits = _DTOA_R (data, value, mode, ndigits, decpt, &dsgn, &rve);
        digits = _DTOA_R (data, value, mode, ndigits, decpt, &dsgn, &rve);
 
 
        if ((ch != 'g' && ch != 'G') || flags & ALT) {  /* Print trailing zeros */
        if ((ch != 'g' && ch != 'G') || flags & ALT) {  /* Print trailing zeros */
                bp = digits + ndigits;
                bp = digits + ndigits;
                if (ch == 'f' || ch == 'F') {
                if (ch == 'f' || ch == 'F') {
                        if (*digits == '0' && value)
                        if (*digits == '0' && value)
                                *decpt = -ndigits + 1;
                                *decpt = -ndigits + 1;
                        bp += *decpt;
                        bp += *decpt;
                }
                }
                if (value == 0)  /* kludge for __dtoa irregularity */
                if (value == 0)  /* kludge for __dtoa irregularity */
                        rve = bp;
                        rve = bp;
                while (rve < bp)
                while (rve < bp)
                        *rve++ = '0';
                        *rve++ = '0';
        }
        }
        *length = rve - digits;
        *length = rve - digits;
        return (digits);
        return (digits);
}
}
 
 
static int
static int
exponent(char *p0, int exp, int fmtch)
exponent(char *p0, int exp, int fmtch)
{
{
        register char *p, *t;
        register char *p, *t;
        char expbuf[MAXEXPLEN];
        char expbuf[MAXEXPLEN];
# ifdef _WANT_IO_C99_FORMATS
# ifdef _WANT_IO_C99_FORMATS
        int isa = fmtch == 'a' || fmtch == 'A';
        int isa = fmtch == 'a' || fmtch == 'A';
# else
# else
#  define isa 0
#  define isa 0
# endif
# endif
 
 
        p = p0;
        p = p0;
        *p++ = isa ? 'p' - 'a' + fmtch : fmtch;
        *p++ = isa ? 'p' - 'a' + fmtch : fmtch;
        if (exp < 0) {
        if (exp < 0) {
                exp = -exp;
                exp = -exp;
                *p++ = '-';
                *p++ = '-';
        }
        }
        else
        else
                *p++ = '+';
                *p++ = '+';
        t = expbuf + MAXEXPLEN;
        t = expbuf + MAXEXPLEN;
        if (exp > 9) {
        if (exp > 9) {
                do {
                do {
                        *--t = to_char (exp % 10);
                        *--t = to_char (exp % 10);
                } while ((exp /= 10) > 9);
                } while ((exp /= 10) > 9);
                *--t = to_char (exp);
                *--t = to_char (exp);
                for (; t < expbuf + MAXEXPLEN; *p++ = *t++);
                for (; t < expbuf + MAXEXPLEN; *p++ = *t++);
        }
        }
        else {
        else {
                if (!isa)
                if (!isa)
                        *p++ = '0';
                        *p++ = '0';
                *p++ = to_char (exp);
                *p++ = to_char (exp);
        }
        }
        return (p - p0);
        return (p - p0);
}
}
#endif /* FLOATING_POINT */
#endif /* FLOATING_POINT */
 
 
 
 
#ifndef _NO_POS_ARGS
#ifndef _NO_POS_ARGS
 
 
/* Positional argument support.
/* Positional argument support.
   Written by Jeff Johnston
   Written by Jeff Johnston
 
 
   Copyright (c) 2002 Red Hat Incorporated.
   Copyright (c) 2002 Red Hat Incorporated.
   All rights reserved.
   All rights reserved.
 
 
   Redistribution and use in source and binary forms, with or without
   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions are met:
   modification, are permitted provided that the following conditions are met:
 
 
      Redistributions of source code must retain the above copyright
      Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
      notice, this list of conditions and the following disclaimer.
 
 
      Redistributions in binary form must reproduce the above copyright
      Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
      documentation and/or other materials provided with the distribution.
 
 
      The name of Red Hat Incorporated may not be used to endorse
      The name of Red Hat Incorporated may not be used to endorse
      or promote products derived from this software without specific
      or promote products derived from this software without specific
      prior written permission.
      prior written permission.
 
 
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   DISCLAIMED.  IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY
   DISCLAIMED.  IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY
   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 
 
/* The below constant state tables are shared between all versions of
/* The below constant state tables are shared between all versions of
   vfprintf and vfwprintf.  They must only be defined once, which we do in
   vfprintf and vfwprintf.  They must only be defined once, which we do in
   the STRING_ONLY/INTEGER_ONLY versions here. */
   the STRING_ONLY/INTEGER_ONLY versions here. */
#if defined (STRING_ONLY) && defined(INTEGER_ONLY)
#if defined (STRING_ONLY) && defined(INTEGER_ONLY)
 
 
_CONST __CH_CLASS __chclass[256] = {
_CONST __CH_CLASS __chclass[256] = {
  /* 00-07 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 00-07 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 08-0f */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 08-0f */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 10-17 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 10-17 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 18-1f */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 18-1f */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 20-27 */  FLAG,    OTHER,   OTHER,   FLAG,    DOLLAR,  OTHER,   OTHER,   FLAG,
  /* 20-27 */  FLAG,    OTHER,   OTHER,   FLAG,    DOLLAR,  OTHER,   OTHER,   FLAG,
  /* 28-2f */  OTHER,   OTHER,   STAR,    FLAG,    OTHER,   FLAG,    DOT,     OTHER,
  /* 28-2f */  OTHER,   OTHER,   STAR,    FLAG,    OTHER,   FLAG,    DOT,     OTHER,
  /* 30-37 */  ZERO,    DIGIT,   DIGIT,   DIGIT,   DIGIT,   DIGIT,   DIGIT,   DIGIT,
  /* 30-37 */  ZERO,    DIGIT,   DIGIT,   DIGIT,   DIGIT,   DIGIT,   DIGIT,   DIGIT,
  /* 38-3f */  DIGIT,   DIGIT,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 38-3f */  DIGIT,   DIGIT,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 40-47 */  OTHER,   SPEC,    OTHER,   SPEC,    SPEC,    SPEC,    SPEC,    SPEC,
  /* 40-47 */  OTHER,   SPEC,    OTHER,   SPEC,    SPEC,    SPEC,    SPEC,    SPEC,
  /* 48-4f */  OTHER,   OTHER,   OTHER,   OTHER,   MODFR,   OTHER,   OTHER,   SPEC,
  /* 48-4f */  OTHER,   OTHER,   OTHER,   OTHER,   MODFR,   OTHER,   OTHER,   SPEC,
  /* 50-57 */  OTHER,   OTHER,   OTHER,   SPEC,    OTHER,   SPEC,    OTHER,   OTHER,
  /* 50-57 */  OTHER,   OTHER,   OTHER,   SPEC,    OTHER,   SPEC,    OTHER,   OTHER,
  /* 58-5f */  SPEC,    OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 58-5f */  SPEC,    OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 60-67 */  OTHER,   SPEC,    OTHER,   SPEC,    SPEC,    SPEC,    SPEC,    SPEC,
  /* 60-67 */  OTHER,   SPEC,    OTHER,   SPEC,    SPEC,    SPEC,    SPEC,    SPEC,
  /* 68-6f */  MODFR,   SPEC,    MODFR,   OTHER,   MODFR,   OTHER,   SPEC,    SPEC,
  /* 68-6f */  MODFR,   SPEC,    MODFR,   OTHER,   MODFR,   OTHER,   SPEC,    SPEC,
  /* 70-77 */  SPEC,    MODFR,   OTHER,   SPEC,    MODFR,   SPEC,    OTHER,   OTHER,
  /* 70-77 */  SPEC,    MODFR,   OTHER,   SPEC,    MODFR,   SPEC,    OTHER,   OTHER,
  /* 78-7f */  SPEC,    OTHER,   MODFR,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 78-7f */  SPEC,    OTHER,   MODFR,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 80-87 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 80-87 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 88-8f */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 88-8f */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 90-97 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 90-97 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 98-9f */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* 98-9f */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* a0-a7 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* a0-a7 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* a8-af */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* a8-af */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* b0-b7 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* b0-b7 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* b8-bf */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* b8-bf */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* c0-c7 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* c0-c7 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* c8-cf */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* c8-cf */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* d0-d7 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* d0-d7 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* d8-df */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* d8-df */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* e0-e7 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* e0-e7 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* e8-ef */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* e8-ef */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* f0-f7 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* f0-f7 */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* f8-ff */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
  /* f8-ff */  OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,   OTHER,
};
};
 
 
_CONST __STATE __state_table[MAX_STATE][MAX_CH_CLASS] = {
_CONST __STATE __state_table[MAX_STATE][MAX_CH_CLASS] = {
  /*             '0'     '1-9'     '$'     MODFR    SPEC    '.'     '*'    FLAG    OTHER */
  /*             '0'     '1-9'     '$'     MODFR    SPEC    '.'     '*'    FLAG    OTHER */
  /* START */  { SFLAG,   WDIG,    DONE,   SMOD,    DONE,   SDOT,  VARW,   SFLAG,  DONE },
  /* START */  { SFLAG,   WDIG,    DONE,   SMOD,    DONE,   SDOT,  VARW,   SFLAG,  DONE },
  /* SFLAG */  { SFLAG,   WDIG,    DONE,   SMOD,    DONE,   SDOT,  VARW,   SFLAG,  DONE },
  /* SFLAG */  { SFLAG,   WDIG,    DONE,   SMOD,    DONE,   SDOT,  VARW,   SFLAG,  DONE },
  /* WDIG  */  { DONE,    DONE,    WIDTH,  SMOD,    DONE,   SDOT,  DONE,   DONE,   DONE },
  /* WDIG  */  { DONE,    DONE,    WIDTH,  SMOD,    DONE,   SDOT,  DONE,   DONE,   DONE },
  /* WIDTH */  { DONE,    DONE,    DONE,   SMOD,    DONE,   SDOT,  DONE,   DONE,   DONE },
  /* WIDTH */  { DONE,    DONE,    DONE,   SMOD,    DONE,   SDOT,  DONE,   DONE,   DONE },
  /* SMOD  */  { DONE,    DONE,    DONE,   DONE,    DONE,   DONE,  DONE,   DONE,   DONE },
  /* SMOD  */  { DONE,    DONE,    DONE,   DONE,    DONE,   DONE,  DONE,   DONE,   DONE },
  /* SDOT  */  { SDOT,    PREC,    DONE,   SMOD,    DONE,   DONE,  VARP,   DONE,   DONE },
  /* SDOT  */  { SDOT,    PREC,    DONE,   SMOD,    DONE,   DONE,  VARP,   DONE,   DONE },
  /* VARW  */  { DONE,    VWDIG,   DONE,   SMOD,    DONE,   SDOT,  DONE,   DONE,   DONE },
  /* VARW  */  { DONE,    VWDIG,   DONE,   SMOD,    DONE,   SDOT,  DONE,   DONE,   DONE },
  /* VARP  */  { DONE,    VPDIG,   DONE,   SMOD,    DONE,   DONE,  DONE,   DONE,   DONE },
  /* VARP  */  { DONE,    VPDIG,   DONE,   SMOD,    DONE,   DONE,  DONE,   DONE,   DONE },
  /* PREC  */  { DONE,    DONE,    DONE,   SMOD,    DONE,   DONE,  DONE,   DONE,   DONE },
  /* PREC  */  { DONE,    DONE,    DONE,   SMOD,    DONE,   DONE,  DONE,   DONE,   DONE },
  /* VWDIG */  { DONE,    DONE,    WIDTH,  DONE,    DONE,   DONE,  DONE,   DONE,   DONE },
  /* VWDIG */  { DONE,    DONE,    WIDTH,  DONE,    DONE,   DONE,  DONE,   DONE,   DONE },
  /* VPDIG */  { DONE,    DONE,    PREC,   DONE,    DONE,   DONE,  DONE,   DONE,   DONE },
  /* VPDIG */  { DONE,    DONE,    PREC,   DONE,    DONE,   DONE,  DONE,   DONE,   DONE },
};
};
 
 
_CONST __ACTION __action_table[MAX_STATE][MAX_CH_CLASS] = {
_CONST __ACTION __action_table[MAX_STATE][MAX_CH_CLASS] = {
  /*             '0'     '1-9'     '$'     MODFR    SPEC    '.'     '*'    FLAG    OTHER */
  /*             '0'     '1-9'     '$'     MODFR    SPEC    '.'     '*'    FLAG    OTHER */
  /* START */  { NOOP,    NUMBER,  NOOP,   GETMOD,  GETARG, NOOP,  NOOP,   NOOP,   NOOP },
  /* START */  { NOOP,    NUMBER,  NOOP,   GETMOD,  GETARG, NOOP,  NOOP,   NOOP,   NOOP },
  /* SFLAG */  { NOOP,    NUMBER,  NOOP,   GETMOD,  GETARG, NOOP,  NOOP,   NOOP,   NOOP },
  /* SFLAG */  { NOOP,    NUMBER,  NOOP,   GETMOD,  GETARG, NOOP,  NOOP,   NOOP,   NOOP },
  /* WDIG  */  { NOOP,    NOOP,    GETPOS, GETMOD,  GETARG, NOOP,  NOOP,   NOOP,   NOOP },
  /* WDIG  */  { NOOP,    NOOP,    GETPOS, GETMOD,  GETARG, NOOP,  NOOP,   NOOP,   NOOP },
  /* WIDTH */  { NOOP,    NOOP,    NOOP,   GETMOD,  GETARG, NOOP,  NOOP,   NOOP,   NOOP },
  /* WIDTH */  { NOOP,    NOOP,    NOOP,   GETMOD,  GETARG, NOOP,  NOOP,   NOOP,   NOOP },
  /* SMOD  */  { NOOP,    NOOP,    NOOP,   NOOP,    GETARG, NOOP,  NOOP,   NOOP,   NOOP },
  /* SMOD  */  { NOOP,    NOOP,    NOOP,   NOOP,    GETARG, NOOP,  NOOP,   NOOP,   NOOP },
  /* SDOT  */  { NOOP,    SKIPNUM, NOOP,   GETMOD,  GETARG, NOOP,  NOOP,   NOOP,   NOOP },
  /* SDOT  */  { NOOP,    SKIPNUM, NOOP,   GETMOD,  GETARG, NOOP,  NOOP,   NOOP,   NOOP },
  /* VARW  */  { NOOP,    NUMBER,  NOOP,   GETPW,   GETPWB, GETPW, NOOP,   NOOP,   NOOP },
  /* VARW  */  { NOOP,    NUMBER,  NOOP,   GETPW,   GETPWB, GETPW, NOOP,   NOOP,   NOOP },
  /* VARP  */  { NOOP,    NUMBER,  NOOP,   GETPW,   GETPWB, NOOP,  NOOP,   NOOP,   NOOP },
  /* VARP  */  { NOOP,    NUMBER,  NOOP,   GETPW,   GETPWB, NOOP,  NOOP,   NOOP,   NOOP },
  /* PREC  */  { NOOP,    NOOP,    NOOP,   GETMOD,  GETARG, NOOP,  NOOP,   NOOP,   NOOP },
  /* PREC  */  { NOOP,    NOOP,    NOOP,   GETMOD,  GETARG, NOOP,  NOOP,   NOOP,   NOOP },
  /* VWDIG */  { NOOP,    NOOP,    PWPOS,  NOOP,    NOOP,   NOOP,  NOOP,   NOOP,   NOOP },
  /* VWDIG */  { NOOP,    NOOP,    PWPOS,  NOOP,    NOOP,   NOOP,  NOOP,   NOOP,   NOOP },
  /* VPDIG */  { NOOP,    NOOP,    PWPOS,  NOOP,    NOOP,   NOOP,  NOOP,   NOOP,   NOOP },
  /* VPDIG */  { NOOP,    NOOP,    PWPOS,  NOOP,    NOOP,   NOOP,  NOOP,   NOOP,   NOOP },
};
};
 
 
#endif /* STRING_ONLY && INTEGER_ONLY */
#endif /* STRING_ONLY && INTEGER_ONLY */
 
 
/* function to get positional parameter N where n = N - 1 */
/* function to get positional parameter N where n = N - 1 */
static union arg_val *
static union arg_val *
_DEFUN(get_arg, (data, n, fmt, ap, numargs_p, args, arg_type, last_fmt),
_DEFUN(get_arg, (data, n, fmt, ap, numargs_p, args, arg_type, last_fmt),
       struct _reent *data _AND
       struct _reent *data _AND
       int n               _AND
       int n               _AND
       char *fmt           _AND
       char *fmt           _AND
       va_list *ap         _AND
       va_list *ap         _AND
       int *numargs_p      _AND
       int *numargs_p      _AND
       union arg_val *args _AND
       union arg_val *args _AND
       int *arg_type       _AND
       int *arg_type       _AND
       char **last_fmt)
       char **last_fmt)
{
{
  int ch;
  int ch;
  int number, flags;
  int number, flags;
  int spec_type;
  int spec_type;
  int numargs = *numargs_p;
  int numargs = *numargs_p;
  __CH_CLASS chtype;
  __CH_CLASS chtype;
  __STATE state, next_state;
  __STATE state, next_state;
  __ACTION action;
  __ACTION action;
  int pos, last_arg;
  int pos, last_arg;
  int max_pos_arg = n;
  int max_pos_arg = n;
  /* Only need types that can be reached via vararg promotions.  */
  /* Only need types that can be reached via vararg promotions.  */
  enum types { INT, LONG_INT, QUAD_INT, CHAR_PTR, DOUBLE, LONG_DOUBLE, WIDE_CHAR };
  enum types { INT, LONG_INT, QUAD_INT, CHAR_PTR, DOUBLE, LONG_DOUBLE, WIDE_CHAR };
# ifdef _MB_CAPABLE
# ifdef _MB_CAPABLE
  wchar_t wc;
  wchar_t wc;
  mbstate_t wc_state;
  mbstate_t wc_state;
  int nbytes;
  int nbytes;
# endif
# endif
 
 
  /* if this isn't the first call, pick up where we left off last time */
  /* if this isn't the first call, pick up where we left off last time */
  if (*last_fmt != NULL)
  if (*last_fmt != NULL)
    fmt = *last_fmt;
    fmt = *last_fmt;
 
 
# ifdef _MB_CAPABLE
# ifdef _MB_CAPABLE
  memset (&wc_state, '\0', sizeof (wc_state));
  memset (&wc_state, '\0', sizeof (wc_state));
# endif
# endif
 
 
  /* we need to process either to end of fmt string or until we have actually
  /* we need to process either to end of fmt string or until we have actually
     read the desired parameter from the vararg list. */
     read the desired parameter from the vararg list. */
  while (*fmt && n >= numargs)
  while (*fmt && n >= numargs)
    {
    {
# ifdef _MB_CAPABLE
# ifdef _MB_CAPABLE
      while ((nbytes = __mbtowc (data, &wc, fmt, MB_CUR_MAX,
      while ((nbytes = __mbtowc (data, &wc, fmt, MB_CUR_MAX,
                                 __locale_charset (), &wc_state)) > 0)
                                 __locale_charset (), &wc_state)) > 0)
        {
        {
          fmt += nbytes;
          fmt += nbytes;
          if (wc == '%')
          if (wc == '%')
            break;
            break;
        }
        }
 
 
      if (nbytes <= 0)
      if (nbytes <= 0)
        break;
        break;
# else
# else
      while (*fmt != '\0' && *fmt != '%')
      while (*fmt != '\0' && *fmt != '%')
        fmt += 1;
        fmt += 1;
 
 
      if (*fmt == '\0')
      if (*fmt == '\0')
        break;
        break;
# endif /* ! _MB_CAPABLE */
# endif /* ! _MB_CAPABLE */
      state = START;
      state = START;
      flags = 0;
      flags = 0;
      pos = -1;
      pos = -1;
      number = 0;
      number = 0;
      spec_type = INT;
      spec_type = INT;
 
 
      /* Use state/action table to process format specifiers.  We ignore invalid
      /* Use state/action table to process format specifiers.  We ignore invalid
         formats and we are only interested in information that tells us how to
         formats and we are only interested in information that tells us how to
         read the vararg list. */
         read the vararg list. */
      while (state != DONE)
      while (state != DONE)
        {
        {
          ch = *fmt++;
          ch = *fmt++;
          chtype = __chclass[ch];
          chtype = __chclass[ch];
          next_state = __state_table[state][chtype];
          next_state = __state_table[state][chtype];
          action = __action_table[state][chtype];
          action = __action_table[state][chtype];
          state = next_state;
          state = next_state;
 
 
          switch (action)
          switch (action)
            {
            {
            case GETMOD:  /* we have format modifier */
            case GETMOD:  /* we have format modifier */
              switch (ch)
              switch (ch)
                {
                {
                case 'h':
                case 'h':
                  /* No flag needed, since short and char promote to int.  */
                  /* No flag needed, since short and char promote to int.  */
                  break;
                  break;
                case 'L':
                case 'L':
                  flags |= LONGDBL;
                  flags |= LONGDBL;
                  break;
                  break;
                case 'q':
                case 'q':
                  flags |= QUADINT;
                  flags |= QUADINT;
                  break;
                  break;
# ifdef _WANT_IO_C99_FORMATS
# ifdef _WANT_IO_C99_FORMATS
                case 'j':
                case 'j':
                  if (sizeof (intmax_t) == sizeof (long))
                  if (sizeof (intmax_t) == sizeof (long))
                    flags |= LONGINT;
                    flags |= LONGINT;
                  else
                  else
                    flags |= QUADINT;
                    flags |= QUADINT;
                  break;
                  break;
                case 'z':
                case 'z':
                  if (sizeof (size_t) <= sizeof (int))
                  if (sizeof (size_t) <= sizeof (int))
                    /* no flag needed */;
                    /* no flag needed */;
                  else if (sizeof (size_t) <= sizeof (long))
                  else if (sizeof (size_t) <= sizeof (long))
                    flags |= LONGINT;
                    flags |= LONGINT;
                  else
                  else
                    /* POSIX states that at least one programming
                    /* POSIX states that at least one programming
                       environment must support size_t no wider than
                       environment must support size_t no wider than
                       long, but that means other environments can
                       long, but that means other environments can
                       have size_t as wide as long long.  */
                       have size_t as wide as long long.  */
                    flags |= QUADINT;
                    flags |= QUADINT;
                  break;
                  break;
                case 't':
                case 't':
                  if (sizeof (ptrdiff_t) <= sizeof (int))
                  if (sizeof (ptrdiff_t) <= sizeof (int))
                    /* no flag needed */;
                    /* no flag needed */;
                  else if (sizeof (ptrdiff_t) <= sizeof (long))
                  else if (sizeof (ptrdiff_t) <= sizeof (long))
                    flags |= LONGINT;
                    flags |= LONGINT;
                  else
                  else
                    /* POSIX states that at least one programming
                    /* POSIX states that at least one programming
                       environment must support ptrdiff_t no wider than
                       environment must support ptrdiff_t no wider than
                       long, but that means other environments can
                       long, but that means other environments can
                       have ptrdiff_t as wide as long long.  */
                       have ptrdiff_t as wide as long long.  */
                    flags |= QUADINT;
                    flags |= QUADINT;
                  break;
                  break;
# endif /* _WANT_IO_C99_FORMATS */
# endif /* _WANT_IO_C99_FORMATS */
                case 'l':
                case 'l':
                default:
                default:
# if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG
# if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG
                  if (*fmt == 'l')
                  if (*fmt == 'l')
                    {
                    {
                      flags |= QUADINT;
                      flags |= QUADINT;
                      ++fmt;
                      ++fmt;
                    }
                    }
                  else
                  else
# endif
# endif
                    flags |= LONGINT;
                    flags |= LONGINT;
                  break;
                  break;
                }
                }
              break;
              break;
            case GETARG: /* we have format specifier */
            case GETARG: /* we have format specifier */
              {
              {
                numargs &= (MAX_POS_ARGS - 1);
                numargs &= (MAX_POS_ARGS - 1);
                /* process the specifier and translate it to a type to fetch from varargs */
                /* process the specifier and translate it to a type to fetch from varargs */
                switch (ch)
                switch (ch)
                  {
                  {
                  case 'd':
                  case 'd':
                  case 'i':
                  case 'i':
                  case 'o':
                  case 'o':
                  case 'x':
                  case 'x':
                  case 'X':
                  case 'X':
                  case 'u':
                  case 'u':
                    if (flags & LONGINT)
                    if (flags & LONGINT)
                      spec_type = LONG_INT;
                      spec_type = LONG_INT;
# ifndef _NO_LONGLONG
# ifndef _NO_LONGLONG
                    else if (flags & QUADINT)
                    else if (flags & QUADINT)
                      spec_type = QUAD_INT;
                      spec_type = QUAD_INT;
# endif
# endif
                    else
                    else
                      spec_type = INT;
                      spec_type = INT;
                    break;
                    break;
                  case 'D':
                  case 'D':
                  case 'U':
                  case 'U':
                  case 'O':
                  case 'O':
                    spec_type = LONG_INT;
                    spec_type = LONG_INT;
                    break;
                    break;
# ifdef _WANT_IO_C99_FORMATS
# ifdef _WANT_IO_C99_FORMATS
                  case 'a':
                  case 'a':
                  case 'A':
                  case 'A':
                  case 'F':
                  case 'F':
# endif
# endif
                  case 'f':
                  case 'f':
                  case 'g':
                  case 'g':
                  case 'G':
                  case 'G':
                  case 'E':
                  case 'E':
                  case 'e':
                  case 'e':
# ifndef _NO_LONGDBL
# ifndef _NO_LONGDBL
                    if (flags & LONGDBL)
                    if (flags & LONGDBL)
                      spec_type = LONG_DOUBLE;
                      spec_type = LONG_DOUBLE;
                    else
                    else
# endif
# endif
                      spec_type = DOUBLE;
                      spec_type = DOUBLE;
                    break;
                    break;
                  case 's':
                  case 's':
# ifdef _WANT_IO_C99_FORMATS
# ifdef _WANT_IO_C99_FORMATS
                  case 'S':
                  case 'S':
# endif
# endif
                  case 'p':
                  case 'p':
                  case 'n':
                  case 'n':
                    spec_type = CHAR_PTR;
                    spec_type = CHAR_PTR;
                    break;
                    break;
                  case 'c':
                  case 'c':
# ifdef _WANT_IO_C99_FORMATS
# ifdef _WANT_IO_C99_FORMATS
                    if (flags & LONGINT)
                    if (flags & LONGINT)
                      spec_type = WIDE_CHAR;
                      spec_type = WIDE_CHAR;
                    else
                    else
# endif
# endif
                      spec_type = INT;
                      spec_type = INT;
                    break;
                    break;
# ifdef _WANT_IO_C99_FORMATS
# ifdef _WANT_IO_C99_FORMATS
                  case 'C':
                  case 'C':
                    spec_type = WIDE_CHAR;
                    spec_type = WIDE_CHAR;
                    break;
                    break;
# endif
# endif
                  }
                  }
 
 
                /* if we have a positional parameter, just store the type, otherwise
                /* if we have a positional parameter, just store the type, otherwise
                   fetch the parameter from the vararg list */
                   fetch the parameter from the vararg list */
                if (pos != -1)
                if (pos != -1)
                  arg_type[pos] = spec_type;
                  arg_type[pos] = spec_type;
                else
                else
                  {
                  {
                    switch (spec_type)
                    switch (spec_type)
                      {
                      {
                      case LONG_INT:
                      case LONG_INT:
                        args[numargs++].val_long = va_arg (*ap, long);
                        args[numargs++].val_long = va_arg (*ap, long);
                        break;
                        break;
                      case QUAD_INT:
                      case QUAD_INT:
                        args[numargs++].val_quad_t = va_arg (*ap, quad_t);
                        args[numargs++].val_quad_t = va_arg (*ap, quad_t);
                        break;
                        break;
                      case WIDE_CHAR:
                      case WIDE_CHAR:
                        args[numargs++].val_wint_t = va_arg (*ap, wint_t);
                        args[numargs++].val_wint_t = va_arg (*ap, wint_t);
                        break;
                        break;
                      case INT:
                      case INT:
                        args[numargs++].val_int = va_arg (*ap, int);
                        args[numargs++].val_int = va_arg (*ap, int);
                        break;
                        break;
                      case CHAR_PTR:
                      case CHAR_PTR:
                        args[numargs++].val_char_ptr_t = va_arg (*ap, char *);
                        args[numargs++].val_char_ptr_t = va_arg (*ap, char *);
                        break;
                        break;
                      case DOUBLE:
                      case DOUBLE:
                        args[numargs++].val_double = va_arg (*ap, double);
                        args[numargs++].val_double = va_arg (*ap, double);
                        break;
                        break;
                      case LONG_DOUBLE:
                      case LONG_DOUBLE:
                        args[numargs++].val__LONG_DOUBLE = va_arg (*ap, _LONG_DOUBLE);
                        args[numargs++].val__LONG_DOUBLE = va_arg (*ap, _LONG_DOUBLE);
                        break;
                        break;
                      }
                      }
                  }
                  }
              }
              }
              break;
              break;
            case GETPOS: /* we have positional specifier */
            case GETPOS: /* we have positional specifier */
              if (arg_type[0] == -1)
              if (arg_type[0] == -1)
                memset (arg_type, 0, sizeof (int) * MAX_POS_ARGS);
                memset (arg_type, 0, sizeof (int) * MAX_POS_ARGS);
              pos = number - 1;
              pos = number - 1;
              max_pos_arg = (max_pos_arg > pos ? max_pos_arg : pos);
              max_pos_arg = (max_pos_arg > pos ? max_pos_arg : pos);
              break;
              break;
            case PWPOS:  /* we have positional specifier for width or precision */
            case PWPOS:  /* we have positional specifier for width or precision */
              if (arg_type[0] == -1)
              if (arg_type[0] == -1)
                memset (arg_type, 0, sizeof (int) * MAX_POS_ARGS);
                memset (arg_type, 0, sizeof (int) * MAX_POS_ARGS);
              number -= 1;
              number -= 1;
              arg_type[number] = INT;
              arg_type[number] = INT;
              max_pos_arg = (max_pos_arg > number ? max_pos_arg : number);
              max_pos_arg = (max_pos_arg > number ? max_pos_arg : number);
              break;
              break;
            case GETPWB: /* we require format pushback */
            case GETPWB: /* we require format pushback */
              --fmt;
              --fmt;
              /* fallthrough */
              /* fallthrough */
            case GETPW:  /* we have a variable precision or width to acquire */
            case GETPW:  /* we have a variable precision or width to acquire */
              args[numargs++].val_int = va_arg (*ap, int);
              args[numargs++].val_int = va_arg (*ap, int);
              break;
              break;
            case NUMBER: /* we have a number to process */
            case NUMBER: /* we have a number to process */
              number = (ch - '0');
              number = (ch - '0');
              while ((ch = *fmt) != '\0' && is_digit (ch))
              while ((ch = *fmt) != '\0' && is_digit (ch))
                {
                {
                  number = number * 10 + (ch - '0');
                  number = number * 10 + (ch - '0');
                  ++fmt;
                  ++fmt;
                }
                }
              break;
              break;
            case SKIPNUM: /* we have a number to skip */
            case SKIPNUM: /* we have a number to skip */
              while ((ch = *fmt) != '\0' && is_digit (ch))
              while ((ch = *fmt) != '\0' && is_digit (ch))
                ++fmt;
                ++fmt;
              break;
              break;
            case NOOP:
            case NOOP:
            default:
            default:
              break; /* do nothing */
              break; /* do nothing */
            }
            }
        }
        }
    }
    }
 
 
  /* process all arguments up to at least the one we are looking for and if we
  /* process all arguments up to at least the one we are looking for and if we
     have seen the end of the string, then process up to the max argument needed */
     have seen the end of the string, then process up to the max argument needed */
  if (*fmt == '\0')
  if (*fmt == '\0')
    last_arg = max_pos_arg;
    last_arg = max_pos_arg;
  else
  else
    last_arg = n;
    last_arg = n;
 
 
  while (numargs <= last_arg)
  while (numargs <= last_arg)
    {
    {
      switch (arg_type[numargs])
      switch (arg_type[numargs])
        {
        {
        case LONG_INT:
        case LONG_INT:
          args[numargs++].val_long = va_arg (*ap, long);
          args[numargs++].val_long = va_arg (*ap, long);
          break;
          break;
        case QUAD_INT:
        case QUAD_INT:
          args[numargs++].val_quad_t = va_arg (*ap, quad_t);
          args[numargs++].val_quad_t = va_arg (*ap, quad_t);
          break;
          break;
        case CHAR_PTR:
        case CHAR_PTR:
          args[numargs++].val_char_ptr_t = va_arg (*ap, char *);
          args[numargs++].val_char_ptr_t = va_arg (*ap, char *);
          break;
          break;
        case DOUBLE:
        case DOUBLE:
          args[numargs++].val_double = va_arg (*ap, double);
          args[numargs++].val_double = va_arg (*ap, double);
          break;
          break;
        case LONG_DOUBLE:
        case LONG_DOUBLE:
          args[numargs++].val__LONG_DOUBLE = va_arg (*ap, _LONG_DOUBLE);
          args[numargs++].val__LONG_DOUBLE = va_arg (*ap, _LONG_DOUBLE);
          break;
          break;
        case WIDE_CHAR:
        case WIDE_CHAR:
          args[numargs++].val_wint_t = va_arg (*ap, wint_t);
          args[numargs++].val_wint_t = va_arg (*ap, wint_t);
          break;
          break;
        case INT:
        case INT:
        default:
        default:
          args[numargs++].val_int = va_arg (*ap, int);
          args[numargs++].val_int = va_arg (*ap, int);
          break;
          break;
        }
        }
    }
    }
 
 
  /* alter the global numargs value and keep a reference to the last bit of the fmt
  /* alter the global numargs value and keep a reference to the last bit of the fmt
     string we processed here because the caller will continue processing where we started */
     string we processed here because the caller will continue processing where we started */
  *numargs_p = numargs;
  *numargs_p = numargs;
  *last_fmt = fmt;
  *last_fmt = fmt;
  return &args[n];
  return &args[n];
}
}
#endif /* !_NO_POS_ARGS */
#endif /* !_NO_POS_ARGS */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.