/contrib/sdk/sources/newlib/libc/stdio/fgetwc.c |
---|
0,0 → 1,243 |
/*- |
* Copyright (c) 2002-2004 Tim J. Robbins. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
/* |
FUNCTION |
<<fgetwc>>, <<getwc>>, <<fgetwc_unlocked>>, <<getwc_unlocked>>---get a wide character from a file or stream |
INDEX |
fgetwc |
INDEX |
fgetwc_unlocked |
INDEX |
_fgetwc_r |
INDEX |
_fgetwc_unlocked_r |
INDEX |
getwc |
INDEX |
getwc_unlocked |
INDEX |
_getwc_r |
INDEX |
_getwc_unlocked_r |
ANSI_SYNOPSIS |
#include <stdio.h> |
#include <wchar.h> |
wint_t fgetwc(FILE *<[fp]>); |
#define _GNU_SOURCE |
#include <stdio.h> |
#include <wchar.h> |
wint_t fgetwc_unlocked(FILE *<[fp]>); |
#include <stdio.h> |
#include <wchar.h> |
wint_t _fgetwc_r(struct _reent *<[ptr]>, FILE *<[fp]>); |
#include <stdio.h> |
#include <wchar.h> |
wint_t _fgetwc_unlocked_r(struct _reent *<[ptr]>, FILE *<[fp]>); |
#include <stdio.h> |
#include <wchar.h> |
wint_t getwc(FILE *<[fp]>); |
#define _GNU_SOURCE |
#include <stdio.h> |
#include <wchar.h> |
wint_t getwc_unlocked(FILE *<[fp]>); |
#include <stdio.h> |
#include <wchar.h> |
wint_t _getwc_r(struct _reent *<[ptr]>, FILE *<[fp]>); |
#include <stdio.h> |
#include <wchar.h> |
wint_t _getwc_unlocked_r(struct _reent *<[ptr]>, FILE *<[fp]>); |
TRAD_SYNOPSIS |
#include <stdio.h> |
#include <wchar.h> |
wint_t fgetwc(<[fp]>) |
FILE *<[fp]>; |
#define _GNU_SOURCE |
#include <stdio.h> |
#include <wchar.h> |
wint_t fgetwc_unlocked(<[fp]>) |
FILE *<[fp]>; |
#include <stdio.h> |
#include <wchar.h> |
wint_t _fgetwc_r(<[ptr]>, <[fp]>) |
struct _reent *<[ptr]>; |
FILE *<[fp]>; |
#include <stdio.h> |
#include <wchar.h> |
wint_t _fgetwc_unlocked_r(<[ptr]>, <[fp]>) |
struct _reent *<[ptr]>; |
FILE *<[fp]>; |
#include <stdio.h> |
#include <wchar.h> |
wint_t getwc(<[fp]>) |
FILE *<[fp]>; |
#define _GNU_SOURCE |
#include <stdio.h> |
#include <wchar.h> |
wint_t getwc_unlocked(<[fp]>) |
FILE *<[fp]>; |
#include <stdio.h> |
#include <wchar.h> |
wint_t _getwc_r(<[ptr]>, <[fp]>) |
struct _reent *<[ptr]>; |
FILE *<[fp]>; |
#include <stdio.h> |
#include <wchar.h> |
wint_t _getwc_unlocked_r(<[ptr]>, <[fp]>) |
struct _reent *<[ptr]>; |
FILE *<[fp]>; |
DESCRIPTION |
Use <<fgetwc>> to get the next wide character from the file or stream |
identified by <[fp]>. As a side effect, <<fgetwc>> advances the file's |
current position indicator. |
<<fgetwc_unlocked>> is a non-thread-safe version of <<fgetwc>>. |
<<fgetwc_unlocked>> may only safely be used within a scope |
protected by flockfile() (or ftrylockfile()) and funlockfile(). This |
function may safely be used in a multi-threaded program if and only |
if they are called while the invoking thread owns the (FILE *) |
object, as is the case after a successful call to the flockfile() or |
ftrylockfile() functions. If threads are disabled, then |
<<fgetwc_unlocked>> is equivalent to <<fgetwc>>. |
The <<getwc>> and <<getwc_unlocked>> functions or macros functions identically |
to <<fgetwc>> and <<fgetwc_unlocked>>. It may be implemented as a macro, and |
may evaluate its argument more than once. There is no reason ever to use it. |
<<_fgetwc_r>>, <<_getwc_r>>, <<_fgetwc_unlocked_r>>, and <<_getwc_unlocked_r>> |
are simply reentrant versions of the above functions that are passed the |
additional reentrant structure pointer argument: <[ptr]>. |
RETURNS |
The next wide character cast to <<wint_t>>, unless there is no more data, |
or the host system reports a read error; in either of these situations, |
<<fgetwc>> and <<getwc>> return <<WEOF>>. |
You can distinguish the two situations that cause an <<EOF>> result by |
using the <<ferror>> and <<feof>> functions. |
PORTABILITY |
<<fgetwc>> and <<getwc>> are required by C99 and POSIX.1-2001. |
<<fgetwc_unlocked>> and <<getwc_unlocked>> are GNU extensions. |
*/ |
#include <_ansi.h> |
#include <reent.h> |
#include <errno.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <wchar.h> |
#include "local.h" |
wint_t |
_DEFUN(__fgetwc, (ptr, fp), |
struct _reent *ptr _AND |
register FILE *fp) |
{ |
wchar_t wc; |
size_t nconv; |
if (fp->_r <= 0 && __srefill_r (ptr, fp)) |
return (WEOF); |
if (MB_CUR_MAX == 1) |
{ |
/* Fast path for single-byte encodings. */ |
wc = *fp->_p++; |
fp->_r--; |
return (wc); |
} |
do |
{ |
nconv = _mbrtowc_r (ptr, &wc, (char *) fp->_p, fp->_r, &fp->_mbstate); |
if (nconv == (size_t)-1) |
break; |
else if (nconv == (size_t)-2) |
continue; |
else if (nconv == 0) |
{ |
/* |
* Assume that the only valid representation of |
* the null wide character is a single null byte. |
*/ |
fp->_p++; |
fp->_r--; |
return (L'\0'); |
} |
else |
{ |
fp->_p += nconv; |
fp->_r -= nconv; |
return (wc); |
} |
} |
while (__srefill_r(ptr, fp) == 0); |
fp->_flags |= __SERR; |
errno = EILSEQ; |
return (WEOF); |
} |
wint_t |
_DEFUN(_fgetwc_r, (ptr, fp), |
struct _reent *ptr _AND |
register FILE *fp) |
{ |
wint_t r; |
_newlib_flockfile_start (fp); |
ORIENT(fp, 1); |
r = __fgetwc (ptr, fp); |
_newlib_flockfile_end (fp); |
return r; |
} |
wint_t |
_DEFUN(fgetwc, (fp), |
FILE *fp) |
{ |
struct _reent *reent = _REENT; |
CHECK_INIT(reent, fp); |
return _fgetwc_r (reent, fp); |
} |
/contrib/sdk/sources/newlib/libc/stdio/fgetwc_u.c |
---|
0,0 → 1,49 |
/* |
* Copyright (c) 2014 Red Hat, Inc. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
#include <_ansi.h> |
#include <stdio.h> |
#include <wchar.h> |
#include "local.h" |
wint_t |
_DEFUN(_fgetwc_unlocked_r, (ptr, fp), |
struct _reent *ptr _AND |
register FILE *fp) |
{ |
ORIENT(fp, 1); |
return __fgetwc (ptr, fp); |
} |
wint_t |
_DEFUN(fgetwc_unlocked, (fp), |
FILE *fp) |
{ |
struct _reent *reent = _REENT; |
CHECK_INIT(reent, fp); |
return _fgetwc_unlocked_r (reent, fp); |
} |
/contrib/sdk/sources/newlib/libc/stdio/fgetws.c |
---|
0,0 → 1,212 |
/*- |
* Copyright (c) 2002-2004 Tim J. Robbins. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
/* |
FUNCTION |
<<fgetws>>, <<fgetws_unlocked>>---get wide character string from a file or stream |
INDEX |
fgetws |
INDEX |
fgetws_unlocked |
INDEX |
_fgetws_r |
INDEX |
_fgetws_unlocked_r |
ANSI_SYNOPSIS |
#include <wchar.h> |
wchar_t *fgetws(wchar_t *__restrict <[ws]>, int <[n]>, |
FILE *__restrict <[fp]>); |
#define _GNU_SOURCE |
#include <wchar.h> |
wchar_t *fgetws_unlocked(wchar_t *__restrict <[ws]>, int <[n]>, |
FILE *__restrict <[fp]>); |
#include <wchar.h> |
wchar_t *_fgetws_r(struct _reent *<[ptr]>, wchar_t *<[ws]>, |
int <[n]>, FILE *<[fp]>); |
#include <wchar.h> |
wchar_t *_fgetws_unlocked_r(struct _reent *<[ptr]>, wchar_t *<[ws]>, |
int <[n]>, FILE *<[fp]>); |
TRAD_SYNOPSIS |
#include <wchar.h> |
wchar_t *fgetws(<[ws]>,<[n]>,<[fp]>) |
wchar_t *__restrict <[ws]>; |
int <[n]>; |
FILE *__restrict <[fp]>; |
#define _GNU_SOURCE |
#include <wchar.h> |
wchar_t *fgetws_unlocked(<[ws]>,<[n]>,<[fp]>) |
wchar_t *__restrict <[ws]>; |
int <[n]>; |
FILE *__restrict <[fp]>; |
#include <wchar.h> |
wchar_t *_fgetws_r(<[ptr]>, <[ws]>,<[n]>,<[fp]>) |
struct _reent *<[ptr]>; |
wchar_t *<[ws]>; |
int <[n]>; |
FILE *<[fp]>; |
#include <wchar.h> |
wchar_t *_fgetws_unlocked_r(<[ptr]>, <[ws]>,<[n]>,<[fp]>) |
struct _reent *<[ptr]>; |
wchar_t *<[ws]>; |
int <[n]>; |
FILE *<[fp]>; |
DESCRIPTION |
Reads at most <[n-1]> wide characters from <[fp]> until a newline |
is found. The wide characters including to the newline are stored |
in <[ws]>. The buffer is terminated with a 0. |
<<fgetws_unlocked>> is a non-thread-safe version of <<fgetws>>. |
<<fgetws_unlocked>> may only safely be used within a scope |
protected by flockfile() (or ftrylockfile()) and funlockfile(). This |
function may safely be used in a multi-threaded program if and only |
if they are called while the invoking thread owns the (FILE *) |
object, as is the case after a successful call to the flockfile() or |
ftrylockfile() functions. If threads are disabled, then |
<<fgetws_unlocked>> is equivalent to <<fgetws>>. |
The <<_fgetws_r>> and <<_fgetws_unlocked_r>> functions are simply reentrant |
version of the above and are passed an additional reentrancy structure |
pointer: <[ptr]>. |
RETURNS |
<<fgetws>> returns the buffer passed to it, with the data |
filled in. If end of file occurs with some data already |
accumulated, the data is returned with no other indication. If |
no data are read, NULL is returned instead. |
PORTABILITY |
<<fgetws>> is required by C99 and POSIX.1-2001. |
<<fgetws_unlocked>> is a GNU extension. |
*/ |
#include <_ansi.h> |
#include <reent.h> |
#include <errno.h> |
#include <stdio.h> |
#include <string.h> |
#include <wchar.h> |
#include "local.h" |
#ifdef __IMPL_UNLOCKED__ |
#define _fgetws_r _fgetws_unlocked_r |
#define fgetws fgetws_unlocked |
#endif |
wchar_t * |
_DEFUN(_fgetws_r, (ptr, ws, n, fp), |
struct _reent *ptr _AND |
wchar_t * ws _AND |
int n _AND |
FILE * fp) |
{ |
wchar_t *wsp; |
size_t nconv; |
const char *src; |
unsigned char *nl; |
_newlib_flockfile_start (fp); |
ORIENT (fp, 1); |
if (n <= 0) |
{ |
errno = EINVAL; |
goto error; |
} |
if (fp->_r <= 0 && __srefill_r (ptr, fp)) |
/* EOF */ |
goto error; |
wsp = ws; |
do |
{ |
src = (char *) fp->_p; |
nl = memchr (fp->_p, '\n', fp->_r); |
nconv = _mbsnrtowcs_r (ptr, wsp, &src, |
/* Read all bytes up to the next NL, or up to the |
end of the buffer if there is no NL. */ |
nl != NULL ? (nl - fp->_p + 1) : fp->_r, |
/* But never more than n - 1 wide chars. */ |
n - 1, |
&fp->_mbstate); |
if (nconv == (size_t) -1) |
/* Conversion error */ |
goto error; |
if (src == NULL) |
{ |
/* |
* We hit a null byte. Increment the character count, |
* since mbsnrtowcs()'s return value doesn't include |
* the terminating null, then resume conversion |
* after the null. |
*/ |
nconv++; |
src = memchr (fp->_p, '\0', fp->_r); |
src++; |
} |
fp->_r -= (unsigned char *) src - fp->_p; |
fp->_p = (unsigned char *) src; |
n -= nconv; |
wsp += nconv; |
} |
while (wsp[-1] != L'\n' && n > 1 && (fp->_r > 0 |
|| __srefill_r (ptr, fp) == 0)); |
if (wsp == ws) |
/* EOF */ |
goto error; |
if (!mbsinit (&fp->_mbstate)) |
/* Incomplete character */ |
goto error; |
*wsp++ = L'\0'; |
_newlib_flockfile_exit (fp); |
return ws; |
error: |
_newlib_flockfile_end (fp); |
return NULL; |
} |
wchar_t * |
_DEFUN(fgetws, (ws, n, fp), |
wchar_t *__restrict ws _AND |
int n _AND |
FILE *__restrict fp) |
{ |
struct _reent *reent = _REENT; |
CHECK_INIT (reent, fp); |
return _fgetws_r (reent, ws, n, fp); |
} |
/contrib/sdk/sources/newlib/libc/stdio/fgetws_u.c |
---|
0,0 → 1,28 |
/* |
* Copyright (c) 2014 Red Hat, Inc. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
#define __IMPL_UNLOCKED__ |
#include "fgetws.c" |
/contrib/sdk/sources/newlib/libc/stdio/fputwc_u.c |
---|
0,0 → 1,51 |
/* |
* Copyright (c) 2014 Red Hat, Inc. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
#include <_ansi.h> |
#include <stdio.h> |
#include <wchar.h> |
#include "local.h" |
wint_t |
_DEFUN(_fputwc_unlocked_r, (ptr, wc, fp), |
struct _reent *ptr _AND |
wchar_t wc _AND |
FILE *fp) |
{ |
ORIENT(fp, 1); |
return __fputwc(ptr, wc, fp); |
} |
wint_t |
_DEFUN(fputwc_unlocked, (wc, fp), |
wchar_t wc _AND |
FILE *fp) |
{ |
struct _reent *reent = _REENT; |
CHECK_INIT(reent, fp); |
return _fputwc_unlocked_r (reent, wc, fp); |
} |
/contrib/sdk/sources/newlib/libc/stdio/fputws.c |
---|
0,0 → 1,193 |
/*- |
* Copyright (c) 2002-2004 Tim J. Robbins. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
/* |
FUNCTION |
<<fputws>>, <<fputws_unlocked>>---write a wide character string in a file or stream |
INDEX |
fputws |
INDEX |
fputws_unlocked |
INDEX |
_fputws_r |
INDEX |
_fputws_unlocked_r |
ANSI_SYNOPSIS |
#include <wchar.h> |
int fputws(const wchar_t *__restrict <[ws]>, FILE *__restrict <[fp]>); |
#define _GNU_SOURCE |
#include <wchar.h> |
int fputws_unlocked(const wchar_t *__restrict <[ws]>, FILE *__restrict <[fp]>); |
#include <wchar.h> |
int _fputws_r(struct _reent *<[ptr]>, const wchar_t *<[ws]>, |
FILE *<[fp]>); |
#include <wchar.h> |
int _fputws_unlocked_r(struct _reent *<[ptr]>, const wchar_t *<[ws]>, |
FILE *<[fp]>); |
TRAD_SYNOPSIS |
#include <wchar.h> |
int fputws(<[ws]>, <[fp]>) |
wchar_t *__restrict <[ws]>; |
FILE *__restrict <[fp]>; |
#define _GNU_SOURCE |
#include <wchar.h> |
int fputws_unlocked(<[ws]>, <[fp]>) |
wchar_t *__restrict <[ws]>; |
FILE *__restrict <[fp]>; |
#include <wchar.h> |
int _fputws_r(<[ptr]>, <[ws]>, <[fp]>) |
struct _reent *<[ptr]>; |
wchar_t *<[ws]>; |
FILE *<[fp]>; |
#include <wchar.h> |
int _fputws_unlocked_r(<[ptr]>, <[ws]>, <[fp]>) |
struct _reent *<[ptr]>; |
wchar_t *<[ws]>; |
FILE *<[fp]>; |
DESCRIPTION |
<<fputws>> writes the wide character string at <[ws]> (but without the |
trailing null) to the file or stream identified by <[fp]>. |
<<fputws_unlocked>> is a non-thread-safe version of <<fputws>>. |
<<fputws_unlocked>> may only safely be used within a scope |
protected by flockfile() (or ftrylockfile()) and funlockfile(). This |
function may safely be used in a multi-threaded program if and only |
if they are called while the invoking thread owns the (FILE *) |
object, as is the case after a successful call to the flockfile() or |
ftrylockfile() functions. If threads are disabled, then |
<<fputws_unlocked>> is equivalent to <<fputws>>. |
<<_fputws_r>> and <<_fputws_unlocked_r>> are simply reentrant versions of the |
above that take an additional reentrant struct pointer argument: <[ptr]>. |
RETURNS |
If successful, the result is a non-negative integer; otherwise, the result |
is <<-1>> to indicate an error. |
PORTABILITY |
<<fputws>> is required by C99 and POSIX.1-2001. |
<<fputws_unlocked>> is a GNU extension. |
*/ |
#include <_ansi.h> |
#include <reent.h> |
#include <errno.h> |
#include <limits.h> |
#include <stdio.h> |
#include <wchar.h> |
#include "fvwrite.h" |
#include "local.h" |
#ifdef __IMPL_UNLOCKED__ |
#define _fputws_r _fputws_unlocked_r |
#define fputws fputws_unlocked |
#endif |
int |
_DEFUN(_fputws_r, (ptr, ws, fp), |
struct _reent *ptr _AND |
const wchar_t *ws _AND |
FILE *fp) |
{ |
size_t nbytes; |
char buf[BUFSIZ]; |
#ifdef _FVWRITE_IN_STREAMIO |
struct __suio uio; |
struct __siov iov; |
_newlib_flockfile_start (fp); |
ORIENT (fp, 1); |
if (cantwrite (ptr, fp) != 0) |
goto error; |
uio.uio_iov = &iov; |
uio.uio_iovcnt = 1; |
iov.iov_base = buf; |
do |
{ |
nbytes = _wcsrtombs_r(ptr, buf, &ws, sizeof (buf), &fp->_mbstate); |
if (nbytes == (size_t) -1) |
goto error; |
iov.iov_len = uio.uio_resid = nbytes; |
if (__sfvwrite_r(ptr, fp, &uio) != 0) |
goto error; |
} |
while (ws != NULL); |
_newlib_flockfile_exit (fp); |
return (0); |
error: |
_newlib_flockfile_end (fp); |
return (-1); |
#else |
_newlib_flockfile_start (fp); |
ORIENT (fp, 1); |
if (cantwrite (ptr, fp) != 0) |
goto error; |
do |
{ |
size_t i = 0; |
nbytes = _wcsrtombs_r (ptr, buf, &ws, sizeof (buf), &fp->_mbstate); |
if (nbytes == (size_t) -1) |
goto error; |
while (i < nbytes) |
{ |
if (__sputc_r (ptr, buf[i], fp) == EOF) |
goto error; |
i++; |
} |
} |
while (ws != NULL); |
_newlib_flockfile_exit (fp); |
return (0); |
error: |
_newlib_flockfile_end (fp); |
return (-1); |
#endif |
} |
int |
_DEFUN(fputws, (ws, fp), |
const wchar_t *__restrict ws _AND |
FILE *__restrict fp) |
{ |
struct _reent *reent = _REENT; |
CHECK_INIT (reent, fp); |
return _fputws_r (reent, ws, fp); |
} |
/contrib/sdk/sources/newlib/libc/stdio/fputws_u.c |
---|
0,0 → 1,28 |
/* |
* Copyright (c) 2014 Red Hat, Inc. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
#define __IMPL_UNLOCKED__ |
#include "fputws.c" |
/contrib/sdk/sources/newlib/libc/stdio/fwprintf.c |
---|
0,0 → 1,56 |
/* |
* Copyright (c) 1990 The Regents of the University of California. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms are permitted |
* provided that the above copyright notice and this paragraph are |
* duplicated in all such forms and that any documentation, |
* advertising materials, and other materials related to such |
* distribution and use acknowledge that the software was developed |
* by the University of California, Berkeley. The name of the |
* University may not be used to endorse or promote products derived |
* from this software without specific prior written permission. |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
*/ |
/* doc in swprintf.c */ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include <stdarg.h> |
int |
_DEFUN(_fwprintf_r, (ptr, fp, fmt), |
struct _reent *ptr _AND |
FILE *fp _AND |
const wchar_t *fmt _DOTS) |
{ |
int ret; |
va_list ap; |
va_start (ap, fmt); |
ret = _vfwprintf_r (ptr, fp, fmt, ap); |
va_end (ap); |
return ret; |
} |
#ifndef _REENT_ONLY |
int |
_DEFUN(fwprintf, (fp, fmt), |
FILE *__restrict fp _AND |
const wchar_t *__restrict fmt _DOTS) |
{ |
int ret; |
va_list ap; |
va_start (ap, fmt); |
ret = _vfwprintf_r (_REENT, fp, fmt, ap); |
va_end (ap); |
return ret; |
} |
#endif /* ! _REENT_ONLY */ |
/contrib/sdk/sources/newlib/libc/stdio/fwscanf.c |
---|
0,0 → 1,53 |
/* |
* Copyright (c) 1990 The Regents of the University of California. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms are permitted |
* provided that the above copyright notice and this paragraph are |
* duplicated in all such forms and that any documentation, |
* advertising materials, and other materials related to such |
* distribution and use acknowledge that the software was developed |
* by the University of California, Berkeley. The name of the |
* University may not be used to endorse or promote products derived |
* from this software without specific prior written permission. |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
*/ |
/* Doc in swscanf.c */ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include <stdarg.h> |
#include "local.h" |
#ifndef _REENT_ONLY |
int |
fwscanf (FILE *__restrict fp, _CONST wchar_t *__restrict fmt, ...) |
{ |
int ret; |
va_list ap; |
va_start (ap, fmt); |
ret = _vfwscanf_r (_REENT, fp, fmt, ap); |
va_end (ap); |
return ret; |
} |
#endif /* !_REENT_ONLY */ |
int |
_fwscanf_r (struct _reent *ptr, FILE *fp, _CONST wchar_t *fmt, ...) |
{ |
int ret; |
va_list ap; |
va_start (ap, fmt); |
ret = _vfwscanf_r (ptr, fp, fmt, ap); |
va_end (ap); |
return (ret); |
} |
/contrib/sdk/sources/newlib/libc/stdio/getw.c |
---|
0,0 → 1,69 |
/* |
* Copyright (c) 1990 The Regents of the University of California. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms are permitted |
* provided that the above copyright notice and this paragraph are |
* duplicated in all such forms and that any documentation, |
* advertising materials, and other materials related to such |
* distribution and use acknowledge that the software was developed |
* by the University of California, Berkeley. The name of the |
* University may not be used to endorse or promote products derived |
* from this software without specific prior written permission. |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
*/ |
/* |
FUNCTION |
<<getw>>---read a word (int) |
INDEX |
getw |
ANSI_SYNOPSIS |
#include <stdio.h> |
int getw(FILE *<[fp]>); |
TRAD_SYNOPSIS |
#include <stdio.h> |
int getw(<[fp]>) |
FILE *<[fp]>; |
DESCRIPTION |
<<getw>> is a function, defined in <<stdio.h>>. You can use <<getw>> |
to get the next word from the file or stream identified by <[fp]>. As |
a side effect, <<getw>> advances the file's current position |
indicator. |
RETURNS |
The next word (read as an <<int>>), unless there is no more |
data or the host system reports a read error; in either of these |
situations, <<getw>> returns <<EOF>>. Since <<EOF>> is a valid |
<<int>>, you must use <<ferror>> or <<feof>> to distinguish these |
situations. |
PORTABILITY |
<<getw>> is a remnant of K&R C; it is not part of any ISO C Standard. |
<<fread>> should be used instead. In fact, this implementation of |
<<getw>> is based upon <<fread>>. |
Supporting OS subroutines required: <<fread>>. */ |
#if defined(LIBC_SCCS) && !defined(lint) |
static char sccsid[] = "%W% (Berkeley) %G%"; |
#endif /* LIBC_SCCS and not lint */ |
#include <_ansi.h> |
#include <stdio.h> |
int |
_DEFUN(getw, (fp), |
register FILE *fp) |
{ |
int result; |
if (fread ((char*)&result, sizeof (result), 1, fp) != 1) |
return EOF; |
return result; |
} |
/contrib/sdk/sources/newlib/libc/stdio/getwc.c |
---|
0,0 → 1,52 |
/*- |
* Copyright (c) 2002 Tim J. Robbins. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include "local.h" |
#undef getwc |
wint_t |
_DEFUN(_getwc_r, (ptr, fp), |
struct _reent *ptr _AND |
FILE *fp) |
{ |
return _fgetwc_r (ptr, fp); |
} |
/* |
* Synonym for fgetwc(). The only difference is that getwc(), if it is a |
* macro, may evaluate `fp' more than once. |
*/ |
wint_t |
_DEFUN(getwc, (fp), |
FILE *fp) |
{ |
return fgetwc(fp); |
} |
/contrib/sdk/sources/newlib/libc/stdio/getwc_u.c |
---|
0,0 → 1,53 |
/* |
* Copyright (c) 2014 Red Hat, Inc. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
#define _GNU_SOURCE |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include "local.h" |
#undef getwc_unlocked |
wint_t |
_DEFUN(_getwc_unlocked_r, (ptr, fp), |
struct _reent *ptr _AND |
FILE *fp) |
{ |
return _fgetwc_unlocked_r (ptr, fp); |
} |
/* |
* Synonym for fgetwc_unlocked(). The only difference is that getwc(), if it is |
* a macro, may evaluate `fp' more than once. |
*/ |
wint_t |
_DEFUN(getwc_unlocked, (fp), |
FILE *fp) |
{ |
return fgetwc_unlocked(fp); |
} |
/contrib/sdk/sources/newlib/libc/stdio/getwchar.c |
---|
0,0 → 1,126 |
/*- |
* Copyright (c) 2002 Tim J. Robbins. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
/* |
FUNCTION |
<<getwchar>>, <<getwchar_unlocked>>---read a wide character from standard input |
INDEX |
getwchar |
INDEX |
getwchar_unlocked |
INDEX |
_getwchar_r |
INDEX |
_getwchar_unlocked_r |
ANSI_SYNOPSIS |
#include <wchar.h> |
wint_t getwchar(void); |
#define _GNU_SOURCE |
#include <wchar.h> |
wint_t getwchar_unlocked(void); |
#include <wchar.h> |
wint_t _getwchar_r(struct _reent *<[reent]>); |
#include <wchar.h> |
wint_t _getwchar_unlocked_r(struct _reent *<[reent]>); |
TRAD_SYNOPSIS |
#include <wchar.h> |
wint_t getwchar(); |
#define _GNU_SOURCE |
#include <wchar.h> |
wint_t getwchar_unlocked(); |
#include <wchar.h> |
wint_t _getwchar_r(<[reent]>) |
char * <[reent]>; |
#include <wchar.h> |
wint_t _getwchar_unlocked_r(<[reent]>) |
char * <[reent]>; |
DESCRIPTION |
<<getwchar>> function or macro is the wide character equivalent of |
the <<getchar>> function. You can use <<getwchar>> to get the next |
wide character from the standard input stream. As a side effect, |
<<getwchar>> advances the standard input's current position indicator. |
<<getwchar_unlocked>> is a non-thread-safe version of <<getwchar>>. |
<<getwchar_unlocked>> may only safely be used within a scope |
protected by flockfile() (or ftrylockfile()) and funlockfile(). This |
function may safely be used in a multi-threaded program if and only |
if they are called while the invoking thread owns the (FILE *) |
object, as is the case after a successful call to the flockfile() or |
ftrylockfile() functions. If threads are disabled, then |
<<getwchar_unlocked>> is equivalent to <<getwchar>>. |
The alternate functions <<_getwchar_r>> and <<_getwchar_unlocked_r>> are |
reentrant versions of the above. The extra argument <[reent]> is a pointer to |
a reentrancy structure. |
RETURNS |
The next wide character cast to <<wint_t>>, unless there is no more |
data, or the host system reports a read error; in either of these |
situations, <<getwchar>> returns <<WEOF>>. |
You can distinguish the two situations that cause an <<WEOF>> result by |
using `<<ferror(stdin)>>' and `<<feof(stdin)>>'. |
PORTABILITY |
<<getwchar>> is required by C99. |
<<getwchar_unlocked>> is a GNU extension. |
*/ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include "local.h" |
#undef getwchar |
wint_t |
_DEFUN (_getwchar_r, (ptr), |
struct _reent *ptr) |
{ |
return _fgetwc_r (ptr, stdin); |
} |
/* |
* Synonym for fgetwc(stdin). |
*/ |
wint_t |
_DEFUN_VOID (getwchar) |
{ |
_REENT_SMALL_CHECK_INIT (_REENT); |
return fgetwc (stdin); |
} |
/contrib/sdk/sources/newlib/libc/stdio/getwchar_u.c |
---|
0,0 → 1,51 |
/* |
* Copyright (c) 2014 Red Hat, Inc. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
#define _GNU_SOURCE |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include "local.h" |
#undef getwchar_unlocked |
wint_t |
_DEFUN (_getwchar_unlocked_r, (ptr), |
struct _reent *ptr) |
{ |
return _fgetwc_unlocked_r (ptr, stdin); |
} |
/* |
* Synonym for fgetwc_unlocked(stdin). |
*/ |
wint_t |
_DEFUN_VOID (getwchar_unlocked) |
{ |
_REENT_SMALL_CHECK_INIT (_REENT); |
return fgetwc_unlocked (stdin); |
} |
/contrib/sdk/sources/newlib/libc/stdio/putw.c |
---|
0,0 → 1,65 |
/* |
* Copyright (c) 1990 The Regents of the University of California. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms are permitted |
* provided that the above copyright notice and this paragraph are |
* duplicated in all such forms and that any documentation, |
* advertising materials, and other materials related to such |
* distribution and use acknowledge that the software was developed |
* by the University of California, Berkeley. The name of the |
* University may not be used to endorse or promote products derived |
* from this software without specific prior written permission. |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
*/ |
/* |
FUNCTION |
<<putw>>---write a word (int) |
INDEX |
putw |
ANSI_SYNOPSIS |
#include <stdio.h> |
int putw(int <[w]>, FILE *<[fp]>); |
TRAD_SYNOPSIS |
#include <stdio.h> |
int putw(<w>, <[fp]>) |
int <w>; |
FILE *<[fp]>; |
DESCRIPTION |
<<putw>> is a function, defined in <<stdio.h>>. You can use <<putw>> |
to write a word to the file or stream identified by <[fp]>. As a side |
effect, <<putw>> advances the file's current position indicator. |
RETURNS |
Zero on success, <<EOF>> on failure. |
PORTABILITY |
<<putw>> is a remnant of K&R C; it is not part of any ISO C Standard. |
<<fwrite>> should be used instead. In fact, this implementation of |
<<putw>> is based upon <<fwrite>>. |
Supporting OS subroutines required: <<fwrite>>. |
*/ |
#if defined(LIBC_SCCS) && !defined(lint) |
static char sccsid[] = "%W% (Berkeley) %G%"; |
#endif /* LIBC_SCCS and not lint */ |
#include <stdio.h> |
int |
_DEFUN(putw, (w, fp), |
int w _AND |
register FILE *fp) |
{ |
if (fwrite ((_CONST char*)&w, sizeof (w), 1, fp) != 1) |
return EOF; |
return 0; |
} |
/contrib/sdk/sources/newlib/libc/stdio/putwc.c |
---|
0,0 → 1,53 |
/*- |
* Copyright (c) 2002 Tim J. Robbins. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include "local.h" |
#undef putwc |
wint_t |
_DEFUN(_putwc_r, (ptr, wc, fp), |
struct _reent *ptr _AND |
wchar_t wc _AND |
FILE *fp) |
{ |
return _fputwc_r (ptr, wc, fp); |
} |
/* |
* Synonym for fputwc(). The only difference is that putwc(), if it is a |
* macro, may evaluate `fp' more than once. |
*/ |
wint_t |
_DEFUN(putwc, (wc, fp), |
wchar_t wc _AND |
FILE *fp) |
{ |
return fputwc (wc, fp); |
} |
/contrib/sdk/sources/newlib/libc/stdio/putwc_u.c |
---|
0,0 → 1,54 |
/*- |
* Copyright (c) 2014 Red Hat, Inc. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
#define _GNU_SOURCE |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include "local.h" |
#undef putwc_unlocked |
wint_t |
_DEFUN(_putwc_unlocked_r, (ptr, wc, fp), |
struct _reent *ptr _AND |
wchar_t wc _AND |
FILE *fp) |
{ |
return _fputwc_unlocked_r (ptr, wc, fp); |
} |
/* |
* Synonym for fputwc_unlocked(). The only difference is that putwc_unlocked(), |
* if it is a macro, may evaluate `fp' more than once. |
*/ |
wint_t |
_DEFUN(putwc_unlocked, (wc, fp), |
wchar_t wc _AND |
FILE *fp) |
{ |
return fputwc_unlocked (wc, fp); |
} |
/contrib/sdk/sources/newlib/libc/stdio/putwchar.c |
---|
0,0 → 1,125 |
/*- |
* Copyright (c) 2002 Tim J. Robbins. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
/* |
FUNCTION |
<<putwchar>>, <<putwchar_unlocked>>---write a wide character to standard output |
INDEX |
putwchar |
INDEX |
putwchar_unlocked |
INDEX |
_putwchar_r |
INDEX |
_putwchar_unlocked_r |
ANSI_SYNOPSIS |
#include <wchar.h> |
wint_t putwchar(wchar_t <[wc]>); |
#include <wchar.h> |
wint_t putwchar_unlocked(wchar_t <[wc]>); |
#include <wchar.h> |
wint_t _putwchar_r(struct _reent *<[reent]>, wchar_t <[wc]>); |
#include <wchar.h> |
wint_t _putwchar_unlocked_r(struct _reent *<[reent]>, wchar_t <[wc]>); |
TRAD_SYNOPSIS |
#include <wchar.h> |
wint_t putwchar(<[wc]>) |
wchar_t <[wc]>; |
#include <wchar.h> |
wint_t putwchar_unlocked(<[wc]>) |
wchar_t <[wc]>; |
#include <wchar.h> |
wint_t _putwchar_r(<[reent]>, <[wc]>) |
struct _reent *<[reent]>; |
wchar_t <[wc]>; |
#include <wchar.h> |
wint_t _putwchar_unlocked_r(<[reent]>, <[wc]>) |
struct _reent *<[reent]>; |
wchar_t <[wc]>; |
DESCRIPTION |
The <<putwchar>> function or macro is the wide-character equivalent of |
the <<putchar>> function. It writes the wide character wc to stdout. |
<<putwchar_unlocked>> is a non-thread-safe version of <<putwchar>>. |
<<putwchar_unlocked>> may only safely be used within a scope |
protected by flockfile() (or ftrylockfile()) and funlockfile(). This |
function may safely be used in a multi-threaded program if and only |
if they are called while the invoking thread owns the (FILE *) |
object, as is the case after a successful call to the flockfile() or |
ftrylockfile() functions. If threads are disabled, then |
<<putwchar_unlocked>> is equivalent to <<putwchar>>. |
The alternate functions <<_putwchar_r>> and <<_putwchar_unlocked_r>> are |
reentrant versions of the above. The extra argument <[reent]> is a pointer |
to a reentrancy structure. |
RETURNS |
If successful, <<putwchar>> returns its argument <[wc]>. If an error |
intervenes, the result is <<EOF>>. You can use `<<ferror(stdin)>>' to |
query for errors. |
PORTABILITY |
<<putwchar>> is required by C99. |
<<putwchar_unlocked>> is a GNU extension. |
*/ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include "local.h" |
#undef putwchar |
wint_t |
_DEFUN(_putwchar_r, (ptr, wc), |
struct _reent *ptr _AND |
wchar_t wc) |
{ |
return _fputwc_r (ptr, wc, stdout); |
} |
/* |
* Synonym for fputwc(wc, stdout). |
*/ |
wint_t |
_DEFUN(putwchar, (wc), |
wchar_t wc) |
{ |
_REENT_SMALL_CHECK_INIT (_REENT); |
return fputwc (wc, stdout); |
} |
/contrib/sdk/sources/newlib/libc/stdio/putwchar_u.c |
---|
0,0 → 1,53 |
/* |
* Copyright (c) 2014 Red Hat, Inc. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
#define _GNU_SOURCE |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include "local.h" |
#undef putwchar_unlocked |
wint_t |
_DEFUN(_putwchar_unlocked_r, (ptr, wc), |
struct _reent *ptr _AND |
wchar_t wc) |
{ |
return _fputwc_unlocked_r (ptr, wc, stdout); |
} |
/* |
* Synonym for fputwc_unlocked(wc, stdout). |
*/ |
wint_t |
_DEFUN(putwchar_unlocked, (wc), |
wchar_t wc) |
{ |
_REENT_SMALL_CHECK_INIT (_REENT); |
return fputwc_unlocked (wc, stdout); |
} |
/contrib/sdk/sources/newlib/libc/stdio/swprintf.c |
---|
0,0 → 1,635 |
/* |
* Copyright (c) 1990, 2007 The Regents of the University of California. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms are permitted |
* provided that the above copyright notice and this paragraph are |
* duplicated in all such forms and that any documentation, |
* advertising materials, and other materials related to such |
* distribution and use acknowledge that the software was developed |
* by the University of California, Berkeley. The name of the |
* University may not be used to endorse or promote products derived |
* from this software without specific prior written permission. |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
*/ |
/* |
FUNCTION |
<<swprintf>>, <<fwprintf>>, <<wprintf>>---wide character format output |
INDEX |
fwprintf |
INDEX |
_fwprintf_r |
INDEX |
wprintf |
INDEX |
_wprintf_r |
INDEX |
swprintf |
INDEX |
_swprintf_r |
ANSI_SYNOPSIS |
#include <wchar.h> |
int wprintf(const wchar_t *<[format]>, ...); |
int fwprintf(FILE *__restrict <[fd]>, |
const wchar_t *__restrict <[format]>, ...); |
int swprintf(wchar_t *__restrict <[str]>, size_t <[size]>, |
const wchar_t *__restrict <[format]>, ...); |
int _wprintf_r(struct _reent *<[ptr]>, const wchar_t *<[format]>, ...); |
int _fwprintf_r(struct _reent *<[ptr]>, FILE *<[fd]>, |
const wchar_t *<[format]>, ...); |
int _swprintf_r(struct _reent *<[ptr]>, wchar_t *<[str]>, |
size_t <[size]>, const wchar_t *<[format]>, ...); |
DESCRIPTION |
<<wprintf>> accepts a series of arguments, applies to each a |
format specifier from <<*<[format]>>>, and writes the |
formatted data to <<stdout>>, without a terminating NUL |
wide character. The behavior of <<wprintf>> is undefined if there |
are not enough arguments for the format or if any argument is not the |
right type for the corresponding conversion specifier. <<wprintf>> |
returns when it reaches the end of the format string. If there are |
more arguments than the format requires, excess arguments are |
ignored. |
<<fwprintf>> is like <<wprintf>>, except that output is directed |
to the stream <[fd]> rather than <<stdout>>. |
<<swprintf>> is like <<wprintf>>, except that output is directed |
to the buffer <[str]> with a terminating wide <<NUL>>, and the |
resulting string length is limited to at most <[size]> wide characters, |
including the terminating <<NUL>>. It is considered an error if the |
output (including the terminating wide-<<NULL>>) does not fit into |
<[size]> wide characters. (This error behavior is not the same as for |
<<snprintf>>, which <<swprintf>> is otherwise completely analogous to. |
While <<snprintf>> allows the needed size to be known simply by giving |
<[size]>=0, <<swprintf>> does not, giving an error instead.) |
For <<swprintf>> the behavior is undefined if the output |
<<*<[str]>>> overlaps with one of the arguments. Behavior is also |
undefined if the argument for <<%n>> within <<*<[format]>>> |
overlaps another argument. |
<[format]> is a pointer to a wide character string containing two |
types of objects: ordinary characters (other than <<%>>), |
which are copied unchanged to the output, and conversion |
specifications, each of which is introduced by <<%>>. (To |
include <<%>> in the output, use <<%%>> in the format string.) |
A conversion specification has the following form: |
. %[<[pos]>][<[flags]>][<[width]>][.<[prec]>][<[size]>]<[type]> |
The fields of the conversion specification have the following |
meanings: |
O+ |
o <[pos]> |
Conversions normally consume arguments in the order that they |
are presented. However, it is possible to consume arguments |
out of order, and reuse an argument for more than one |
conversion specification (although the behavior is undefined |
if the same argument is requested with different types), by |
specifying <[pos]>, which is a decimal integer followed by |
'$'. The integer must be between 1 and <NL_ARGMAX> from |
limits.h, and if argument <<%n$>> is requested, all earlier |
arguments must be requested somewhere within <[format]>. If |
positional parameters are used, then all conversion |
specifications except for <<%%>> must specify a position. |
This positional parameters method is a POSIX extension to the C |
standard definition for the functions. |
o <[flags]> |
<[flags]> is an optional sequence of characters which control |
output justification, numeric signs, decimal points, trailing |
zeros, and octal and hex prefixes. The flag characters are |
minus (<<->>), plus (<<+>>), space ( ), zero (<<0>>), sharp |
(<<#>>), and quote (<<'>>). They can appear in any |
combination, although not all flags can be used for all |
conversion specification types. |
o+ |
o ' |
A POSIX extension to the C standard. However, this |
implementation presently treats it as a no-op, which |
is the default behavior for the C locale, anyway. (If |
it did what it is supposed to, when <[type]> were <<i>>, |
<<d>>, <<u>>, <<f>>, <<F>>, <<g>>, or <<G>>, the |
integer portion of the conversion would be formatted |
with thousands' grouping wide characters.) |
o - |
The result of the conversion is left |
justified, and the right is padded with |
blanks. If you do not use this flag, the |
result is right justified, and padded on the |
left. |
o + |
The result of a signed conversion (as |
determined by <[type]> of <<d>>, <<i>>, <<a>>, |
<<A>>, <<e>>, <<E>>, <<f>>, <<F>>, <<g>>, or |
<<G>>) will always begin with a plus or minus |
sign. (If you do not use this flag, positive |
values do not begin with a plus sign.) |
o " " (space) |
If the first character of a signed conversion |
specification is not a sign, or if a signed |
conversion results in no characters, the |
result will begin with a space. If the space |
( ) flag and the plus (<<+>>) flag both |
appear, the space flag is ignored. |
o 0 |
If the <[type]> character is <<d>>, <<i>>, |
<<o>>, <<u>>, <<x>>, <<X>>, <<a>>, <<A>>, |
<<e>>, <<E>>, <<f>>, <<F>>, <<g>>, or <<G>>: leading |
zeros are used to pad the field width |
(following any indication of sign or base); no |
spaces are used for padding. If the zero |
(<<0>>) and minus (<<->>) flags both appear, |
the zero (<<0>>) flag will be ignored. For |
<<d>>, <<i>>, <<o>>, <<u>>, <<x>>, and <<X>> |
conversions, if a precision <[prec]> is |
specified, the zero (<<0>>) flag is ignored. |
Note that <<0>> is interpreted as a flag, not |
as the beginning of a field width. |
o # |
The result is to be converted to an |
alternative form, according to the <[type]> |
character. |
o- |
The alternative form output with the # flag depends on the <[type]> |
character: |
o+ |
o o |
Increases precision to force the first |
digit of the result to be a zero. |
o x |
A non-zero result will have a <<0x>> |
prefix. |
o X |
A non-zero result will have a <<0X>> |
prefix. |
o a, A, e, E, f, or F |
The result will always contain a |
decimal point even if no digits follow |
the point. (Normally, a decimal point |
appears only if a digit follows it.) |
Trailing zeros are removed. |
o g or G |
The result will always contain a |
decimal point even if no digits follow |
the point. Trailing zeros are not |
removed. |
o all others |
Undefined. |
o- |
o <[width]> |
<[width]> is an optional minimum field width. You can |
either specify it directly as a decimal integer, or |
indirectly by using instead an asterisk (<<*>>), in |
which case an <<int>> argument is used as the field |
width. If positional arguments are used, then the |
width must also be specified positionally as <<*m$>>, |
with m as a decimal integer. Negative field widths |
are treated as specifying the minus (<<->>) flag for |
left justfication, along with a positive field width. |
The resulting format may be wider than the specified |
width. |
o <[prec]> |
<[prec]> is an optional field; if present, it is |
introduced with `<<.>>' (a period). You can specify |
the precision either directly as a decimal integer or |
indirectly by using an asterisk (<<*>>), in which case |
an <<int>> argument is used as the precision. If |
positional arguments are used, then the precision must |
also be specified positionally as <<*m$>>, with m as a |
decimal integer. Supplying a negative precision is |
equivalent to omitting the precision. If only a |
period is specified the precision is zero. The effect |
depends on the conversion <[type]>. |
o+ |
o d, i, o, u, x, or X |
Minimum number of digits to appear. If no |
precision is given, defaults to 1. |
o a or A |
Number of digits to appear after the decimal |
point. If no precision is given, the |
precision defaults to the minimum needed for |
an exact representation. |
o e, E, f or F |
Number of digits to appear after the decimal |
point. If no precision is given, the |
precision defaults to 6. |
o g or G |
Maximum number of significant digits. A |
precision of 0 is treated the same as a |
precision of 1. If no precision is given, the |
precision defaults to 6. |
o s or S |
Maximum number of characters to print from the |
string. If no precision is given, the entire |
string is printed. |
o all others |
undefined. |
o- |
o <[size]> |
<[size]> is an optional modifier that changes the data |
type that the corresponding argument has. Behavior is |
unspecified if a size is given that does not match the |
<[type]>. |
o+ |
o hh |
With <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, or |
<<X>>, specifies that the argument should be |
converted to a <<signed char>> or <<unsigned |
char>> before printing. |
With <<n>>, specifies that the argument is a |
pointer to a <<signed char>>. |
o h |
With <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, or |
<<X>>, specifies that the argument should be |
converted to a <<short>> or <<unsigned short>> |
before printing. |
With <<n>>, specifies that the argument is a |
pointer to a <<short>>. |
o l |
With <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, or |
<<X>>, specifies that the argument is a |
<<long>> or <<unsigned long>>. |
With <<c>>, specifies that the argument has |
type <<wint_t>>. |
With <<s>>, specifies that the argument is a |
pointer to <<wchar_t>>. |
With <<n>>, specifies that the argument is a |
pointer to a <<long>>. |
With <<a>>, <<A>>, <<e>>, <<E>>, <<f>>, <<F>>, |
<<g>>, or <<G>>, has no effect (because of |
vararg promotion rules, there is no need to |
distinguish between <<float>> and <<double>>). |
o ll |
With <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, or |
<<X>>, specifies that the argument is a |
<<long long>> or <<unsigned long long>>. |
With <<n>>, specifies that the argument is a |
pointer to a <<long long>>. |
o j |
With <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, or |
<<X>>, specifies that the argument is an |
<<intmax_t>> or <<uintmax_t>>. |
With <<n>>, specifies that the argument is a |
pointer to an <<intmax_t>>. |
o z |
With <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, or |
<<X>>, specifies that the argument is a <<size_t>>. |
With <<n>>, specifies that the argument is a |
pointer to a <<size_t>>. |
o t |
With <<d>>, <<i>>, <<o>>, <<u>>, <<x>>, or |
<<X>>, specifies that the argument is a |
<<ptrdiff_t>>. |
With <<n>>, specifies that the argument is a |
pointer to a <<ptrdiff_t>>. |
o L |
With <<a>>, <<A>>, <<e>>, <<E>>, <<f>>, <<F>>, |
<<g>>, or <<G>>, specifies that the argument |
is a <<long double>>. |
o- |
o <[type]> |
<[type]> specifies what kind of conversion <<wprintf>> |
performs. Here is a table of these: |
o+ |
o % |
Prints the percent character (<<%>>). |
o c |
If no <<l>> qualifier is present, the int argument shall |
be converted to a wide character as if by calling |
the btowc() function and the resulting wide character |
shall be written. Otherwise, the wint_t argument |
shall be converted to wchar_t, and written. |
o C |
Short for <<%lc>>. A POSIX extension to the C standard. |
o s |
If no <<l>> qualifier is present, the application |
shall ensure that the argument is a pointer to a |
character array containing a character sequence |
beginning in the initial shift state. Characters |
from the array shall be converted as if by repeated |
calls to the mbrtowc() function, with the conversion |
state described by an mbstate_t object initialized to |
zero before the first character is converted, and |
written up to (but not including) the terminating |
null wide character. If the precision is specified, |
no more than that many wide characters shall be |
written. If the precision is not specified, or is |
greater than the size of the array, the application |
shall ensure that the array contains a null wide |
character. |
If an <<l>> qualifier is present, the application |
shall ensure that the argument is a pointer to an |
array of type wchar_t. Wide characters from the array |
shall be written up to (but not including) a |
terminating null wide character. If no precision is |
specified, or is greater than the size of the array, |
the application shall ensure that the array contains |
a null wide character. If a precision is specified, |
no more than that many wide characters shall be |
written. |
o S |
Short for <<%ls>>. A POSIX extension to the C standard. |
o d or i |
Prints a signed decimal integer; takes an |
<<int>>. Leading zeros are inserted as |
necessary to reach the precision. A value of 0 with |
a precision of 0 produces an empty string. |
o o |
Prints an unsigned octal integer; takes an |
<<unsigned>>. Leading zeros are inserted as |
necessary to reach the precision. A value of 0 with |
a precision of 0 produces an empty string. |
o u |
Prints an unsigned decimal integer; takes an |
<<unsigned>>. Leading zeros are inserted as |
necessary to reach the precision. A value of 0 with |
a precision of 0 produces an empty string. |
o x |
Prints an unsigned hexadecimal integer (using |
<<abcdef>> as digits beyond <<9>>); takes an |
<<unsigned>>. Leading zeros are inserted as |
necessary to reach the precision. A value of 0 with |
a precision of 0 produces an empty string. |
o X |
Like <<x>>, but uses <<ABCDEF>> as digits |
beyond <<9>>. |
o f |
Prints a signed value of the form |
<<[-]9999.9999>>, with the precision |
determining how many digits follow the decimal |
point; takes a <<double>> (remember that |
<<float>> promotes to <<double>> as a vararg). |
The low order digit is rounded to even. If |
the precision results in at most DECIMAL_DIG |
digits, the result is rounded correctly; if |
more than DECIMAL_DIG digits are printed, the |
result is only guaranteed to round back to the |
original value. |
If the value is infinite, the result is |
<<inf>>, and no zero padding is performed. If |
the value is not a number, the result is |
<<nan>>, and no zero padding is performed. |
o F |
Like <<f>>, but uses <<INF>> and <<NAN>> for |
non-finite numbers. |
o e |
Prints a signed value of the form |
<<[-]9.9999e[+|-]999>>; takes a <<double>>. |
The digit before the decimal point is non-zero |
if the value is non-zero. The precision |
determines how many digits appear between |
<<.>> and <<e>>, and the exponent always |
contains at least two digits. The value zero |
has an exponent of zero. If the value is not |
finite, it is printed like <<f>>. |
o E |
Like <<e>>, but using <<E>> to introduce the |
exponent, and like <<F>> for non-finite |
values. |
o g |
Prints a signed value in either <<f>> or <<e>> |
form, based on the given value and |
precision---an exponent less than -4 or |
greater than the precision selects the <<e>> |
form. Trailing zeros and the decimal point |
are printed only if necessary; takes a |
<<double>>. |
o G |
Like <<g>>, except use <<F>> or <<E>> form. |
o a |
Prints a signed value of the form |
<<[-]0x1.ffffp[+|-]9>>; takes a <<double>>. |
The letters <<abcdef>> are used for digits |
beyond <<9>>. The precision determines how |
many digits appear after the decimal point. |
The exponent contains at least one digit, and |
is a decimal value representing the power of |
2; a value of 0 has an exponent of 0. |
Non-finite values are printed like <<f>>. |
o A |
Like <<a>>, except uses <<X>>, <<P>>, and |
<<ABCDEF>> instead of lower case. |
o n |
Takes a pointer to <<int>>, and stores a count |
of the number of bytes written so far. No |
output is created. |
o p |
Takes a pointer to <<void>>, and prints it in |
an implementation-defined format. This |
implementation is similar to <<%#tx>>), except |
that <<0x>> appears even for the NULL pointer. |
o m |
Prints the output of <<strerror(errno)>>; no |
argument is required. A GNU extension. |
o- |
O- |
<<_wprintf_r>>, <<_fwprintf_r>>, <<_swprintf_r>>, are simply |
reentrant versions of the functions above. |
RETURNS |
On success, <<swprintf>> return the number of wide characters in |
the output string, except the concluding <<NUL>> is not counted. |
<<wprintf>> and <<fwprintf>> return the number of characters transmitted. |
If an error occurs, the result of <<wprintf>>, <<fwprintf>>, and |
<<swprintf>> is a negative value. For <<wprintf>> and <<fwprintf>>, |
<<errno>> may be set according to <<fputwc>>. For <<swprintf>>, <<errno>> |
may be set to EOVERFLOW if <[size]> is greater than INT_MAX / sizeof (wchar_t), |
or when the output does not fit into <[size]> wide characters (including the |
terminating wide <<NULL>>). |
BUGS |
The ``''' (quote) flag does not work when locale's thousands_sep is not empty. |
PORTABILITY |
POSIX-1.2008 with extensions; C99 (compliant except for POSIX extensions). |
Depending on how newlib was configured, not all format specifiers are |
supported. |
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, |
<<lseek>>, <<read>>, <<sbrk>>, <<write>>. |
*/ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include <stdarg.h> |
#include <limits.h> |
#include <errno.h> |
#include "local.h" |
/* NOTE: _swprintf_r() should be identical to swprintf() except for the |
* former having ptr as a parameter and the latter needing to declare it as |
* a variable set to _REENT. */ |
int |
_DEFUN(_swprintf_r, (ptr, str, size, fmt), |
struct _reent *ptr _AND |
wchar_t *str _AND |
size_t size _AND |
_CONST wchar_t *fmt _DOTS) |
{ |
int ret; |
va_list ap; |
FILE f; |
if (size > INT_MAX / sizeof (wchar_t)) |
{ |
ptr->_errno = EOVERFLOW; /* POSIX extension */ |
return EOF; |
} |
f._flags = __SWR | __SSTR; |
f._bf._base = f._p = (unsigned char *) str; |
f._bf._size = f._w = (size > 0 ? (size - 1) * sizeof (wchar_t) : 0); |
f._file = -1; /* No file. */ |
va_start (ap, fmt); |
ret = _svfwprintf_r (ptr, &f, fmt, ap); |
va_end (ap); |
/* _svfwprintf_r() does not put in a terminating NUL, so add one if |
* appropriate, which is whenever size is > 0. _svfwprintf_r() stops |
* after n-1, so always just put at the end. */ |
if (size > 0) { |
*(wchar_t *)f._p = L'\0'; /* terminate the string */ |
} |
if(ret >= size) { |
/* _svfwprintf_r() returns how many wide characters it would have printed |
* if there were enough space. Return an error if too big to fit in str, |
* unlike snprintf, which returns the size needed. */ |
ptr->_errno = EOVERFLOW; /* POSIX extension */ |
ret = -1; |
} |
return (ret); |
} |
#ifndef _REENT_ONLY |
int |
_DEFUN(swprintf, (str, size, fmt), |
wchar_t *__restrict str _AND |
size_t size _AND |
_CONST wchar_t *__restrict fmt _DOTS) |
{ |
int ret; |
va_list ap; |
FILE f; |
struct _reent *ptr = _REENT; |
if (size > INT_MAX / sizeof (wchar_t)) |
{ |
ptr->_errno = EOVERFLOW; /* POSIX extension */ |
return EOF; |
} |
f._flags = __SWR | __SSTR; |
f._bf._base = f._p = (unsigned char *) str; |
f._bf._size = f._w = (size > 0 ? (size - 1) * sizeof (wchar_t) : 0); |
f._file = -1; /* No file. */ |
va_start (ap, fmt); |
ret = _svfwprintf_r (ptr, &f, fmt, ap); |
va_end (ap); |
/* _svfwprintf_r() does not put in a terminating NUL, so add one if |
* appropriate, which is whenever size is > 0. _svfwprintf_r() stops |
* after n-1, so always just put at the end. */ |
if (size > 0) { |
*(wchar_t *)f._p = L'\0'; /* terminate the string */ |
} |
if(ret >= size) { |
/* _svfwprintf_r() returns how many wide characters it would have printed |
* if there were enough space. Return an error if too big to fit in str, |
* unlike snprintf, which returns the size needed. */ |
ptr->_errno = EOVERFLOW; /* POSIX extension */ |
ret = -1; |
} |
return (ret); |
} |
#endif |
/contrib/sdk/sources/newlib/libc/stdio/swscanf.c |
---|
0,0 → 1,487 |
/* |
* Copyright (c) 1990 The Regents of the University of California. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms are permitted |
* provided that the above copyright notice and this paragraph are |
* duplicated in all such forms and that any documentation, |
* advertising materials, and other materials related to such |
* distribution and use acknowledge that the software was developed |
* by the University of California, Berkeley. The name of the |
* University may not be used to endorse or promote products derived |
* from this software without specific prior written permission. |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
*/ |
/* |
FUNCTION |
<<swscanf>>, <<fwscanf>>, <<wscanf>>---scan and format wide character input |
INDEX |
wscanf |
INDEX |
_wscanf_r |
INDEX |
fwscanf |
INDEX |
_fwscanf_r |
INDEX |
swscanf |
INDEX |
_swscanf_r |
ANSI_SYNOPSIS |
#include <stdio.h> |
int wscanf(const wchar_t *__restrict <[format]>, ...); |
int fwscanf(FILE *__restrict <[fd]>, |
const wchar_t *__restrict <[format]>, ...); |
int swscanf(const wchar_t *__restrict <[str]>, |
const wchar_t *__restrict <[format]>, ...); |
int _wscanf_r(struct _reent *<[ptr]>, const wchar_t *<[format]>, ...); |
int _fwscanf_r(struct _reent *<[ptr]>, FILE *<[fd]>, |
const wchar_t *<[format]>, ...); |
int _swscanf_r(struct _reent *<[ptr]>, const wchar_t *<[str]>, |
const wchar_t *<[format]>, ...); |
TRAD_SYNOPSIS |
#include <stdio.h> |
int wscanf(<[format]> [, <[arg]>, ...]) |
wchar_t *__restrict <[format]>; |
int fwscanf(<[fd]>, <[format]> [, <[arg]>, ...]); |
FILE *<[fd]>; |
wchar_t *<[format]>; |
int swscanf(<[str]>, <[format]> [, <[arg]>, ...]); |
wchar_t *__restrict <[str]>; |
wchar_t *__restrict <[format]>; |
int _wscanf_r(<[ptr]>, <[format]> [, <[arg]>, ...]) |
struct _reent *<[ptr]>; |
wchar_t *<[format]>; |
int _fwscanf_r(<[ptr]>, <[fd]>, <[format]> [, <[arg]>, ...]); |
struct _reent *<[ptr]>; |
FILE *<[fd]>; |
wchar_t *<[format]>; |
int _swscanf_r(<[ptr]>, <[str]>, <[format]> [, <[arg]>, ...]); |
struct _reent *<[ptr]>; |
wchar_t *<[str]>; |
wchar_t *<[format]>; |
DESCRIPTION |
<<wscanf>> scans a series of input fields from standard input, |
one wide character at a time. Each field is interpreted according to |
a format specifier passed to <<wscanf>> in the format string at |
<<*<[format]>>>. <<wscanf>> stores the interpreted input from |
each field at the address passed to it as the corresponding argument |
following <[format]>. You must supply the same number of |
format specifiers and address arguments as there are input fields. |
There must be sufficient address arguments for the given format |
specifiers; if not the results are unpredictable and likely |
disasterous. Excess address arguments are merely ignored. |
<<wscanf>> often produces unexpected results if the input diverges from |
an expected pattern. Since the combination of <<gets>> or <<fgets>> |
followed by <<swscanf>> is safe and easy, that is the preferred way |
to be certain that a program is synchronized with input at the end |
of a line. |
<<fwscanf>> and <<swscanf>> are identical to <<wscanf>>, other than the |
source of input: <<fwscanf>> reads from a file, and <<swscanf>> |
from a string. |
The routines <<_wscanf_r>>, <<_fwscanf_r>>, and <<_swscanf_r>> are reentrant |
versions of <<wscanf>>, <<fwscanf>>, and <<swscanf>> that take an additional |
first argument pointing to a reentrancy structure. |
The string at <<*<[format]>>> is a wide character sequence composed |
of zero or more directives. Directives are composed of |
one or more whitespace characters, non-whitespace characters, |
and format specifications. |
Whitespace characters are blank (<< >>), tab (<<\t>>), or |
newline (<<\n>>). |
When <<wscanf>> encounters a whitespace character in the format string |
it will read (but not store) all consecutive whitespace characters |
up to the next non-whitespace character in the input. |
Non-whitespace characters are all other ASCII characters except the |
percent sign (<<%>>). When <<wscanf>> encounters a non-whitespace |
character in the format string it will read, but not store |
a matching non-whitespace character. |
Format specifications tell <<wscanf>> to read and convert characters |
from the input field into specific types of values, and store then |
in the locations specified by the address arguments. |
Trailing whitespace is left unread unless explicitly |
matched in the format string. |
The format specifiers must begin with a percent sign (<<%>>) |
and have the following form: |
. %[*][<[width]>][<[size]>]<[type]> |
Each format specification begins with the percent character (<<%>>). |
The other fields are: |
O+ |
o * |
an optional marker; if present, it suppresses interpretation and |
assignment of this input field. |
o <[width]> |
an optional maximum field width: a decimal integer, |
which controls the maximum number of characters that |
will be read before converting the current input field. If the |
input field has fewer than <[width]> characters, <<wscanf>> |
reads all the characters in the field, and then |
proceeds with the next field and its format specification. |
If a whitespace or a non-convertable wide character occurs |
before <[width]> character are read, the characters up |
to that character are read, converted, and stored. |
Then <<wscanf>> proceeds to the next format specification. |
o <[size]> |
<<h>>, <<j>>, <<l>>, <<L>>, <<t>>, and <<z>> are optional size |
characters which override the default way that <<wscanf>> |
interprets the data type of the corresponding argument. |
@multitable @columnfractions 0.18 0.30 0.52 |
@headitem |
Modifier |
@tab |
Type(s) |
@tab |
@item |
hh |
@tab |
d, i, o, u, x, n |
@tab |
convert input to char, store in char object |
@item |
h |
@tab |
d, i, o, u, x, n |
@tab |
convert input to short, store in short object |
@item |
h |
@tab |
e, f, c, s, p |
@tab |
no effect |
@item |
j |
@tab |
d, i, o, u, x, n |
@tab |
convert input to intmax_t, store in intmax_t object |
@item |
j |
@tab |
all others |
@tab |
no effect |
@item |
l |
@tab |
d, i, o, u, x, n |
@tab |
convert input to long, store in long object |
@item |
l |
@tab |
e, f, g |
@tab |
convert input to double, store in a double object |
@item |
l |
@tab |
c, s, [ |
@tab |
the input is stored in a wchar_t object |
@item |
l |
@tab |
p |
@tab |
no effect |
@item |
ll |
@tab |
d, i, o, u, x, n |
@tab |
convert to long long, store in long long object |
@item |
L |
@tab |
d, i, o, u, x, n |
@tab |
convert to long long, store in long long object |
@item |
L |
@tab |
e, f, g, E, G |
@tab |
convert to long double, store in long double object |
@item |
L |
@tab |
all others |
@tab |
no effect |
@item |
t |
@tab |
d, i, o, u, x, n |
@tab |
convert input to ptrdiff_t, store in ptrdiff_t object |
@item |
t |
@tab |
all others |
@tab |
no effect |
@item |
z |
@tab |
d, i, o, u, x, n |
@tab |
convert input to size_t, store in size_t object |
@item |
z |
@tab |
all others |
@tab |
no effect |
@end multitable |
o <[type]> |
A character to specify what kind of conversion |
<<wscanf>> performs. Here is a table of the conversion |
characters: |
o+ |
o % |
No conversion is done; the percent character (<<%>>) is stored. |
o c |
Scans one wide character. Corresponding <[arg]>: <<(char *arg)>>. |
Otherwise, if an <<l>> specifier is present, the corresponding |
<[arg]> is a <<(wchar_t *arg)>>. |
o s |
Reads a character string into the array supplied. |
Corresponding <[arg]>: <<(char arg[])>>. |
If an <<l>> specifier is present, the corresponding <[arg]> is a <<(wchar_t *arg)>>. |
o [<[pattern]>] |
Reads a non-empty character string into memory |
starting at <[arg]>. This area must be large |
enough to accept the sequence and a |
terminating null character which will be added |
automatically. (<[pattern]> is discussed in the paragraph following |
this table). Corresponding <[arg]>: <<(char *arg)>>. |
If an <<l>> specifier is present, the corresponding <[arg]> is |
a <<(wchar_t *arg)>>. |
o d |
Reads a decimal integer into the corresponding <[arg]>: <<(int *arg)>>. |
o o |
Reads an octal integer into the corresponding <[arg]>: <<(int *arg)>>. |
o u |
Reads an unsigned decimal integer into the corresponding |
<[arg]>: <<(unsigned int *arg)>>. |
o x,X |
Read a hexadecimal integer into the corresponding <[arg]>: |
<<(int *arg)>>. |
o e, f, g |
Read a floating-point number into the corresponding <[arg]>: |
<<(float *arg)>>. |
o E, F, G |
Read a floating-point number into the corresponding <[arg]>: |
<<(double *arg)>>. |
o i |
Reads a decimal, octal or hexadecimal integer into the |
corresponding <[arg]>: <<(int *arg)>>. |
o n |
Stores the number of characters read in the corresponding |
<[arg]>: <<(int *arg)>>. |
o p |
Stores a scanned pointer. ANSI C leaves the details |
to each implementation; this implementation treats |
<<%p>> exactly the same as <<%U>>. Corresponding |
<[arg]>: <<(void **arg)>>. |
o- |
A <[pattern]> of characters surrounded by square brackets can be used |
instead of the <<s>> type character. <[pattern]> is a set of |
characters which define a search set of possible characters making up |
the <<wscanf>> input field. If the first character in the brackets is a |
caret (<<^>>), the search set is inverted to include all ASCII characters |
except those between the brackets. There is no range facility as is |
defined in the corresponding non-wide character scanf functions. |
Ranges are not part of the POSIX standard. |
Here are some <[pattern]> examples: |
o+ |
o %[abcd] |
matches wide character strings containing only |
<<a>>, <<b>>, <<c>>, and <<d>>. |
o %[^abcd] |
matches wide character strings containing any characters except |
<<a>>, <<b>>, <<c>>, or <<d>>. |
o %[A-DW-Z] |
Note: No wide character ranges, so this expression matches wide |
character strings containing <<A>>, <<->>, <<D>>, <<W>>, <<Z>>. |
o- |
Floating point numbers (for field types <<e>>, <<f>>, <<g>>, <<E>>, |
<<F>>, <<G>>) must correspond to the following general form: |
. [+/-] ddddd[.]ddd [E|e[+|-]ddd] |
where objects inclosed in square brackets are optional, and <<ddd>> |
represents decimal, octal, or hexadecimal digits. |
O- |
RETURNS |
<<wscanf>> returns the number of input fields successfully |
scanned, converted and stored; the return value does |
not include scanned fields which were not stored. |
If <<wscanf>> attempts to read at end-of-file, the return |
value is <<EOF>>. |
If no fields were stored, the return value is <<0>>. |
<<wscanf>> might stop scanning a particular field before |
reaching the normal field end character, or may |
terminate entirely. |
<<wscanf>> stops scanning and storing the current field |
and moves to the next input field (if any) |
in any of the following situations: |
O+ |
o The assignment suppressing character (<<*>>) appears |
after the <<%>> in the format specification; the current |
input field is scanned but not stored. |
o <[width]> characters have been read (<[width]> is a |
width specification, a positive decimal integer). |
o The next wide character read cannot be converted |
under the the current format (for example, |
if a <<Z>> is read when the format is decimal). |
o The next wide character in the input field does not appear |
in the search set (or does appear in the inverted search set). |
O- |
When <<wscanf>> stops scanning the current input field for one of |
these reasons, the next character is considered unread and |
used as the first character of the following input field, or the |
first character in a subsequent read operation on the input. |
<<wscanf>> will terminate under the following circumstances: |
O+ |
o The next wide character in the input field conflicts |
with a corresponding non-whitespace character in the |
format string. |
o The next wide character in the input field is <<WEOF>>. |
o The format string has been exhausted. |
O- |
When the format string contains a wide character sequence that is |
not part of a format specification, the same wide character |
sequence must appear in the input; <<wscanf>> will |
scan but not store the matched characters. If a |
conflict occurs, the first conflicting wide character remains in the |
input as if it had never been read. |
PORTABILITY |
<<wscanf>> is C99, POSIX-1.2008. |
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, |
<<lseek>>, <<read>>, <<sbrk>>, <<write>>. |
*/ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include <stdarg.h> |
#include "local.h" |
#ifndef _REENT_ONLY |
int |
swscanf (_CONST wchar_t *__restrict str, _CONST wchar_t *__restrict fmt, ...) |
{ |
int ret; |
va_list ap; |
FILE f; |
f._flags = __SRD | __SSTR; |
f._bf._base = f._p = (unsigned char *) str; |
f._bf._size = f._r = wcslen (str) * sizeof (wchar_t); |
f._read = __seofread; |
f._ub._base = NULL; |
f._lb._base = NULL; |
f._file = -1; /* No file. */ |
va_start (ap, fmt); |
ret = __ssvfwscanf_r (_REENT, &f, fmt, ap); |
va_end (ap); |
return ret; |
} |
#endif /* !_REENT_ONLY */ |
int |
_swscanf_r (struct _reent *ptr, _CONST wchar_t *str, _CONST wchar_t *fmt, ...) |
{ |
int ret; |
va_list ap; |
FILE f; |
f._flags = __SRD | __SSTR; |
f._bf._base = f._p = (unsigned char *) str; |
f._bf._size = f._r = wcslen (str) * sizeof (wchar_t); |
f._read = __seofread; |
f._ub._base = NULL; |
f._lb._base = NULL; |
f._file = -1; /* No file. */ |
va_start (ap, fmt); |
ret = __ssvfwscanf_r (ptr, &f, fmt, ap); |
va_end (ap); |
return ret; |
} |
/contrib/sdk/sources/newlib/libc/stdio/ungetwc.c |
---|
0,0 → 1,117 |
/*- |
* Copyright (c) 2002-2004 Tim J. Robbins. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
/* |
FUNCTION |
<<ungetwc>>---push wide character data back into a stream |
INDEX |
ungetwc |
INDEX |
_ungetwc_r |
ANSI_SYNOPSIS |
#include <stdio.h> |
#include <wchar.h> |
wint_t ungetwc(wint_t <[wc]>, FILE *<[stream]>); |
wint_t _ungetwc_r(struct _reent *<[reent]>, wint_t <[wc]>, FILE *<[stream]>); |
DESCRIPTION |
<<ungetwc>> is used to return wide characters back to <[stream]> to be |
read again. If <[wc]> is WEOF, the stream is unchanged. Otherwise, the |
wide character <[wc]> is put back on the stream, and subsequent reads will see |
the wide chars pushed back in reverse order. Pushed wide chars are lost if the |
stream is repositioned, such as by <<fseek>>, <<fsetpos>>, or |
<<rewind>>. |
The underlying file is not changed, but it is possible to push back |
something different than what was originally read. Ungetting a |
character will clear the end-of-stream marker, and decrement the file |
position indicator. Pushing back beyond the beginning of a file gives |
unspecified behavior. |
The alternate function <<_ungetwc_r>> is a reentrant version. The |
extra argument <[reent]> is a pointer to a reentrancy structure. |
RETURNS |
The wide character pushed back, or <<WEOF>> on error. |
PORTABILITY |
C99 |
*/ |
#include <_ansi.h> |
#include <reent.h> |
#include <errno.h> |
#include <limits.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <wchar.h> |
#include "local.h" |
wint_t |
_DEFUN(_ungetwc_r, (ptr, wc, fp), |
struct _reent *ptr _AND |
wint_t wc _AND |
register FILE *fp) |
{ |
char buf[MB_LEN_MAX]; |
size_t len; |
_newlib_flockfile_start (fp); |
ORIENT (fp, 1); |
if (wc == WEOF) |
wc = WEOF; |
else if ((len = _wcrtomb_r(ptr, buf, wc, &fp->_mbstate)) == (size_t)-1) |
{ |
fp->_flags |= __SERR; |
wc = WEOF; |
} |
else |
while (len-- != 0) |
if (_ungetc_r(ptr, (unsigned char)buf[len], fp) == EOF) |
{ |
wc = WEOF; |
break; |
} |
_newlib_flockfile_end (fp); |
return wc; |
} |
/* |
* MT-safe version. |
*/ |
wint_t |
_DEFUN(ungetwc, (wint_t wc, FILE *fp), |
wint_t wc _AND |
FILE *fp) |
{ |
struct _reent *reent = _REENT; |
CHECK_INIT (reent, fp); |
return _ungetwc_r (reent, wc, fp); |
} |
/contrib/sdk/sources/newlib/libc/stdio/vfwprintf.c |
---|
0,0 → 1,2019 |
/* |
* Copyright (c) 1990 The Regents of the University of California. |
* All rights reserved. |
* |
* This code is derived from software contributed to Berkeley by |
* Chris Torek. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* 1. Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* 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 |
* without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
* HOWEVER CAUSED AND 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 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
*/ |
/* |
FUNCTION |
<<vfwprintf>>, <<vwprintf>>, <<vswprintf>>---wide character format argument list |
INDEX |
vfwprintf |
INDEX |
_vfwprintf_r |
INDEX |
vwprintf |
INDEX |
_vwprintf_r |
INDEX |
vswprintf |
INDEX |
_vswprintf_r |
ANSI_SYNOPSIS |
#include <stdio.h> |
#include <stdarg.h> |
#include <wchar.h> |
int vwprintf(const wchar_t *__restrict <[fmt]>, va_list <[list]>); |
int vfwprintf(FILE *__restrict <[fp]>, |
const wchar_t *__restrict <[fmt]>, va_list <[list]>); |
int vswprintf(wchar_t * __restrict <[str]>, size_t <[size]>, |
const wchar_t *__ restrict <[fmt]>, va_list <[list]>); |
int _vwprintf_r(struct _reent *<[reent]>, const wchar_t *<[fmt]>, |
va_list <[list]>); |
int _vfwprintf_r(struct _reent *<[reent]>, FILE *<[fp]>, |
const wchar_t *<[fmt]>, va_list <[list]>); |
int _vswprintf_r(struct _reent *<[reent]>, wchar_t *<[str]>, |
size_t <[size]>, const wchar_t *<[fmt]>, va_list <[list]>); |
DESCRIPTION |
<<vwprintf>>, <<vfwprintf>> and <<vswprintf>> are (respectively) variants |
of <<wprintf>>, <<fwprintf>> and <<swprintf>>. They differ only in allowing |
their caller to pass the variable argument list as a <<va_list>> object |
(initialized by <<va_start>>) rather than directly accepting a variable |
number of arguments. The caller is responsible for calling <<va_end>>. |
<<_vwprintf_r>>, <<_vfwprintf_r>> and <<_vswprintf_r>> are reentrant |
versions of the above. |
RETURNS |
The return values are consistent with the corresponding functions. |
PORTABILITY |
POSIX-1.2008 with extensions; C99 (compliant except for POSIX extensions). |
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, |
<<lseek>>, <<read>>, <<sbrk>>, <<write>>. |
SEEALSO |
<<wprintf>>, <<fwprintf>> and <<swprintf>>. |
*/ |
/* |
* Actual wprintf innards. |
* |
* This code is large and complicated... |
*/ |
#include <newlib.h> |
#ifdef INTEGER_ONLY |
# define VFWPRINTF vfiwprintf |
# ifdef STRING_ONLY |
# define _VFWPRINTF_R _svfiwprintf_r |
# else |
# define _VFWPRINTF_R _vfiwprintf_r |
# endif |
#else |
# define VFWPRINTF vfwprintf |
# ifdef STRING_ONLY |
# define _VFWPRINTF_R _svfwprintf_r |
# else |
# define _VFWPRINTF_R _vfwprintf_r |
# endif |
# ifndef NO_FLOATING_POINT |
# define FLOATING_POINT |
# endif |
#endif |
#define _NO_POS_ARGS |
#ifdef _WANT_IO_POS_ARGS |
# undef _NO_POS_ARGS |
#endif |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <limits.h> |
#include <stdint.h> |
#include <wchar.h> |
#include <sys/lock.h> |
#include <stdarg.h> |
#include "local.h" |
#include "fvwrite.h" |
#include "vfieeefp.h" |
#ifdef __HAVE_LOCALE_INFO_EXTENDED__ |
#include "../locale/lnumeric.h" |
#endif |
/* 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 |
preferred over _dtoa_r. */ |
#define _NO_LONGDBL |
#if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG) |
#undef _NO_LONGDBL |
#endif |
#define _NO_LONGLONG |
#if defined _WANT_IO_LONG_LONG \ |
&& (defined __GNUC__ || __STDC_VERSION__ >= 199901L) |
# undef _NO_LONGLONG |
#endif |
int _EXFUN(_VFWPRINTF_R, (struct _reent *, FILE *, _CONST wchar_t *, va_list)); |
/* Defined in vfprintf.c. */ |
#ifdef _FVWRITE_IN_STREAMIO |
# ifdef STRING_ONLY |
# define __SPRINT __ssprint_r |
# else |
# define __SPRINT __sprint_r |
# endif |
int _EXFUN(__SPRINT, (struct _reent *, FILE *, register struct __suio *)); |
#else |
# ifdef STRING_ONLY |
# define __SPRINT __ssputs_r |
# else |
# define __SPRINT __sfputs_r |
# endif |
int _EXFUN(__SPRINT, (struct _reent *, FILE *, _CONST char *, size_t)); |
#endif |
#ifndef STRING_ONLY |
#ifdef _UNBUF_STREAM_OPT |
/* |
* Helper function for `fprintf to unbuffered unix file': creates a |
* temporary buffer. We only work on write-only files; this avoids |
* worries about ungetc buffers and so forth. |
*/ |
static int |
_DEFUN(__sbwprintf, (rptr, fp, fmt, ap), |
struct _reent *rptr _AND |
register FILE *fp _AND |
_CONST wchar_t *fmt _AND |
va_list ap) |
{ |
int ret; |
FILE fake; |
unsigned char buf[BUFSIZ]; |
/* copy the important variables */ |
fake._flags = fp->_flags & ~__SNBF; |
fake._flags2 = fp->_flags2; |
fake._file = fp->_file; |
fake._cookie = fp->_cookie; |
fake._write = fp->_write; |
/* set up the buffer */ |
fake._bf._base = fake._p = buf; |
fake._bf._size = fake._w = sizeof (buf); |
fake._lbfsize = 0; /* not actually used, but Just In Case */ |
#ifndef __SINGLE_THREAD__ |
__lock_init_recursive (fake._lock); |
#endif |
/* do the work, then copy any error status */ |
ret = _VFWPRINTF_R (rptr, &fake, fmt, ap); |
if (ret >= 0 && _fflush_r (rptr, &fake)) |
ret = EOF; |
if (fake._flags & __SERR) |
fp->_flags |= __SERR; |
#ifndef __SINGLE_THREAD__ |
__lock_close_recursive (fake._lock); |
#endif |
return (ret); |
} |
#endif /* _UNBUF_STREAM_OPT */ |
#endif /* !STRING_ONLY */ |
#if defined (FLOATING_POINT) || defined (_WANT_IO_C99_FORMATS) |
# include <locale.h> |
#endif |
#ifdef FLOATING_POINT |
# include <math.h> |
/* For %La, an exponent of 15 bits occupies the exponent character, a |
sign, and up to 5 digits. */ |
# define MAXEXPLEN 7 |
# define DEFPREC 6 |
# ifdef _NO_LONGDBL |
extern char *_dtoa_r _PARAMS((struct _reent *, double, int, |
int, int *, int *, char **)); |
# define _PRINTF_FLOAT_TYPE double |
# define _DTOA_R _dtoa_r |
# define FREXP frexp |
# else /* !_NO_LONGDBL */ |
extern char *_ldtoa_r _PARAMS((struct _reent *, _LONG_DOUBLE, int, |
int, int *, int *, char **)); |
extern int _EXFUN(_ldcheck,(_LONG_DOUBLE *)); |
# define _PRINTF_FLOAT_TYPE _LONG_DOUBLE |
# define _DTOA_R _ldtoa_r |
/* FIXME - frexpl is not yet supported; and cvt infloops if (double)f |
converts a finite value into infinity. */ |
/* # define FREXP frexpl */ |
# define FREXP(f,e) ((_LONG_DOUBLE) frexp ((double)f, e)) |
# endif /* !_NO_LONGDBL */ |
static wchar_t *wcvt(struct _reent *, _PRINTF_FLOAT_TYPE, int, int, wchar_t *, |
int *, int, int *, wchar_t *, int); |
static int wexponent(wchar_t *, int, int); |
#endif /* FLOATING_POINT */ |
/* BUF must be big enough for the maximum %#llo (assuming long long is |
at most 64 bits, this would be 23 characters), the maximum |
multibyte character %C, and the maximum default precision of %La |
(assuming long double is at most 128 bits with 113 bits of |
mantissa, this would be 29 characters). %e, %f, and %g use |
reentrant storage shared with mprec. All other formats that use |
buf get by with fewer characters. Making BUF slightly bigger |
reduces the need for malloc in %.*a and %ls/%S, when large precision or |
long strings are processed. |
The bigger size of 100 bytes is used on systems which allow number |
strings using the locale's grouping character. Since that's a multibyte |
value, we should use a conservative value. |
*/ |
#ifdef _WANT_IO_C99_FORMATS |
#define BUF 100 |
#else |
#define BUF 40 |
#endif |
#if defined _MB_CAPABLE && MB_LEN_MAX > BUF |
# undef BUF |
# define BUF MB_LEN_MAX |
#endif |
#ifndef _NO_LONGLONG |
# define quad_t long long |
# define u_quad_t unsigned long long |
#else |
# define quad_t long |
# define u_quad_t unsigned long |
#endif |
typedef quad_t * quad_ptr_t; |
typedef _PTR void_ptr_t; |
typedef char * char_ptr_t; |
typedef wchar_t* wchar_ptr_t; |
typedef long * long_ptr_t; |
typedef int * int_ptr_t; |
typedef short * short_ptr_t; |
#ifndef _NO_POS_ARGS |
# ifdef NL_ARGMAX |
# define MAX_POS_ARGS NL_ARGMAX |
# else |
# define MAX_POS_ARGS 32 |
# endif |
union arg_val |
{ |
int val_int; |
u_int val_u_int; |
long val_long; |
u_long val_u_long; |
float val_float; |
double val_double; |
_LONG_DOUBLE val__LONG_DOUBLE; |
int_ptr_t val_int_ptr_t; |
short_ptr_t val_short_ptr_t; |
long_ptr_t val_long_ptr_t; |
char_ptr_t val_char_ptr_t; |
wchar_ptr_t val_wchar_ptr_t; |
quad_ptr_t val_quad_ptr_t; |
void_ptr_t val_void_ptr_t; |
quad_t val_quad_t; |
u_quad_t val_u_quad_t; |
wint_t val_wint_t; |
}; |
static union arg_val * |
_EXFUN(get_arg, (struct _reent *data, int n, wchar_t *fmt, |
va_list *ap, int *numargs, union arg_val *args, |
int *arg_type, wchar_t **last_fmt)); |
#endif /* !_NO_POS_ARGS */ |
/* |
* Macros for converting digits to letters and vice versa |
*/ |
#define to_digit(c) ((c) - L'0') |
#define is_digit(c) ((unsigned)to_digit (c) <= 9) |
#define to_char(n) ((n) + L'0') |
/* |
* Flags used during conversion. |
*/ |
#define ALT 0x001 /* alternate form */ |
#define HEXPREFIX 0x002 /* add 0x or 0X prefix */ |
#define LADJUST 0x004 /* left adjustment */ |
#define LONGDBL 0x008 /* long double */ |
#define LONGINT 0x010 /* long integer */ |
#ifndef _NO_LONGLONG |
# define QUADINT 0x020 /* quad integer */ |
#else /* ifdef _NO_LONGLONG, make QUADINT equivalent to LONGINT, so |
that %lld behaves the same as %ld, not as %d, as expected if: |
sizeof (long long) = sizeof long > sizeof int */ |
# define QUADINT LONGINT |
#endif |
#define SHORTINT 0x040 /* short integer */ |
#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */ |
#define FPT 0x100 /* Floating point number */ |
#ifdef _WANT_IO_C99_FORMATS |
# define CHARINT 0x200 /* char as integer */ |
#else /* define as 0, to make SARG and UARG occupy fewer instructions */ |
# define CHARINT 0 |
#endif |
#ifdef _WANT_IO_C99_FORMATS |
# define GROUPING 0x400 /* use grouping ("'" flag) */ |
#endif |
#ifndef STRING_ONLY |
int |
_DEFUN(VFWPRINTF, (fp, fmt0, ap), |
FILE *__restrict fp _AND |
_CONST wchar_t *__restrict fmt0 _AND |
va_list ap) |
{ |
int result; |
result = _VFWPRINTF_R (_REENT, fp, fmt0, ap); |
return result; |
} |
#endif /* STRING_ONLY */ |
int |
_DEFUN(_VFWPRINTF_R, (data, fp, fmt0, ap), |
struct _reent *data _AND |
FILE * fp _AND |
_CONST wchar_t *fmt0 _AND |
va_list ap) |
{ |
register wchar_t *fmt; /* format string */ |
register wint_t ch; /* character from fmt */ |
register int n, m; /* handy integers (short term usage) */ |
register wchar_t *cp; /* handy char pointer (short term usage) */ |
register int flags; /* flags as above */ |
wchar_t *fmt_anchor; /* current format spec being processed */ |
#ifndef _NO_POS_ARGS |
int N; /* arg number */ |
int arg_index; /* index into args processed directly */ |
int numargs; /* number of varargs read */ |
wchar_t *saved_fmt; /* saved fmt pointer */ |
union arg_val args[MAX_POS_ARGS]; |
int arg_type[MAX_POS_ARGS]; |
int is_pos_arg; /* is current format positional? */ |
int old_is_pos_arg; /* is current format positional? */ |
#endif |
int ret; /* return value accumulator */ |
int width; /* width from format (%8d), or 0 */ |
int prec; /* precision from format (%.3d), or -1 */ |
wchar_t sign; /* sign prefix (' ', '+', '-', or \0) */ |
#ifdef _WANT_IO_C99_FORMATS |
/* locale specific numeric grouping */ |
wchar_t thousands_sep = L'\0'; |
const char *grouping = NULL; |
#endif |
#if defined (_MB_CAPABLE) && !defined (__HAVE_LOCALE_INFO_EXTENDED__) \ |
&& (defined (FLOATING_POINT) || defined (_WANT_IO_C99_FORMATS)) |
mbstate_t state; /* mbtowc calls from library must not change state */ |
#endif |
#ifdef FLOATING_POINT |
wchar_t decimal_point; |
wchar_t softsign; /* temporary negative sign for floats */ |
union { int i; _PRINTF_FLOAT_TYPE fp; } _double_ = {0}; |
# define _fpvalue (_double_.fp) |
int expt; /* integer value of exponent */ |
int expsize = 0; /* character count for expstr */ |
wchar_t expstr[MAXEXPLEN]; /* buffer for exponent string */ |
int lead; /* sig figs before decimal or group sep */ |
#endif /* FLOATING_POINT */ |
#if defined (FLOATING_POINT) || defined (_WANT_IO_C99_FORMATS) |
int ndig = 0; /* actual number of digits returned by cvt */ |
#endif |
#if defined (FLOATING_POINT) && defined (_WANT_IO_C99_FORMATS) |
int nseps; /* number of group separators with ' */ |
int nrepeats; /* number of repeats of the last group */ |
#endif |
u_quad_t _uquad; /* integer arguments %[diouxX] */ |
enum { OCT, DEC, HEX } base;/* base for [diouxX] conversion */ |
int dprec; /* a copy of prec if [diouxX], 0 otherwise */ |
int realsz; /* field size expanded by dprec */ |
int size = 0; /* size of converted field or string */ |
wchar_t *xdigs = NULL; /* digits for [xX] conversion */ |
#ifdef _FVWRITE_IN_STREAMIO |
#define NIOV 8 |
struct __suio uio; /* output information: summary */ |
struct __siov iov[NIOV];/* ... and individual io vectors */ |
register struct __siov *iovp;/* for PRINT macro */ |
#endif |
wchar_t buf[BUF]; /* space for %c, %ls/%S, %[diouxX], %[aA] */ |
wchar_t ox[2]; /* space for 0x hex-prefix */ |
wchar_t *malloc_buf = NULL;/* handy pointer for malloced buffers */ |
/* |
* Choose PADSIZE to trade efficiency vs. size. If larger printf |
* fields occur frequently, increase PADSIZE and make the initialisers |
* below longer. |
*/ |
#define PADSIZE 16 /* pad chunk size */ |
static _CONST wchar_t blanks[PADSIZE] = |
{L' ',L' ',L' ',L' ',L' ',L' ',L' ',L' ', |
L' ',L' ',L' ',L' ',L' ',L' ',L' ',L' '}; |
static _CONST wchar_t zeroes[PADSIZE] = |
{L'0',L'0',L'0',L'0',L'0',L'0',L'0',L'0', |
L'0',L'0',L'0',L'0',L'0',L'0',L'0',L'0'}; |
#ifdef FLOATING_POINT |
#ifdef _MB_CAPABLE |
#ifdef __HAVE_LOCALE_INFO_EXTENDED__ |
decimal_point = *__get_current_numeric_locale ()->wdecimal_point; |
#else |
{ |
size_t nconv; |
memset (&state, '\0', sizeof (state)); |
nconv = _mbrtowc_r (data, &decimal_point, |
_localeconv_r (data)->decimal_point, |
MB_CUR_MAX, &state); |
if (nconv == (size_t) -1 || nconv == (size_t) -2) |
decimal_point = L'.'; |
} |
#endif |
#else |
decimal_point = (wchar_t) *_localeconv_r (data)->decimal_point; |
#endif |
#endif |
/* |
* BEWARE, these `goto error' on error, and PAD uses `n'. |
*/ |
#ifdef _FVWRITE_IN_STREAMIO |
#define PRINT(ptr, len) { \ |
iovp->iov_base = (char *) (ptr); \ |
iovp->iov_len = (len) * sizeof (wchar_t); \ |
uio.uio_resid += (len) * sizeof (wchar_t); \ |
iovp++; \ |
if (++uio.uio_iovcnt >= NIOV) { \ |
if (__SPRINT(data, fp, &uio)) \ |
goto error; \ |
iovp = iov; \ |
} \ |
} |
#define PAD(howmany, with) { \ |
if ((n = (howmany)) > 0) { \ |
while (n > PADSIZE) { \ |
PRINT (with, PADSIZE); \ |
n -= PADSIZE; \ |
} \ |
PRINT (with, n); \ |
} \ |
} |
#define PRINTANDPAD(p, ep, len, with) { \ |
int n = (ep) - (p); \ |
if (n > (len)) \ |
n = (len); \ |
if (n > 0) \ |
PRINT((p), n); \ |
PAD((len) - (n > 0 ? n : 0), (with)); \ |
} |
#define FLUSH() { \ |
if (uio.uio_resid && __SPRINT(data, fp, &uio)) \ |
goto error; \ |
uio.uio_iovcnt = 0; \ |
iovp = iov; \ |
} |
#else |
#define PRINT(ptr, len) { \ |
if (__SPRINT (data, fp, (_CONST char *)(ptr), (len) * sizeof (wchar_t)) == EOF) \ |
goto error; \ |
} |
#define PAD(howmany, with) { \ |
if ((n = (howmany)) > 0) { \ |
while (n > PADSIZE) { \ |
PRINT (with, PADSIZE); \ |
n -= PADSIZE; \ |
} \ |
PRINT (with, n); \ |
} \ |
} |
#define PRINTANDPAD(p, ep, len, with) { \ |
int n = (ep) - (p); \ |
if (n > (len)) \ |
n = (len); \ |
if (n > 0) \ |
PRINT((p), n); \ |
PAD((len) - (n > 0 ? n : 0), (with)); \ |
} |
#define FLUSH() |
#endif |
/* Macros to support positional arguments */ |
#ifndef _NO_POS_ARGS |
# define GET_ARG(n, ap, type) \ |
(is_pos_arg \ |
? (n < numargs \ |
? args[n].val_##type \ |
: get_arg (data, n, fmt_anchor, &ap, &numargs, args, \ |
arg_type, &saved_fmt)->val_##type) \ |
: (arg_index++ < numargs \ |
? args[n].val_##type \ |
: (numargs < MAX_POS_ARGS \ |
? args[numargs++].val_##type = va_arg (ap, type) \ |
: va_arg (ap, type)))) |
#else |
# define GET_ARG(n, ap, type) (va_arg (ap, type)) |
#endif |
/* |
* To extend shorts properly, we need both signed and unsigned |
* argument extraction methods. |
*/ |
#ifndef _NO_LONGLONG |
#define SARG() \ |
(flags&QUADINT ? GET_ARG (N, ap, quad_t) : \ |
flags&LONGINT ? GET_ARG (N, ap, long) : \ |
flags&SHORTINT ? (long)(short)GET_ARG (N, ap, int) : \ |
flags&CHARINT ? (long)(signed char)GET_ARG (N, ap, int) : \ |
(long)GET_ARG (N, ap, int)) |
#define UARG() \ |
(flags&QUADINT ? GET_ARG (N, ap, u_quad_t) : \ |
flags&LONGINT ? GET_ARG (N, ap, u_long) : \ |
flags&SHORTINT ? (u_long)(u_short)GET_ARG (N, ap, int) : \ |
flags&CHARINT ? (u_long)(unsigned char)GET_ARG (N, ap, int) : \ |
(u_long)GET_ARG (N, ap, u_int)) |
#else |
#define SARG() \ |
(flags&LONGINT ? GET_ARG (N, ap, long) : \ |
flags&SHORTINT ? (long)(short)GET_ARG (N, ap, int) : \ |
flags&CHARINT ? (long)(signed char)GET_ARG (N, ap, int) : \ |
(long)GET_ARG (N, ap, int)) |
#define UARG() \ |
(flags&LONGINT ? GET_ARG (N, ap, u_long) : \ |
flags&SHORTINT ? (u_long)(u_short)GET_ARG (N, ap, int) : \ |
flags&CHARINT ? (u_long)(unsigned char)GET_ARG (N, ap, int) : \ |
(u_long)GET_ARG (N, ap, u_int)) |
#endif |
#ifndef STRING_ONLY |
/* Initialize std streams if not dealing with sprintf family. */ |
CHECK_INIT (data, fp); |
_newlib_flockfile_start (fp); |
ORIENT(fp, 1); |
/* sorry, fwprintf(read_only_file, "") returns EOF, not 0 */ |
if (cantwrite (data, fp)) { |
_newlib_flockfile_exit (fp); |
return (EOF); |
} |
#ifdef _UNBUF_STREAM_OPT |
/* optimise fwprintf(stderr) (and other unbuffered Unix files) */ |
if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && |
fp->_file >= 0) { |
_newlib_flockfile_exit (fp); |
return (__sbwprintf (data, fp, fmt0, ap)); |
} |
#endif |
#else /* STRING_ONLY */ |
/* Create initial buffer if we are called by asprintf family. */ |
if (fp->_flags & __SMBF && !fp->_bf._base) |
{ |
fp->_bf._base = fp->_p = _malloc_r (data, 64); |
if (!fp->_p) |
{ |
data->_errno = ENOMEM; |
return EOF; |
} |
fp->_bf._size = 64; |
} |
#endif /* STRING_ONLY */ |
fmt = (wchar_t *)fmt0; |
#ifdef _FVWRITE_IN_STREAMIO |
uio.uio_iov = iovp = iov; |
uio.uio_resid = 0; |
uio.uio_iovcnt = 0; |
#endif |
ret = 0; |
#ifndef _NO_POS_ARGS |
arg_index = 0; |
saved_fmt = NULL; |
arg_type[0] = -1; |
numargs = 0; |
is_pos_arg = 0; |
#endif |
/* |
* Scan the format for conversions (`%' character). |
*/ |
for (;;) { |
cp = fmt; |
while (*fmt != L'\0' && *fmt != L'%') |
++fmt; |
if ((m = fmt - cp) != 0) { |
PRINT (cp, m); |
ret += m; |
} |
if (*fmt == L'\0') |
goto done; |
fmt_anchor = fmt; |
fmt++; /* skip over '%' */ |
flags = 0; |
dprec = 0; |
width = 0; |
prec = -1; |
sign = L'\0'; |
#ifdef FLOATING_POINT |
lead = 0; |
#ifdef _WANT_IO_C99_FORMATS |
nseps = nrepeats = 0; |
#endif |
#endif |
#ifndef _NO_POS_ARGS |
N = arg_index; |
is_pos_arg = 0; |
#endif |
rflag: ch = *fmt++; |
reswitch: switch (ch) { |
#ifdef _WANT_IO_C99_FORMATS |
case L'\'': |
#ifdef _MB_CAPABLE |
#ifdef __HAVE_LOCALE_INFO_EXTENDED__ |
thousands_sep = *__get_current_numeric_locale ()->wthousands_sep; |
#else |
{ |
size_t nconv; |
memset (&state, '\0', sizeof (state)); |
nconv = _mbrtowc_r (data, &thousands_sep, |
_localeconv_r (data)->thousands_sep, |
MB_CUR_MAX, &state); |
if (nconv == (size_t) -1 || nconv == (size_t) -2) |
thousands_sep = L'\0'; |
} |
#endif |
#else |
thousands_sep = (wchar_t) *_localeconv_r(data)->thousands_sep; |
#endif |
grouping = _localeconv_r (data)->grouping; |
if (thousands_sep && grouping && *grouping) |
flags |= GROUPING; |
goto rflag; |
#endif |
case L' ': |
/* |
* ``If the space and + flags both appear, the space |
* flag will be ignored.'' |
* -- ANSI X3J11 |
*/ |
if (!sign) |
sign = L' '; |
goto rflag; |
case L'#': |
flags |= ALT; |
goto rflag; |
case L'*': |
#ifndef _NO_POS_ARGS |
/* we must check for positional arg used for dynamic width */ |
n = N; |
old_is_pos_arg = is_pos_arg; |
is_pos_arg = 0; |
if (is_digit (*fmt)) { |
wchar_t *old_fmt = fmt; |
n = 0; |
ch = *fmt++; |
do { |
n = 10 * n + to_digit (ch); |
ch = *fmt++; |
} while (is_digit (ch)); |
if (ch == L'$') { |
if (n <= MAX_POS_ARGS) { |
n -= 1; |
is_pos_arg = 1; |
} |
else |
goto error; |
} |
else { |
fmt = old_fmt; |
goto rflag; |
} |
} |
#endif /* !_NO_POS_ARGS */ |
/* |
* ``A negative field width argument is taken as a |
* - flag followed by a positive field width.'' |
* -- ANSI X3J11 |
* They don't exclude field widths read from args. |
*/ |
width = GET_ARG (n, ap, int); |
#ifndef _NO_POS_ARGS |
is_pos_arg = old_is_pos_arg; |
#endif |
if (width >= 0) |
goto rflag; |
width = -width; |
/* FALLTHROUGH */ |
case L'-': |
flags |= LADJUST; |
goto rflag; |
case L'+': |
sign = L'+'; |
goto rflag; |
case L'.': |
if ((ch = *fmt++) == L'*') { |
#ifndef _NO_POS_ARGS |
/* we must check for positional arg used for dynamic width */ |
n = N; |
old_is_pos_arg = is_pos_arg; |
is_pos_arg = 0; |
if (is_digit (*fmt)) { |
wchar_t *old_fmt = fmt; |
n = 0; |
ch = *fmt++; |
do { |
n = 10 * n + to_digit (ch); |
ch = *fmt++; |
} while (is_digit (ch)); |
if (ch == L'$') { |
if (n <= MAX_POS_ARGS) { |
n -= 1; |
is_pos_arg = 1; |
} |
else |
goto error; |
} |
else { |
fmt = old_fmt; |
goto rflag; |
} |
} |
#endif /* !_NO_POS_ARGS */ |
prec = GET_ARG (n, ap, int); |
#ifndef _NO_POS_ARGS |
is_pos_arg = old_is_pos_arg; |
#endif |
if (prec < 0) |
prec = -1; |
goto rflag; |
} |
n = 0; |
while (is_digit (ch)) { |
n = 10 * n + to_digit (ch); |
ch = *fmt++; |
} |
prec = n < 0 ? -1 : n; |
goto reswitch; |
case L'0': |
/* |
* ``Note that 0 is taken as a flag, not as the |
* beginning of a field width.'' |
* -- ANSI X3J11 |
*/ |
flags |= ZEROPAD; |
goto rflag; |
case L'1': case L'2': case L'3': case L'4': |
case L'5': case L'6': case L'7': case L'8': case L'9': |
n = 0; |
do { |
n = 10 * n + to_digit (ch); |
ch = *fmt++; |
} while (is_digit (ch)); |
#ifndef _NO_POS_ARGS |
if (ch == L'$') { |
if (n <= MAX_POS_ARGS) { |
N = n - 1; |
is_pos_arg = 1; |
goto rflag; |
} |
else |
goto error; |
} |
#endif /* !_NO_POS_ARGS */ |
width = n; |
goto reswitch; |
#ifdef FLOATING_POINT |
case L'L': |
flags |= LONGDBL; |
goto rflag; |
#endif |
case L'h': |
#ifdef _WANT_IO_C99_FORMATS |
if (*fmt == L'h') { |
fmt++; |
flags |= CHARINT; |
} else |
#endif |
flags |= SHORTINT; |
goto rflag; |
case L'l': |
#if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG |
if (*fmt == L'l') { |
fmt++; |
flags |= QUADINT; |
} else |
#endif |
flags |= LONGINT; |
goto rflag; |
case L'q': /* GNU extension */ |
flags |= QUADINT; |
goto rflag; |
#ifdef _WANT_IO_C99_FORMATS |
case L'j': |
if (sizeof (intmax_t) == sizeof (long)) |
flags |= LONGINT; |
else |
flags |= QUADINT; |
goto rflag; |
case L'z': |
if (sizeof (size_t) < sizeof (int)) |
/* POSIX states size_t is 16 or more bits, as is short. */ |
flags |= SHORTINT; |
else if (sizeof (size_t) == sizeof (int)) |
/* no flag needed */; |
else if (sizeof (size_t) <= sizeof (long)) |
flags |= LONGINT; |
else |
/* POSIX states that at least one programming |
environment must support size_t no wider than |
long, but that means other environments can |
have size_t as wide as long long. */ |
flags |= QUADINT; |
goto rflag; |
case L't': |
if (sizeof (ptrdiff_t) < sizeof (int)) |
/* POSIX states ptrdiff_t is 16 or more bits, as |
is short. */ |
flags |= SHORTINT; |
else if (sizeof (ptrdiff_t) == sizeof (int)) |
/* no flag needed */; |
else if (sizeof (ptrdiff_t) <= sizeof (long)) |
flags |= LONGINT; |
else |
/* POSIX states that at least one programming |
environment must support ptrdiff_t no wider than |
long, but that means other environments can |
have ptrdiff_t as wide as long long. */ |
flags |= QUADINT; |
goto rflag; |
case L'C': /* POSIX extension */ |
#endif /* _WANT_IO_C99_FORMATS */ |
case L'c': |
cp = buf; |
if (ch == L'c' && !(flags & LONGINT)) { |
wint_t wc = btowc ((int) GET_ARG (N, ap, int)); |
if (wc == WEOF) { |
fp->_flags |= __SERR; |
goto error; |
} |
cp[0] = (wchar_t) wc; |
} |
else |
{ |
cp[0] = GET_ARG (N, ap, int); |
} |
cp[1] = L'\0'; |
size = 1; |
sign = L'\0'; |
break; |
case L'd': |
case L'i': |
_uquad = SARG (); |
#ifndef _NO_LONGLONG |
if ((quad_t)_uquad < 0) |
#else |
if ((long) _uquad < 0) |
#endif |
{ |
_uquad = -_uquad; |
sign = L'-'; |
} |
base = DEC; |
goto number; |
#ifdef FLOATING_POINT |
# ifdef _WANT_IO_C99_FORMATS |
case L'a': |
case L'A': |
case L'F': |
# endif |
case L'e': |
case L'E': |
case L'f': |
case L'g': |
case L'G': |
# ifdef _NO_LONGDBL |
if (flags & LONGDBL) { |
_fpvalue = (double) GET_ARG (N, ap, _LONG_DOUBLE); |
} else { |
_fpvalue = GET_ARG (N, ap, double); |
} |
/* do this before tricky precision changes |
If the output is infinite or NaN, leading |
zeros are not permitted. Otherwise, scanf |
could not read what printf wrote. |
*/ |
if (isinf (_fpvalue)) { |
if (_fpvalue < 0) |
sign = '-'; |
if (ch <= L'G') /* 'A', 'E', 'F', or 'G' */ |
cp = L"INF"; |
else |
cp = L"inf"; |
size = 3; |
flags &= ~ZEROPAD; |
break; |
} |
if (isnan (_fpvalue)) { |
if (ch <= L'G') /* 'A', 'E', 'F', or 'G' */ |
cp = L"NAN"; |
else |
cp = L"nan"; |
size = 3; |
flags &= ~ZEROPAD; |
break; |
} |
# else /* !_NO_LONGDBL */ |
if (flags & LONGDBL) { |
_fpvalue = GET_ARG (N, ap, _LONG_DOUBLE); |
} else { |
_fpvalue = (_LONG_DOUBLE)GET_ARG (N, ap, double); |
} |
/* do this before tricky precision changes */ |
expt = _ldcheck (&_fpvalue); |
if (expt == 2) { |
if (_fpvalue < 0) |
sign = L'-'; |
if (ch <= L'G') /* 'A', 'E', 'F', or 'G' */ |
cp = L"INF"; |
else |
cp = L"inf"; |
size = 3; |
flags &= ~ZEROPAD; |
break; |
} |
if (expt == 1) { |
if (ch <= L'G') /* 'A', 'E', 'F', or 'G' */ |
cp = L"NAN"; |
else |
cp = L"nan"; |
size = 3; |
flags &= ~ZEROPAD; |
break; |
} |
# endif /* !_NO_LONGDBL */ |
cp = buf; |
# ifdef _WANT_IO_C99_FORMATS |
if (ch == L'a' || ch == L'A') { |
ox[0] = L'0'; |
ox[1] = ch == L'a' ? L'x' : L'X'; |
flags |= HEXPREFIX; |
if (prec >= BUF) |
{ |
if ((malloc_buf = |
(wchar_t *)_malloc_r (data, (prec + 1) * sizeof (wchar_t))) |
== NULL) |
{ |
fp->_flags |= __SERR; |
goto error; |
} |
cp = malloc_buf; |
} |
} else |
# endif /* _WANT_IO_C99_FORMATS */ |
if (prec == -1) { |
prec = DEFPREC; |
} else if ((ch == L'g' || ch == L'G') && prec == 0) { |
prec = 1; |
} |
flags |= FPT; |
cp = wcvt (data, _fpvalue, prec, flags, &softsign, |
&expt, ch, &ndig, cp, BUF); |
/* If buf is not large enough for the converted wchar_t |
sequence, call wcvt again with a malloced new buffer. |
This should happen fairly rarely. |
*/ |
if (cp == buf && ndig > BUF && malloc_buf == NULL) { |
if ((malloc_buf = |
(wchar_t *)_malloc_r (data, ndig * sizeof (wchar_t))) |
== NULL) |
{ |
fp->_flags |= __SERR; |
goto error; |
} |
cp = wcvt (data, _fpvalue, prec, flags, &softsign, |
&expt, ch, &ndig, malloc_buf, ndig); |
} |
if (ch == L'g' || ch == L'G') { |
if (expt <= -4 || expt > prec) |
ch -= 2; /* 'e' or 'E' */ |
else |
ch = L'g'; |
} |
# ifdef _WANT_IO_C99_FORMATS |
else if (ch == L'F') |
ch = L'f'; |
# endif |
if (ch <= L'e') { /* 'a', 'A', 'e', or 'E' fmt */ |
--expt; |
expsize = wexponent (expstr, expt, ch); |
size = expsize + ndig; |
if (ndig > 1 || flags & ALT) |
++size; |
# ifdef _WANT_IO_C99_FORMATS |
flags &= ~GROUPING; |
# endif |
} else { |
if (ch == L'f') { /* f fmt */ |
if (expt > 0) { |
size = expt; |
if (prec || flags & ALT) |
size += prec + 1; |
} else /* "0.X" */ |
size = (prec || flags & ALT) |
? prec + 2 |
: 1; |
} else if (expt >= ndig) { /* fixed g fmt */ |
size = expt; |
if (flags & ALT) |
++size; |
} else |
size = ndig + (expt > 0 ? |
1 : 2 - expt); |
# ifdef _WANT_IO_C99_FORMATS |
if ((flags & GROUPING) && expt > 0) { |
/* space for thousands' grouping */ |
nseps = nrepeats = 0; |
lead = expt; |
while (*grouping != CHAR_MAX) { |
if (lead <= *grouping) |
break; |
lead -= *grouping; |
if (grouping[1]) { |
nseps++; |
grouping++; |
} else |
nrepeats++; |
} |
size += nseps + nrepeats; |
} else |
# endif |
lead = expt; |
} |
if (softsign) |
sign = L'-'; |
break; |
#endif /* FLOATING_POINT */ |
#ifdef _GLIBC_EXTENSION |
case L'm': /* GNU extension */ |
{ |
int dummy; |
cp = (wchar_t *) _strerror_r (data, data->_errno, 1, &dummy); |
} |
flags &= ~LONGINT; |
goto string; |
#endif |
case L'n': |
#ifndef _NO_LONGLONG |
if (flags & QUADINT) |
*GET_ARG (N, ap, quad_ptr_t) = ret; |
else |
#endif |
if (flags & LONGINT) |
*GET_ARG (N, ap, long_ptr_t) = ret; |
else if (flags & SHORTINT) |
*GET_ARG (N, ap, short_ptr_t) = ret; |
#ifdef _WANT_IO_C99_FORMATS |
else if (flags & CHARINT) |
*GET_ARG (N, ap, char_ptr_t) = ret; |
#endif |
else |
*GET_ARG (N, ap, int_ptr_t) = ret; |
continue; /* no output */ |
case L'o': |
_uquad = UARG (); |
base = OCT; |
#ifdef _WANT_IO_C99_FORMATS |
flags &= ~GROUPING; |
#endif |
goto nosign; |
case L'p': |
/* |
* ``The argument shall be a pointer to void. The |
* value of the pointer is converted to a sequence |
* of printable characters, in an implementation- |
* defined manner.'' |
* -- ANSI X3J11 |
*/ |
/* NOSTRICT */ |
_uquad = (uintptr_t) GET_ARG (N, ap, void_ptr_t); |
base = HEX; |
xdigs = L"0123456789abcdef"; |
flags |= HEXPREFIX; |
ox[0] = L'0'; |
ox[1] = ch = L'x'; |
goto nosign; |
case L's': |
#ifdef _WANT_IO_C99_FORMATS |
case L'S': /* POSIX extension */ |
#endif |
cp = GET_ARG (N, ap, wchar_ptr_t); |
#ifdef _GLIBC_EXTENSION |
string: |
#endif |
sign = '\0'; |
#ifndef __OPTIMIZE_SIZE__ |
/* Behavior is undefined if the user passed a |
NULL string when precision is not 0. |
However, if we are not optimizing for size, |
we might as well mirror glibc behavior. */ |
if (cp == NULL) { |
cp = L"(null)"; |
size = ((unsigned) prec > 6U) ? 6 : prec; |
} |
else |
#endif /* __OPTIMIZE_SIZE__ */ |
#ifdef _MB_CAPABLE |
if (ch != L'S' && !(flags & LONGINT)) { |
char *arg = (char *) cp; |
size_t insize = 0, nchars = 0, nconv = 0; |
mbstate_t ps; |
wchar_t *p; |
if (prec >= 0) { |
char *p = arg; |
memset ((_PTR)&ps, '\0', sizeof (mbstate_t)); |
while (nchars < (size_t)prec) { |
nconv = mbrlen (p, MB_CUR_MAX, &ps); |
if (nconv == 0 || nconv == (size_t)-1 || |
nconv == (size_t)-2) |
break; |
p += nconv; |
++nchars; |
insize += nconv; |
} |
if (nconv == (size_t) -1 || nconv == (size_t) -2) { |
fp->_flags |= __SERR; |
goto error; |
} |
} else |
insize = strlen(arg); |
if (insize >= BUF) { |
if ((malloc_buf = (wchar_t *) _malloc_r (data, (insize + 1) * sizeof (wchar_t))) |
== NULL) { |
fp->_flags |= __SERR; |
goto error; |
} |
cp = malloc_buf; |
} else |
cp = buf; |
memset ((_PTR)&ps, '\0', sizeof (mbstate_t)); |
p = cp; |
while (insize != 0) { |
nconv = _mbrtowc_r (data, p, arg, insize, &ps); |
if (nconv == 0 || nconv == (size_t)-1 || nconv == (size_t)-2) |
break; |
++p; |
arg += nconv; |
insize -= nconv; |
} |
if (nconv == (size_t) -1 || nconv == (size_t) -2) { |
fp->_flags |= __SERR; |
goto error; |
} |
*p = L'\0'; |
size = p - cp; |
} |
#else |
if (ch != L'S' && !(flags & LONGINT)) { |
char *arg = (char *) cp; |
size_t insize = 0; |
if (prec >= 0) { |
char *p = memchr (arg, '\0', prec); |
insize = p ? p - arg : prec; |
} else |
insize = strlen (arg); |
if (insize >= BUF) { |
if ((malloc_buf = (wchar_t *) _malloc_r (data, (insize + 1) * sizeof (wchar_t))) |
== NULL) { |
fp->_flags |= __SERR; |
goto error; |
} |
cp = malloc_buf; |
} else |
cp = buf; |
for (size = 0; size < insize; ++size) |
cp[size] = arg[size]; |
cp[size] = L'\0'; |
} |
#endif /* _MB_CAPABLE */ |
else if (prec >= 0) { |
/* |
* can't use wcslen; can only look for the |
* NUL in the first `prec' characters, and |
* strlen () will go further. |
*/ |
wchar_t *p = wmemchr (cp, L'\0', prec); |
if (p != NULL) { |
size = p - cp; |
if (size > prec) |
size = prec; |
} else |
size = prec; |
} else |
size = wcslen (cp); |
break; |
case L'u': |
_uquad = UARG (); |
base = DEC; |
goto nosign; |
case L'X': |
xdigs = L"0123456789ABCDEF"; |
goto hex; |
case L'x': |
xdigs = L"0123456789abcdef"; |
hex: _uquad = UARG (); |
base = HEX; |
/* leading 0x/X only if non-zero */ |
if (flags & ALT && _uquad != 0) { |
ox[0] = L'0'; |
ox[1] = ch; |
flags |= HEXPREFIX; |
} |
#ifdef _WANT_IO_C99_FORMATS |
flags &= ~GROUPING; |
#endif |
/* unsigned conversions */ |
nosign: sign = L'\0'; |
/* |
* ``... diouXx conversions ... if a precision is |
* specified, the 0 flag will be ignored.'' |
* -- ANSI X3J11 |
*/ |
number: if ((dprec = prec) >= 0) |
flags &= ~ZEROPAD; |
/* |
* ``The result of converting a zero value with an |
* explicit precision of zero is no characters.'' |
* -- ANSI X3J11 |
*/ |
cp = buf + BUF; |
if (_uquad != 0 || prec != 0) { |
/* |
* Unsigned mod is hard, and unsigned mod |
* by a constant is easier than that by |
* a variable; hence this switch. |
*/ |
switch (base) { |
case OCT: |
do { |
*--cp = to_char (_uquad & 7); |
_uquad >>= 3; |
} while (_uquad); |
/* handle octal leading 0 */ |
if (flags & ALT && *cp != L'0') |
*--cp = L'0'; |
break; |
case DEC: |
/* many numbers are 1 digit */ |
if (_uquad < 10) { |
*--cp = to_char(_uquad); |
break; |
} |
#ifdef _WANT_IO_C99_FORMATS |
ndig = 0; |
#endif |
do { |
*--cp = to_char (_uquad % 10); |
#ifdef _WANT_IO_C99_FORMATS |
ndig++; |
/* If (*grouping == CHAR_MAX) then no |
more grouping */ |
if ((flags & GROUPING) |
&& ndig == *grouping |
&& *grouping != CHAR_MAX |
&& _uquad > 9) { |
*--cp = thousands_sep; |
ndig = 0; |
/* If (grouping[1] == '\0') then we |
have to use *grouping character |
(last grouping rule) for all |
next cases. */ |
if (grouping[1] != '\0') |
grouping++; |
} |
#endif |
_uquad /= 10; |
} while (_uquad != 0); |
break; |
case HEX: |
do { |
*--cp = xdigs[_uquad & 15]; |
_uquad >>= 4; |
} while (_uquad); |
break; |
default: |
cp = L"bug in vfprintf: bad base"; |
size = wcslen (cp); |
goto skipsize; |
} |
} |
/* |
* ...result is to be converted to an 'alternate form'. |
* For o conversion, it increases the precision to force |
* the first digit of the result to be a zero." |
* -- ANSI X3J11 |
* |
* To demonstrate this case, compile and run: |
* printf ("%#.0o",0); |
*/ |
else if (base == OCT && (flags & ALT)) |
*--cp = L'0'; |
size = buf + BUF - cp; |
skipsize: |
break; |
default: /* "%?" prints ?, unless ? is NUL */ |
if (ch == L'\0') |
goto done; |
/* pretend it was %c with argument ch */ |
cp = buf; |
*cp = ch; |
size = 1; |
sign = L'\0'; |
break; |
} |
/* |
* All reasonable formats wind up here. At this point, `cp' |
* points to a string which (if not flags&LADJUST) should be |
* padded out to `width' places. If flags&ZEROPAD, it should |
* first be prefixed by any sign or other prefix; otherwise, |
* it should be blank padded before the prefix is emitted. |
* After any left-hand padding and prefixing, emit zeroes |
* required by a decimal [diouxX] precision, then print the |
* string proper, then emit zeroes required by any leftover |
* floating precision; finally, if LADJUST, pad with blanks. |
* If flags&FPT, ch must be in [aAeEfg]. |
* |
* Compute actual size, so we know how much to pad. |
* size excludes decimal prec; realsz includes it. |
*/ |
realsz = dprec > size ? dprec : size; |
if (sign) |
realsz++; |
if (flags & HEXPREFIX) |
realsz+= 2; |
/* right-adjusting blank padding */ |
if ((flags & (LADJUST|ZEROPAD)) == 0) |
PAD (width - realsz, blanks); |
/* prefix */ |
if (sign) |
PRINT (&sign, 1); |
if (flags & HEXPREFIX) |
PRINT (ox, 2); |
/* right-adjusting zero padding */ |
if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD) |
PAD (width - realsz, zeroes); |
/* leading zeroes from decimal precision */ |
PAD (dprec - size, zeroes); |
/* the string or number proper */ |
#ifdef FLOATING_POINT |
if ((flags & FPT) == 0) { |
PRINT (cp, size); |
} else { /* glue together f_p fragments */ |
if (ch >= L'f') { /* 'f' or 'g' */ |
if (_fpvalue == 0) { |
/* kludge for __dtoa irregularity */ |
PRINT (L"0", 1); |
if (expt < ndig || flags & ALT) { |
PRINT (&decimal_point, 1); |
PAD (ndig - 1, zeroes); |
} |
} else if (expt <= 0) { |
PRINT (L"0", 1); |
if (expt || ndig || flags & ALT) { |
PRINT (&decimal_point, 1); |
PAD (-expt, zeroes); |
PRINT (cp, ndig); |
} |
} else { |
wchar_t *convbuf = cp; |
PRINTANDPAD(cp, convbuf + ndig, |
lead, zeroes); |
cp += lead; |
#ifdef _WANT_IO_C99_FORMATS |
if (flags & GROUPING) { |
while (nseps > 0 || nrepeats > 0) { |
if (nrepeats > 0) |
nrepeats--; |
else { |
grouping--; |
nseps--; |
} |
PRINT (&thousands_sep, 1); |
PRINTANDPAD (cp, convbuf + ndig, |
*grouping, zeroes); |
cp += *grouping; |
} |
if (cp > convbuf + ndig) |
cp = convbuf + ndig; |
} |
#endif |
if (expt < ndig || flags & ALT) |
PRINT (&decimal_point, 1); |
PRINTANDPAD (cp, convbuf + ndig, |
ndig - expt, zeroes); |
} |
} else { /* 'a', 'A', 'e', or 'E' */ |
if (ndig > 1 || flags & ALT) { |
PRINT (cp, 1); |
cp++; |
PRINT (&decimal_point, 1); |
if (_fpvalue) { |
PRINT (cp, ndig - 1); |
} else /* 0.[0..] */ |
/* __dtoa irregularity */ |
PAD (ndig - 1, zeroes); |
} else /* XeYYY */ |
PRINT (cp, 1); |
PRINT (expstr, expsize); |
} |
} |
#else /* !FLOATING_POINT */ |
PRINT (cp, size); |
#endif |
/* left-adjusting padding (always blank) */ |
if (flags & LADJUST) |
PAD (width - realsz, blanks); |
/* finally, adjust ret */ |
ret += width > realsz ? width : realsz; |
FLUSH (); /* copy out the I/O vectors */ |
if (malloc_buf != NULL) { |
_free_r (data, malloc_buf); |
malloc_buf = NULL; |
} |
} |
done: |
FLUSH (); |
error: |
if (malloc_buf != NULL) |
_free_r (data, malloc_buf); |
#ifndef STRING_ONLY |
_newlib_flockfile_end (fp); |
#endif |
return (__sferror (fp) ? EOF : ret); |
/* NOTREACHED */ |
} |
#ifdef FLOATING_POINT |
/* Using reentrant DATA, convert finite VALUE into a string of digits |
with no decimal point, using NDIGITS precision and FLAGS as guides |
to whether trailing zeros must be included. Set *SIGN to nonzero |
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 |
[aAeEfFgG]; different from vfprintf.c:cvt(), the return string |
lives in BUF regardless of CH. LEN is the length of BUF, except |
when CH is [aA], in which case LEN is not in use. If BUF is not |
large enough for the converted string, only the first LEN number |
of characters will be returned in BUF, but *LENGTH will be set to |
the full length of the string before the truncation. */ |
static wchar_t * |
wcvt(struct _reent *data, _PRINTF_FLOAT_TYPE value, int ndigits, int flags, |
wchar_t *sign, int *decpt, int ch, int *length, wchar_t *buf, int len) |
{ |
int mode, dsgn; |
# ifdef _NO_LONGDBL |
union double_union tmp; |
tmp.d = value; |
if (word0 (tmp) & Sign_bit) { /* this will check for < 0 and -0.0 */ |
value = -value; |
*sign = L'-'; |
} else |
*sign = L'\0'; |
# else /* !_NO_LONGDBL */ |
union |
{ |
struct ldieee ieee; |
_LONG_DOUBLE val; |
} ld; |
ld.val = value; |
if (ld.ieee.sign) { /* this will check for < 0 and -0.0 */ |
value = -value; |
*sign = L'-'; |
} else |
*sign = L'\0'; |
# endif /* !_NO_LONGDBL */ |
# ifdef _WANT_IO_C99_FORMATS |
if (ch == L'a' || ch == L'A') { |
wchar_t *digits, *bp, *rve; |
/* This code assumes FLT_RADIX is a power of 2. The initial |
division ensures the digit before the decimal will be less |
than FLT_RADIX (unless it is rounded later). There is no |
loss of precision in these calculations. */ |
value = FREXP (value, decpt) / 8; |
if (!value) |
*decpt = 1; |
digits = ch == L'a' ? L"0123456789abcdef" : L"0123456789ABCDEF"; |
bp = buf; |
do { |
value *= 16; |
mode = (int) value; |
value -= mode; |
*bp++ = digits[mode]; |
} while (ndigits-- && value); |
if (value > 0.5 || (value == 0.5 && mode & 1)) { |
/* round to even */ |
rve = bp; |
while (*--rve == digits[0xf]) { |
*rve = L'0'; |
} |
*rve = *rve == L'9' ? digits[0xa] : *rve + 1; |
} else { |
while (ndigits-- >= 0) { |
*bp++ = L'0'; |
} |
} |
*length = bp - buf; |
return buf; |
} |
# endif /* _WANT_IO_C99_FORMATS */ |
if (ch == L'f' || ch == L'F') { |
mode = 3; /* ndigits after the decimal point */ |
} else { |
/* To obtain ndigits after the decimal point for the 'e' |
* and 'E' formats, round to ndigits + 1 significant |
* figures. |
*/ |
if (ch == L'e' || ch == L'E') { |
ndigits++; |
} |
mode = 2; /* ndigits significant digits */ |
} |
{ |
char *digits, *bp, *rve; |
#ifndef _MB_CAPABLE |
int i; |
#endif |
digits = _DTOA_R (data, value, mode, ndigits, decpt, &dsgn, &rve); |
if ((ch != L'g' && ch != L'G') || flags & ALT) { /* Print trailing zeros */ |
bp = digits + ndigits; |
if (ch == L'f' || ch == L'F') { |
if (*digits == L'0' && value) |
*decpt = -ndigits + 1; |
bp += *decpt; |
} |
if (value == 0) /* kludge for __dtoa irregularity */ |
rve = bp; |
while (rve < bp) |
*rve++ = '0'; |
} |
*length = rve - digits; /* full length of the string */ |
#ifdef _MB_CAPABLE |
_mbsnrtowcs_r (data, buf, (const char **) &digits, *length, |
len, NULL); |
#else |
for (i = 0; i < *length && i < len; ++i) |
buf[i] = (wchar_t) digits[i]; |
#endif |
return buf; |
} |
} |
static int |
wexponent(wchar_t *p0, int exp, int fmtch) |
{ |
register wchar_t *p, *t; |
wchar_t expbuf[MAXEXPLEN]; |
# ifdef _WANT_IO_C99_FORMATS |
int isa = fmtch == L'a' || fmtch == L'A'; |
# else |
# define isa 0 |
# endif |
p = p0; |
*p++ = isa ? L'p' - L'a' + fmtch : fmtch; |
if (exp < 0) { |
exp = -exp; |
*p++ = L'-'; |
} |
else |
*p++ = L'+'; |
t = expbuf + MAXEXPLEN; |
if (exp > 9) { |
do { |
*--t = to_char (exp % 10); |
} while ((exp /= 10) > 9); |
*--t = to_char (exp); |
for (; t < expbuf + MAXEXPLEN; *p++ = *t++); |
} |
else { |
if (!isa) |
*p++ = L'0'; |
*p++ = to_char (exp); |
} |
return (p - p0); |
} |
#endif /* FLOATING_POINT */ |
#ifndef _NO_POS_ARGS |
/* Positional argument support. |
Written by Jeff Johnston |
Copyright (c) 2002 Red Hat Incorporated. |
All rights reserved. |
Redistribution and use in source and binary forms, with or without |
modification, are permitted provided that the following conditions are met: |
Redistributions of source code must retain the above copyright |
notice, this list of conditions and the following disclaimer. |
Redistributions in binary form must reproduce the above copyright |
notice, this list of conditions and the following disclaimer in the |
documentation and/or other materials provided with the distribution. |
The name of Red Hat Incorporated may not be used to endorse |
or promote products derived from this software without specific |
prior written permission. |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY |
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
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 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ |
/* function to get positional parameter N where n = N - 1 */ |
static union arg_val * |
_DEFUN(get_arg, (data, n, fmt, ap, numargs_p, args, arg_type, last_fmt), |
struct _reent *data _AND |
int n _AND |
wchar_t *fmt _AND |
va_list *ap _AND |
int *numargs_p _AND |
union arg_val *args _AND |
int *arg_type _AND |
wchar_t **last_fmt) |
{ |
wchar_t ch; |
int number, flags; |
int spec_type; |
int numargs = *numargs_p; |
__CH_CLASS chtype; |
__STATE state, next_state; |
__ACTION action; |
int pos, last_arg; |
int max_pos_arg = n; |
/* Only need types that can be reached via vararg promotions. */ |
enum types { INT, LONG_INT, QUAD_INT, CHAR_PTR, DOUBLE, LONG_DOUBLE, WIDE_CHAR }; |
/* if this isn't the first call, pick up where we left off last time */ |
if (*last_fmt != NULL) |
fmt = *last_fmt; |
/* we need to process either to end of fmt string or until we have actually |
read the desired parameter from the vararg list. */ |
while (*fmt && n >= numargs) |
{ |
while (*fmt != L'\0' && *fmt != L'%') |
fmt += 1; |
if (*fmt == L'\0') |
break; |
state = START; |
flags = 0; |
pos = -1; |
number = 0; |
spec_type = INT; |
/* Use state/action table to process format specifiers. We ignore invalid |
formats and we are only interested in information that tells us how to |
read the vararg list. */ |
while (state != DONE) |
{ |
ch = *fmt++; |
chtype = ch < (wchar_t) 256 ? __chclass[ch] : OTHER; |
next_state = __state_table[state][chtype]; |
action = __action_table[state][chtype]; |
state = next_state; |
switch (action) |
{ |
case GETMOD: /* we have format modifier */ |
switch (ch) |
{ |
case L'h': |
/* No flag needed, since short and char promote to int. */ |
break; |
case L'L': |
flags |= LONGDBL; |
break; |
case L'q': |
flags |= QUADINT; |
break; |
# ifdef _WANT_IO_C99_FORMATS |
case L'j': |
if (sizeof (intmax_t) == sizeof (long)) |
flags |= LONGINT; |
else |
flags |= QUADINT; |
break; |
case L'z': |
if (sizeof (size_t) <= sizeof (int)) |
/* no flag needed */; |
else if (sizeof (size_t) <= sizeof (long)) |
flags |= LONGINT; |
else |
/* POSIX states that at least one programming |
environment must support size_t no wider than |
long, but that means other environments can |
have size_t as wide as long long. */ |
flags |= QUADINT; |
break; |
case L't': |
if (sizeof (ptrdiff_t) <= sizeof (int)) |
/* no flag needed */; |
else if (sizeof (ptrdiff_t) <= sizeof (long)) |
flags |= LONGINT; |
else |
/* POSIX states that at least one programming |
environment must support ptrdiff_t no wider than |
long, but that means other environments can |
have ptrdiff_t as wide as long long. */ |
flags |= QUADINT; |
break; |
# endif /* _WANT_IO_C99_FORMATS */ |
case L'l': |
default: |
# if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG |
if (*fmt == L'l') |
{ |
flags |= QUADINT; |
++fmt; |
} |
else |
# endif |
flags |= LONGINT; |
break; |
} |
break; |
case GETARG: /* we have format specifier */ |
{ |
numargs &= (MAX_POS_ARGS - 1); |
/* process the specifier and translate it to a type to fetch from varargs */ |
switch (ch) |
{ |
case L'd': |
case L'i': |
case L'o': |
case L'x': |
case L'X': |
case L'u': |
if (flags & LONGINT) |
spec_type = LONG_INT; |
# ifndef _NO_LONGLONG |
else if (flags & QUADINT) |
spec_type = QUAD_INT; |
# endif |
else |
spec_type = INT; |
break; |
# ifdef _WANT_IO_C99_FORMATS |
case L'a': |
case L'A': |
case L'F': |
# endif |
case L'f': |
case L'g': |
case L'G': |
case L'E': |
case L'e': |
# ifndef _NO_LONGDBL |
if (flags & LONGDBL) |
spec_type = LONG_DOUBLE; |
else |
# endif |
spec_type = DOUBLE; |
break; |
case L's': |
# ifdef _WANT_IO_C99_FORMATS |
case L'S': /* POSIX extension */ |
# endif |
case L'p': |
case L'n': |
spec_type = CHAR_PTR; |
break; |
case L'c': |
# ifdef _WANT_IO_C99_FORMATS |
if (flags & LONGINT) |
spec_type = WIDE_CHAR; |
else |
# endif |
spec_type = INT; |
break; |
# ifdef _WANT_IO_C99_FORMATS |
case L'C': /* POSIX extension */ |
spec_type = WIDE_CHAR; |
break; |
# endif |
} |
/* if we have a positional parameter, just store the type, otherwise |
fetch the parameter from the vararg list */ |
if (pos != -1) |
arg_type[pos] = spec_type; |
else |
{ |
switch (spec_type) |
{ |
case LONG_INT: |
args[numargs++].val_long = va_arg (*ap, long); |
break; |
case QUAD_INT: |
args[numargs++].val_quad_t = va_arg (*ap, quad_t); |
break; |
case WIDE_CHAR: |
args[numargs++].val_wint_t = va_arg (*ap, wint_t); |
break; |
case INT: |
args[numargs++].val_int = va_arg (*ap, int); |
break; |
case CHAR_PTR: |
args[numargs++].val_wchar_ptr_t = va_arg (*ap, wchar_t *); |
break; |
case DOUBLE: |
args[numargs++].val_double = va_arg (*ap, double); |
break; |
case LONG_DOUBLE: |
args[numargs++].val__LONG_DOUBLE = va_arg (*ap, _LONG_DOUBLE); |
break; |
} |
} |
} |
break; |
case GETPOS: /* we have positional specifier */ |
if (arg_type[0] == -1) |
memset (arg_type, 0, sizeof (int) * MAX_POS_ARGS); |
pos = number - 1; |
max_pos_arg = (max_pos_arg > pos ? max_pos_arg : pos); |
break; |
case PWPOS: /* we have positional specifier for width or precision */ |
if (arg_type[0] == -1) |
memset (arg_type, 0, sizeof (int) * MAX_POS_ARGS); |
number -= 1; |
arg_type[number] = INT; |
max_pos_arg = (max_pos_arg > number ? max_pos_arg : number); |
break; |
case GETPWB: /* we require format pushback */ |
--fmt; |
/* fallthrough */ |
case GETPW: /* we have a variable precision or width to acquire */ |
args[numargs++].val_int = va_arg (*ap, int); |
break; |
case NUMBER: /* we have a number to process */ |
number = (ch - '0'); |
while ((ch = *fmt) != '\0' && is_digit (ch)) |
{ |
number = number * 10 + (ch - '0'); |
++fmt; |
} |
break; |
case SKIPNUM: /* we have a number to skip */ |
while ((ch = *fmt) != '\0' && is_digit (ch)) |
++fmt; |
break; |
case NOOP: |
default: |
break; /* do nothing */ |
} |
} |
} |
/* 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 */ |
if (*fmt == '\0') |
last_arg = max_pos_arg; |
else |
last_arg = n; |
while (numargs <= last_arg) |
{ |
switch (arg_type[numargs]) |
{ |
case LONG_INT: |
args[numargs++].val_long = va_arg (*ap, long); |
break; |
case QUAD_INT: |
args[numargs++].val_quad_t = va_arg (*ap, quad_t); |
break; |
case CHAR_PTR: |
args[numargs++].val_wchar_ptr_t = va_arg (*ap, wchar_t *); |
break; |
case DOUBLE: |
args[numargs++].val_double = va_arg (*ap, double); |
break; |
case LONG_DOUBLE: |
args[numargs++].val__LONG_DOUBLE = va_arg (*ap, _LONG_DOUBLE); |
break; |
case WIDE_CHAR: |
args[numargs++].val_wint_t = va_arg (*ap, wint_t); |
break; |
case INT: |
default: |
args[numargs++].val_int = va_arg (*ap, int); |
break; |
} |
} |
/* 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 */ |
*numargs_p = numargs; |
*last_fmt = fmt; |
return &args[n]; |
} |
#endif /* !_NO_POS_ARGS */ |
/contrib/sdk/sources/newlib/libc/stdio/vfwscanf.c |
---|
0,0 → 1,1499 |
/*- |
* Copyright (c) 1990 The Regents of the University of California. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms are permitted |
* provided that the above copyright notice and this paragraph are |
* duplicated in all such forms and that any documentation, |
* advertising materials, and other materials related to such |
* distribution and use acknowledge that the software was developed |
* by the University of California, Berkeley. The name of the |
* University may not be used to endorse or promote products derived |
* from this software without specific prior written permission. |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
*/ |
/* |
FUNCTION |
<<vfwscanf>>, <<vwscanf>>, <<vswscanf>>---scan and format argument list from wide character input |
INDEX |
vfwscanf |
INDEX |
_vfwscanf |
INDEX |
vwscanf |
INDEX |
_vwscanf |
INDEX |
vswscanf |
INDEX |
_vswscanf |
ANSI_SYNOPSIS |
#include <stdio.h> |
#include <stdarg.h> |
int vwscanf(const wchar_t *__restrict <[fmt]>, va_list <[list]>); |
int vfwscanf(FILE *__restrict <[fp]>, |
const wchar_t *__restrict <[fmt]>, va_list <[list]>); |
int vswscanf(const wchar_t *__restrict <[str]>, |
const wchar_t *__restrict <[fmt]>, va_list <[list]>); |
int _vwscanf(struct _reent *<[reent]>, const wchar_t *<[fmt]>, |
va_list <[list]>); |
int _vfwscanf(struct _reent *<[reent]>, FILE *<[fp]>, |
const wchar_t *<[fmt]>, va_list <[list]>); |
int _vswscanf(struct _reent *<[reent]>, const wchar_t *<[str]>, |
const wchar_t *<[fmt]>, va_list <[list]>); |
TRAD_SYNOPSIS |
#include <stdio.h> |
#include <varargs.h> |
int vwscanf( <[fmt]>, <[ist]>) |
wchar_t *__restrict <[fmt]>; |
va_list <[list]>; |
int vfwscanf( <[fp]>, <[fmt]>, <[list]>) |
FILE *__restrict <[fp]>; |
wchar_t *__restrict <[fmt]>; |
va_list <[list]>; |
int vswscanf( <[str]>, <[fmt]>, <[list]>) |
wchar_t *__restrict <[str]>; |
wchar_t *__restrict <[fmt]>; |
va_list <[list]>; |
int _vwscanf( <[reent]>, <[fmt]>, <[ist]>) |
struct _reent *<[reent]>; |
wchar_t *<[fmt]>; |
va_list <[list]>; |
int _vfwscanf( <[reent]>, <[fp]>, <[fmt]>, <[list]>) |
struct _reent *<[reent]>; |
FILE *<[fp]>; |
wchar_t *<[fmt]>; |
va_list <[list]>; |
int _vswscanf( <[reent]>, <[str]>, <[fmt]>, <[list]>) |
struct _reent *<[reent]>; |
wchar_t *<[str]>; |
wchar_t *<[fmt]>; |
va_list <[list]>; |
DESCRIPTION |
<<vwscanf>>, <<vfwscanf>>, and <<vswscanf>> are (respectively) variants |
of <<wscanf>>, <<fwscanf>>, and <<swscanf>>. They differ only in |
allowing their caller to pass the variable argument list as a |
<<va_list>> object (initialized by <<va_start>>) rather than |
directly accepting a variable number of arguments. |
RETURNS |
The return values are consistent with the corresponding functions: |
<<vwscanf>> returns the number of input fields successfully scanned, |
converted, and stored; the return value does not include scanned |
fields which were not stored. |
If <<vwscanf>> attempts to read at end-of-file, the return value |
is <<EOF>>. |
If no fields were stored, the return value is <<0>>. |
The routines <<_vwscanf>>, <<_vfwscanf>>, and <<_vswscanf>> are |
reentrant versions which take an additional first parameter which points |
to the reentrancy structure. |
PORTABILITY |
C99, POSIX-1.2008 |
*/ |
#include <_ansi.h> |
#include <reent.h> |
#include <newlib.h> |
#include <ctype.h> |
#include <wctype.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdint.h> |
#include <limits.h> |
#include <wchar.h> |
#include <string.h> |
#include <stdarg.h> |
#include <errno.h> |
#include "local.h" |
#ifdef INTEGER_ONLY |
#define VFWSCANF vfiwscanf |
#define _VFWSCANF_R _vfiwscanf_r |
#define __SVFWSCANF __svfiwscanf |
#ifdef STRING_ONLY |
# define __SVFWSCANF_R __ssvfiwscanf_r |
#else |
# define __SVFWSCANF_R __svfiwscanf_r |
#endif |
#else |
#define VFWSCANF vfwscanf |
#define _VFWSCANF_R _vfwscanf_r |
#define __SVFWSCANF __svfwscanf |
#ifdef STRING_ONLY |
# define __SVFWSCANF_R __ssvfwscanf_r |
#else |
# define __SVFWSCANF_R __svfwscanf_r |
#endif |
#ifndef NO_FLOATING_POINT |
#define FLOATING_POINT |
#endif |
#endif |
#ifdef STRING_ONLY |
#undef _newlib_flockfile_start |
#undef _newlib_flockfile_exit |
#undef _newlib_flockfile_end |
#define _newlib_flockfile_start(x) {} |
#define _newlib_flockfile_exit(x) {} |
#define _newlib_flockfile_end(x) {} |
#define _ungetwc_r _sungetwc_r |
#define __srefill_r __ssrefill_r |
#define _fgetwc_r _sfgetwc_r |
#endif |
#ifdef FLOATING_POINT |
#include <math.h> |
#include <float.h> |
#include <locale.h> |
#ifdef __HAVE_LOCALE_INFO_EXTENDED__ |
#include "../locale/lnumeric.h" |
#endif |
/* 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 |
preferred over _dtoa_r. */ |
#define _NO_LONGDBL |
#if defined _WANT_IO_LONG_DOUBLE && (LDBL_MANT_DIG > DBL_MANT_DIG) |
#undef _NO_LONGDBL |
extern _LONG_DOUBLE _wcstold_r _PARAMS((wchar_t *s, wchar_t **sptr)); |
#endif |
#include "floatio.h" |
#if ((MAXEXP+MAXFRACT+3) > MB_LEN_MAX) |
# define BUF (MAXEXP+MAXFRACT+3) /* 3 = sign + decimal point + NUL */ |
#else |
# define BUF MB_LEN_MAX |
#endif |
/* An upper bound for how long a long prints in decimal. 4 / 13 approximates |
log (2). Add one char for roundoff compensation and one for the sign. */ |
#define MAX_LONG_LEN ((CHAR_BIT * sizeof (long) - 1) * 4 / 13 + 2) |
#else |
#define BUF 40 |
#endif |
#define _NO_LONGLONG |
#if defined _WANT_IO_LONG_LONG \ |
&& (defined __GNUC__ || __STDC_VERSION__ >= 199901L) |
# undef _NO_LONGLONG |
#endif |
#define _NO_POS_ARGS |
#ifdef _WANT_IO_POS_ARGS |
# undef _NO_POS_ARGS |
# ifdef NL_ARGMAX |
# define MAX_POS_ARGS NL_ARGMAX |
# else |
# define MAX_POS_ARGS 32 |
# endif |
static void * get_arg (int, va_list *, int *, void **); |
#endif /* _WANT_IO_POS_ARGS */ |
/* |
* Flags used during conversion. |
*/ |
#define LONG 0x01 /* l: long or double */ |
#define LONGDBL 0x02 /* L/ll: long double or long long */ |
#define SHORT 0x04 /* h: short */ |
#define CHAR 0x08 /* hh: 8 bit integer */ |
#define SUPPRESS 0x10 /* suppress assignment */ |
#define POINTER 0x20 /* weird %p pointer (`fake hex') */ |
#define NOSKIP 0x40 /* do not skip blanks */ |
/* |
* The following are used in numeric conversions only: |
* SIGNOK, NDIGITS, DPTOK, and EXPOK are for floating point; |
* SIGNOK, NDIGITS, PFXOK, and NZDIGITS are for integral. |
*/ |
#define SIGNOK 0x80 /* +/- is (still) legal */ |
#define NDIGITS 0x100 /* no digits detected */ |
#define DPTOK 0x200 /* (float) decimal point is still legal */ |
#define EXPOK 0x400 /* (float) exponent (e+3, etc) still legal */ |
#define PFXOK 0x200 /* 0x prefix is (still) legal */ |
#define NZDIGITS 0x400 /* no zero digits detected */ |
#define HAVESIGN 0x10000 /* sign detected */ |
/* |
* Conversion types. |
*/ |
#define CT_CHAR 0 /* %c conversion */ |
#define CT_CCL 1 /* %[...] conversion */ |
#define CT_STRING 2 /* %s conversion */ |
#define CT_INT 3 /* integer, i.e., wcstol or wcstoul */ |
#define CT_FLOAT 4 /* floating, i.e., wcstod */ |
#define INCCL(_c) \ |
(cclcompl ? (wmemchr(ccls, (_c), ccle - ccls) == NULL) : \ |
(wmemchr(ccls, (_c), ccle - ccls) != NULL)) |
/* |
* vfwscanf |
*/ |
#ifndef STRING_ONLY |
#ifndef _REENT_ONLY |
int |
_DEFUN(VFWSCANF, (fp, fmt, ap), |
register FILE *__restrict fp _AND |
_CONST wchar_t *__restrict fmt _AND |
va_list ap) |
{ |
struct _reent *reent = _REENT; |
CHECK_INIT(reent, fp); |
return __SVFWSCANF_R (reent, fp, fmt, ap); |
} |
int |
_DEFUN(__SVFWSCANF, (fp, fmt0, ap), |
register FILE *fp _AND |
wchar_t _CONST *fmt0 _AND |
va_list ap) |
{ |
return __SVFWSCANF_R (_REENT, fp, fmt0, ap); |
} |
#endif /* !_REENT_ONLY */ |
int |
_DEFUN(_VFWSCANF_R, (data, fp, fmt, ap), |
struct _reent *data _AND |
register FILE *fp _AND |
_CONST wchar_t *fmt _AND |
va_list ap) |
{ |
CHECK_INIT(data, fp); |
return __SVFWSCANF_R (data, fp, fmt, ap); |
} |
#endif /* !STRING_ONLY */ |
#ifdef STRING_ONLY |
/* When dealing with the swscanf family, we don't want to use the |
* regular ungetwc which will drag in file I/O items we don't need. |
* So, we create our own trimmed-down version. */ |
static wint_t |
_DEFUN(_sungetwc_r, (data, fp, ch), |
struct _reent *data _AND |
wint_t wc _AND |
register FILE *fp) |
{ |
if (wc == WEOF) |
return (WEOF); |
/* After ungetc, we won't be at eof anymore */ |
fp->_flags &= ~__SEOF; |
/* |
* If we are in the middle of ungetwc'ing, just continue. |
* This may require expanding the current ungetc buffer. |
*/ |
if (HASUB (fp)) |
{ |
if (fp->_r >= fp->_ub._size && __submore (data, fp)) |
{ |
return EOF; |
} |
fp->_p -= sizeof (wchar_t); |
*fp->_p = (wchar_t) wc; |
fp->_r += sizeof (wchar_t); |
return wc; |
} |
/* |
* If we can handle this by simply backing up, do so, |
* but never replace the original character. |
* (This makes swscanf() work when scanning `const' data.) |
*/ |
if (fp->_bf._base != NULL && fp->_p > fp->_bf._base |
&& ((wchar_t *)fp->_p)[-1] == wc) |
{ |
fp->_p -= sizeof (wchar_t); |
fp->_r += sizeof (wchar_t); |
return wc; |
} |
/* |
* Create an ungetc buffer. |
* Initially, we will use the `reserve' buffer. |
*/ |
fp->_ur = fp->_r; |
fp->_up = fp->_p; |
fp->_ub._base = fp->_ubuf; |
fp->_ub._size = sizeof (fp->_ubuf); |
fp->_p = &fp->_ubuf[sizeof (fp->_ubuf) - sizeof (wchar_t)]; |
*(wchar_t *) fp->_p = wc; |
fp->_r = 2; |
return wc; |
} |
extern int __ssrefill_r _PARAMS ((struct _reent *ptr, register FILE * fp)); |
static size_t |
_DEFUN(_sfgetwc_r, (ptr, fp), |
struct _reent * ptr _AND |
FILE * fp) |
{ |
wchar_t wc; |
if (fp->_r <= 0 && __ssrefill_r (ptr, fp)) |
return (WEOF); |
wc = *(wchar_t *) fp->_p; |
fp->_p += sizeof (wchar_t); |
fp->_r -= sizeof (wchar_t); |
return (wc); |
} |
#endif /* STRING_ONLY */ |
int |
_DEFUN(__SVFWSCANF_R, (rptr, fp, fmt0, ap), |
struct _reent *rptr _AND |
register FILE *fp _AND |
wchar_t _CONST *fmt0 _AND |
va_list ap) |
{ |
register wchar_t *fmt = (wchar_t *) fmt0; |
register wint_t c; /* character from format, or conversion */ |
register size_t width; /* field width, or 0 */ |
register wchar_t *p = NULL; /* points into all kinds of strings */ |
register int n; /* handy integer */ |
register int flags; /* flags as defined above */ |
register wchar_t *p0; /* saves original value of p when necessary */ |
int nassigned; /* number of fields assigned */ |
int nread; /* number of characters consumed from fp */ |
#ifndef _NO_POS_ARGS |
int N; /* arg number */ |
int arg_index = 0; /* index into args processed directly */ |
int numargs = 0; /* number of varargs read */ |
void *args[MAX_POS_ARGS]; /* positional args read */ |
int is_pos_arg; /* is current format positional? */ |
#endif |
int base = 0; /* base argument to wcstol/wcstoul */ |
mbstate_t mbs; /* value to keep track of multibyte state */ |
#define CCFN_PARAMS _PARAMS((struct _reent *, const wchar_t *, wchar_t **, int)) |
unsigned long (*ccfn)CCFN_PARAMS=0; /* conversion function (wcstol/wcstoul) */ |
wchar_t buf[BUF]; /* buffer for numeric conversions */ |
const wchar_t *ccls; /* character class start */ |
const wchar_t *ccle; /* character class end */ |
int cclcompl = 0; /* ccl is complemented? */ |
wint_t wi; /* handy wint_t */ |
char *mbp = NULL; /* multibyte string pointer for %c %s %[ */ |
size_t nconv; /* number of bytes in mb. conversion */ |
char mbbuf[MB_LEN_MAX]; /* temporary mb. character buffer */ |
char *cp; |
short *sp; |
int *ip; |
#ifdef FLOATING_POINT |
float *flp; |
_LONG_DOUBLE *ldp; |
double *dp; |
wchar_t decpt; |
#endif |
long *lp; |
#ifndef _NO_LONGLONG |
long long *llp; |
#endif |
/* `basefix' is used to avoid `if' tests in the integer scanner */ |
static _CONST short basefix[17] = |
{10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; |
/* Macro to support positional arguments */ |
#ifndef _NO_POS_ARGS |
# define GET_ARG(n, ap, type) \ |
((type) (is_pos_arg \ |
? (n < numargs \ |
? args[n] \ |
: get_arg (n, &ap, &numargs, args)) \ |
: (arg_index++ < numargs \ |
? args[n] \ |
: (numargs < MAX_POS_ARGS \ |
? args[numargs++] = va_arg (ap, void *) \ |
: va_arg (ap, void *))))) |
#else |
# define GET_ARG(n, ap, type) (va_arg (ap, type)) |
#endif |
#ifdef FLOATING_POINT |
#ifdef _MB_CAPABLE |
#ifdef __HAVE_LOCALE_INFO_EXTENDED__ |
decpt = *__get_current_numeric_locale ()->wdecimal_point; |
#else |
{ |
size_t nconv; |
memset (&mbs, '\0', sizeof (mbs)); |
nconv = _mbrtowc_r (rptr, &decpt, |
_localeconv_r (rptr)->decimal_point, |
MB_CUR_MAX, &mbs); |
if (nconv == (size_t) -1 || nconv == (size_t) -2) |
decpt = L'.'; |
} |
#endif /* !__HAVE_LOCALE_INFO_EXTENDED__ */ |
#else |
decpt = (wchar_t) *_localeconv_r (rptr)->decimal_point; |
#endif /* !_MB_CAPABLE */ |
#endif /* FLOATING_POINT */ |
_newlib_flockfile_start (fp); |
ORIENT (fp, 1); |
nassigned = 0; |
nread = 0; |
ccls = ccle = NULL; |
for (;;) |
{ |
c = *fmt++; |
if (c == L'\0') |
goto all_done; |
if (iswspace (c)) |
{ |
while ((c = _fgetwc_r (rptr, fp)) != WEOF && iswspace(c)) |
; |
if (c != WEOF) |
_ungetwc_r (rptr, c, fp); |
continue; |
} |
if (c != L'%') |
goto literal; |
width = 0; |
flags = 0; |
#ifndef _NO_POS_ARGS |
N = arg_index; |
is_pos_arg = 0; |
#endif |
/* |
* switch on the format. continue if done; break once format |
* type is derived. |
*/ |
again: |
c = *fmt++; |
switch (c) |
{ |
case L'%': |
literal: |
if ((wi = _fgetwc_r (rptr, fp)) == WEOF) |
goto input_failure; |
if (wi != c) |
{ |
_ungetwc_r (rptr, wi, fp); |
goto input_failure; |
} |
nread++; |
continue; |
case L'*': |
flags |= SUPPRESS; |
goto again; |
case L'l': |
#if defined _WANT_IO_C99_FORMATS || !defined _NO_LONGLONG |
if (*fmt == L'l') /* Check for 'll' = long long (SUSv3) */ |
{ |
++fmt; |
flags |= LONGDBL; |
} |
else |
#endif |
flags |= LONG; |
goto again; |
case L'L': |
flags |= LONGDBL; |
goto again; |
case L'h': |
#ifdef _WANT_IO_C99_FORMATS |
if (*fmt == 'h') /* Check for 'hh' = char int (SUSv3) */ |
{ |
++fmt; |
flags |= CHAR; |
} |
else |
#endif |
flags |= SHORT; |
goto again; |
#ifdef _WANT_IO_C99_FORMATS |
case L'j': /* intmax_t */ |
if (sizeof (intmax_t) == sizeof (long)) |
flags |= LONG; |
else |
flags |= LONGDBL; |
goto again; |
case L't': /* ptrdiff_t */ |
if (sizeof (ptrdiff_t) < sizeof (int)) |
/* POSIX states ptrdiff_t is 16 or more bits, as |
is short. */ |
flags |= SHORT; |
else if (sizeof (ptrdiff_t) == sizeof (int)) |
/* no flag needed */; |
else if (sizeof (ptrdiff_t) <= sizeof (long)) |
flags |= LONG; |
else |
/* POSIX states that at least one programming |
environment must support ptrdiff_t no wider than |
long, but that means other environments can |
have ptrdiff_t as wide as long long. */ |
flags |= LONGDBL; |
goto again; |
case L'z': /* size_t */ |
if (sizeof (size_t) < sizeof (int)) |
/* POSIX states size_t is 16 or more bits, as is short. */ |
flags |= SHORT; |
else if (sizeof (size_t) == sizeof (int)) |
/* no flag needed */; |
else if (sizeof (size_t) <= sizeof (long)) |
flags |= LONG; |
else |
/* POSIX states that at least one programming |
environment must support size_t no wider than |
long, but that means other environments can |
have size_t as wide as long long. */ |
flags |= LONGDBL; |
goto again; |
#endif /* _WANT_IO_C99_FORMATS */ |
case L'0': |
case L'1': |
case L'2': |
case L'3': |
case L'4': |
case L'5': |
case L'6': |
case L'7': |
case L'8': |
case L'9': |
width = width * 10 + c - L'0'; |
goto again; |
#ifndef _NO_POS_ARGS |
case L'$': |
if (width <= MAX_POS_ARGS) |
{ |
N = width - 1; |
is_pos_arg = 1; |
width = 0; |
goto again; |
} |
rptr->_errno = EINVAL; |
goto input_failure; |
#endif /* !_NO_POS_ARGS */ |
case L'd': |
c = CT_INT; |
ccfn = (unsigned long (*)CCFN_PARAMS)_wcstol_r; |
base = 10; |
break; |
case L'i': |
c = CT_INT; |
ccfn = (unsigned long (*)CCFN_PARAMS)_wcstol_r; |
base = 0; |
break; |
case L'o': |
c = CT_INT; |
ccfn = _wcstoul_r; |
base = 8; |
break; |
case L'u': |
c = CT_INT; |
ccfn = _wcstoul_r; |
base = 10; |
break; |
case L'X': |
case L'x': |
flags |= PFXOK; /* enable 0x prefixing */ |
c = CT_INT; |
ccfn = _wcstoul_r; |
base = 16; |
break; |
#ifdef FLOATING_POINT |
# ifdef _WANT_IO_C99_FORMATS |
case L'A': |
case L'a': |
case L'F': |
# endif |
case L'E': |
case L'G': |
case L'e': |
case L'f': |
case L'g': |
c = CT_FLOAT; |
break; |
#endif |
#ifdef _WANT_IO_C99_FORMATS |
case L'S': |
flags |= LONG; |
/* FALLTHROUGH */ |
#endif |
case L's': |
c = CT_STRING; |
break; |
case L'[': |
ccls = fmt; |
if (*fmt == '^') |
{ |
cclcompl = 1; |
++fmt; |
} |
else |
cclcompl = 0; |
if (*fmt == ']') |
fmt++; |
while (*fmt != '\0' && *fmt != ']') |
fmt++; |
ccle = fmt; |
fmt++; |
flags |= NOSKIP; |
c = CT_CCL; |
break; |
#ifdef _WANT_IO_C99_FORMATS |
case 'C': |
flags |= LONG; |
/* FALLTHROUGH */ |
#endif |
case 'c': |
flags |= NOSKIP; |
c = CT_CHAR; |
break; |
case 'p': /* pointer format is like hex */ |
flags |= POINTER | PFXOK; |
c = CT_INT; |
ccfn = _wcstoul_r; |
base = 16; |
break; |
case 'n': |
if (flags & SUPPRESS) /* ??? */ |
continue; |
#ifdef _WANT_IO_C99_FORMATS |
if (flags & CHAR) |
{ |
cp = GET_ARG (N, ap, char *); |
*cp = nread; |
} |
else |
#endif |
if (flags & SHORT) |
{ |
sp = GET_ARG (N, ap, short *); |
*sp = nread; |
} |
else if (flags & LONG) |
{ |
lp = GET_ARG (N, ap, long *); |
*lp = nread; |
} |
#ifndef _NO_LONGLONG |
else if (flags & LONGDBL) |
{ |
llp = GET_ARG (N, ap, long long*); |
*llp = nread; |
} |
#endif |
else |
{ |
ip = GET_ARG (N, ap, int *); |
*ip = nread; |
} |
continue; |
/* |
* Disgusting backwards compatibility hacks. XXX |
*/ |
case L'\0': /* compat */ |
_newlib_flockfile_exit (fp); |
return EOF; |
default: /* compat */ |
goto match_failure; |
} |
/* |
* Consume leading white space, except for formats that |
* suppress this. |
*/ |
if ((flags & NOSKIP) == 0) |
{ |
while ((wi = _fgetwc_r (rptr, fp)) != WEOF && iswspace (wi)) |
nread++; |
if (wi == WEOF) |
goto input_failure; |
_ungetwc_r (rptr, wi, fp); |
} |
/* |
* Do the conversion. |
*/ |
switch (c) |
{ |
case CT_CHAR: |
/* scan arbitrary characters (sets NOSKIP) */ |
if (width == 0) |
width = 1; |
if (flags & LONG) |
{ |
if (!(flags & SUPPRESS)) |
p = GET_ARG(N, ap, wchar_t *); |
n = 0; |
while (width-- != 0 && (wi = _fgetwc_r (rptr, fp)) != WEOF) |
{ |
if (!(flags & SUPPRESS)) |
*p++ = (wchar_t) wi; |
n++; |
} |
if (n == 0) |
goto input_failure; |
nread += n; |
if (!(flags & SUPPRESS)) |
nassigned++; |
} |
else |
{ |
if (!(flags & SUPPRESS)) |
mbp = GET_ARG(N, ap, char *); |
n = 0; |
memset ((_PTR)&mbs, '\0', sizeof (mbstate_t)); |
while (width != 0 && (wi = _fgetwc_r (rptr, fp)) != WEOF) |
{ |
if (width >= MB_CUR_MAX && !(flags & SUPPRESS)) |
{ |
nconv = _wcrtomb_r (rptr, mbp, wi, &mbs); |
if (nconv == (size_t) -1) |
goto input_failure; |
} |
else |
{ |
nconv = _wcrtomb_r (rptr, mbbuf, wi, &mbs); |
if (nconv == (size_t) -1) |
goto input_failure; |
if (nconv > width) |
{ |
_ungetwc_r (rptr, wi, fp); |
break; |
} |
if (!(flags & SUPPRESS)) |
memcpy(mbp, mbbuf, nconv); |
} |
if (!(flags & SUPPRESS)) |
mbp += nconv; |
width -= nconv; |
n++; |
} |
if (n == 0) |
goto input_failure; |
nread += n; |
if (!(flags & SUPPRESS)) |
nassigned++; |
} |
break; |
case CT_CCL: |
/* scan a (nonempty) character class (sets NOSKIP) */ |
if (width == 0) |
width = (size_t) ~0; /* `infinity' */ |
/* take only those things in the class */ |
if ((flags & SUPPRESS) && (flags & LONG)) |
{ |
n = 0; |
while ((wi = _fgetwc_r (rptr, fp)) != WEOF |
&& width-- != 0 && INCCL (wi)) |
n++; |
if (wi != WEOF) |
_ungetwc_r (rptr, wi, fp); |
if (n == 0) |
goto match_failure; |
} |
else if (flags & LONG) |
{ |
p0 = p = GET_ARG(N, ap, wchar_t *); |
while ((wi = _fgetwc_r (rptr, fp)) != WEOF |
&& width-- != 0 && INCCL (wi)) |
*p++ = (wchar_t) wi; |
if (wi != WEOF) |
_ungetwc_r (rptr, wi, fp); |
n = p - p0; |
if (n == 0) |
goto match_failure; |
*p = L'\0'; |
nassigned++; |
} |
else |
{ |
if (!(flags & SUPPRESS)) |
mbp = GET_ARG(N, ap, char *); |
n = 0; |
memset ((_PTR) &mbs, '\0', sizeof (mbstate_t)); |
while ((wi = _fgetwc_r (rptr, fp)) != WEOF |
&& width-- != 0 && INCCL (wi)) |
{ |
if (width >= MB_CUR_MAX && !(flags & SUPPRESS)) |
{ |
nconv = _wcrtomb_r (rptr, mbp, wi, &mbs); |
if (nconv == (size_t) -1) |
goto input_failure; |
} |
else |
{ |
nconv = wcrtomb(mbbuf, wi, &mbs); |
if (nconv == (size_t) -1) |
goto input_failure; |
if (nconv > width) |
break; |
if (!(flags & SUPPRESS)) |
memcpy(mbp, mbbuf, nconv); |
} |
if (!(flags & SUPPRESS)) |
mbp += nconv; |
width -= nconv; |
n++; |
} |
if (wi != WEOF) |
_ungetwc_r (rptr, wi, fp); |
if (!(flags & SUPPRESS)) |
{ |
*mbp = 0; |
nassigned++; |
} |
} |
nread += n; |
break; |
case CT_STRING: |
/* like CCL, but zero-length string OK, & no NOSKIP */ |
if (width == 0) |
width = (size_t)~0; |
if ((flags & SUPPRESS) && (flags & LONG)) |
{ |
while ((wi = _fgetwc_r (rptr, fp)) != WEOF |
&& width-- != 0 && !iswspace (wi)) |
nread++; |
if (wi != WEOF) |
_ungetwc_r (rptr, wi, fp); |
} |
else if (flags & LONG) |
{ |
p0 = p = GET_ARG(N, ap, wchar_t *); |
while ((wi = _fgetwc_r (rptr, fp)) != WEOF |
&& width-- != 0 && !iswspace (wi)) |
{ |
*p++ = (wchar_t) wi; |
nread++; |
} |
if (wi != WEOF) |
_ungetwc_r (rptr, wi, fp); |
*p = L'\0'; |
nassigned++; |
} |
else |
{ |
if (!(flags & SUPPRESS)) |
mbp = GET_ARG(N, ap, char *); |
memset ((_PTR) &mbs, '\0', sizeof (mbstate_t)); |
while ((wi = _fgetwc_r (rptr, fp)) != WEOF |
&& width != 0 && !iswspace (wi)) |
{ |
if (width >= MB_CUR_MAX && !(flags & SUPPRESS)) |
{ |
nconv = wcrtomb(mbp, wi, &mbs); |
if (nconv == (size_t)-1) |
goto input_failure; |
} |
else |
{ |
nconv = wcrtomb(mbbuf, wi, &mbs); |
if (nconv == (size_t)-1) |
goto input_failure; |
if (nconv > width) |
break; |
if (!(flags & SUPPRESS)) |
memcpy(mbp, mbbuf, nconv); |
} |
if (!(flags & SUPPRESS)) |
mbp += nconv; |
width -= nconv; |
nread++; |
} |
if (wi != WEOF) |
_ungetwc_r (rptr, wi, fp); |
if (!(flags & SUPPRESS)) |
{ |
*mbp = 0; |
nassigned++; |
} |
} |
continue; |
case CT_INT: |
{ |
/* scan an integer as if by wcstol/wcstoul */ |
if (width == 0 || width > sizeof (buf) / sizeof (*buf) - 1) |
width = sizeof(buf) / sizeof (*buf) - 1; |
flags |= SIGNOK | NDIGITS | NZDIGITS; |
for (p = buf; width; width--) |
{ |
c = _fgetwc_r (rptr, fp); |
/* |
* Switch on the character; `goto ok' if we |
* accept it as a part of number. |
*/ |
switch (c) |
{ |
/* |
* The digit 0 is always legal, but is special. |
* For %i conversions, if no digits (zero or nonzero) |
* have been scanned (only signs), we will have base==0. |
* In that case, we should set it to 8 and enable 0x |
* prefixing. Also, if we have not scanned zero digits |
* before this, do not turn off prefixing (someone else |
* will turn it off if we have scanned any nonzero digits). |
*/ |
case L'0': |
if (base == 0) |
{ |
base = 8; |
flags |= PFXOK; |
} |
if (flags & NZDIGITS) |
flags &= ~(SIGNOK | NZDIGITS | NDIGITS); |
else |
flags &= ~(SIGNOK | PFXOK | NDIGITS); |
goto ok; |
/* 1 through 7 always legal */ |
case L'1': |
case L'2': |
case L'3': |
case L'4': |
case L'5': |
case L'6': |
case L'7': |
base = basefix[base]; |
flags &= ~(SIGNOK | PFXOK | NDIGITS); |
goto ok; |
/* digits 8 and 9 ok iff decimal or hex */ |
case L'8': |
case L'9': |
base = basefix[base]; |
if (base <= 8) |
break; /* not legal here */ |
flags &= ~(SIGNOK | PFXOK | NDIGITS); |
goto ok; |
/* letters ok iff hex */ |
case L'A': |
case L'B': |
case L'C': |
case L'D': |
case L'E': |
case L'F': |
case L'a': |
case L'b': |
case L'c': |
case L'd': |
case L'e': |
case L'f': |
/* no need to fix base here */ |
if (base <= 10) |
break; /* not legal here */ |
flags &= ~(SIGNOK | PFXOK | NDIGITS); |
goto ok; |
/* sign ok only as first character */ |
case L'+': |
case L'-': |
if (flags & SIGNOK) |
{ |
flags &= ~SIGNOK; |
flags |= HAVESIGN; |
goto ok; |
} |
break; |
/* x ok iff flag still set & single 0 seen */ |
case L'x': |
case L'X': |
if ((flags & PFXOK) && p == buf + 1 + !!(flags & HAVESIGN)) |
{ |
base = 16;/* if %i */ |
flags &= ~PFXOK; |
goto ok; |
} |
break; |
} |
/* |
* If we got here, c is not a legal character |
* for a number. Stop accumulating digits. |
*/ |
if (c != WEOF) |
_ungetwc_r (rptr, c, fp); |
break; |
ok: |
/* |
* c is legal: store it and look at the next. |
*/ |
*p++ = (wchar_t) c; |
} |
/* |
* If we had only a sign, it is no good; push back the sign. |
* If the number ends in `x', it was [sign] '0' 'x', so push back |
* the x and treat it as [sign] '0'. |
* Use of ungetc here and below assumes ASCII encoding; we are only |
* pushing back 7-bit characters, so casting to unsigned char is |
* not necessary. |
*/ |
if (flags & NDIGITS) |
{ |
if (p > buf) |
_ungetwc_r (rptr, *--p, fp); /* [-+xX] */ |
goto match_failure; |
} |
c = p[-1]; |
if (c == L'x' || c == L'X') |
{ |
--p; |
_ungetwc_r (rptr, c, fp); |
} |
if ((flags & SUPPRESS) == 0) |
{ |
unsigned long res; |
*p = 0; |
res = (*ccfn) (rptr, buf, (wchar_t **) NULL, base); |
if (flags & POINTER) |
{ |
void **vp = GET_ARG (N, ap, void **); |
#ifndef _NO_LONGLONG |
if (sizeof (uintptr_t) > sizeof (unsigned long)) |
{ |
unsigned long long resll; |
resll = _wcstoull_r (rptr, buf, (wchar_t **) NULL, base); |
*vp = (void *) (uintptr_t) resll; |
} |
else |
#endif /* !_NO_LONGLONG */ |
*vp = (void *) (uintptr_t) res; |
} |
#ifdef _WANT_IO_C99_FORMATS |
else if (flags & CHAR) |
{ |
cp = GET_ARG (N, ap, char *); |
*cp = res; |
} |
#endif |
else if (flags & SHORT) |
{ |
sp = GET_ARG (N, ap, short *); |
*sp = res; |
} |
else if (flags & LONG) |
{ |
lp = GET_ARG (N, ap, long *); |
*lp = res; |
} |
#ifndef _NO_LONGLONG |
else if (flags & LONGDBL) |
{ |
unsigned long long resll; |
if (ccfn == _wcstoul_r) |
resll = _wcstoull_r (rptr, buf, (wchar_t **) NULL, base); |
else |
resll = _wcstoll_r (rptr, buf, (wchar_t **) NULL, base); |
llp = GET_ARG (N, ap, long long*); |
*llp = resll; |
} |
#endif |
else |
{ |
ip = GET_ARG (N, ap, int *); |
*ip = res; |
} |
nassigned++; |
} |
nread += p - buf; |
break; |
} |
#ifdef FLOATING_POINT |
case CT_FLOAT: |
{ |
/* scan a floating point number as if by wcstod */ |
/* This code used to assume that the number of digits is reasonable. |
However, ANSI / ISO C makes no such stipulation; we have to get |
exact results even when there is an unreasonable amount of |
leading zeroes. */ |
long leading_zeroes = 0; |
long zeroes, exp_adjust; |
wchar_t *exp_start = NULL; |
unsigned width_left = 0; |
char nancount = 0; |
char infcount = 0; |
#ifdef hardway |
if (width == 0 || width > sizeof (buf) - 1) |
#else |
/* size_t is unsigned, hence this optimisation */ |
if (width - 1 > sizeof (buf) - 2) |
#endif |
{ |
width_left = width - (sizeof (buf) - 1); |
width = sizeof (buf) - 1; |
} |
flags |= SIGNOK | NDIGITS | DPTOK | EXPOK; |
zeroes = 0; |
exp_adjust = 0; |
for (p = buf; width; ) |
{ |
c = _fgetwc_r (rptr, fp); |
/* |
* This code mimicks the integer conversion |
* code, but is much simpler. |
*/ |
switch (c) |
{ |
case L'0': |
if (flags & NDIGITS) |
{ |
flags &= ~SIGNOK; |
zeroes++; |
if (width_left) |
{ |
width_left--; |
width++; |
} |
goto fskip; |
} |
/* Fall through. */ |
case L'1': |
case L'2': |
case L'3': |
case L'4': |
case L'5': |
case L'6': |
case L'7': |
case L'8': |
case L'9': |
if (nancount + infcount == 0) |
{ |
flags &= ~(SIGNOK | NDIGITS); |
goto fok; |
} |
break; |
case L'+': |
case L'-': |
if (flags & SIGNOK) |
{ |
flags &= ~SIGNOK; |
goto fok; |
} |
break; |
case L'n': |
case L'N': |
if (nancount == 0 && zeroes == 0 |
&& (flags & (NDIGITS | DPTOK | EXPOK)) == |
(NDIGITS | DPTOK | EXPOK)) |
{ |
flags &= ~(SIGNOK | DPTOK | EXPOK | NDIGITS); |
nancount = 1; |
goto fok; |
} |
if (nancount == 2) |
{ |
nancount = 3; |
goto fok; |
} |
if (infcount == 1 || infcount == 4) |
{ |
infcount++; |
goto fok; |
} |
break; |
case L'a': |
case L'A': |
if (nancount == 1) |
{ |
nancount = 2; |
goto fok; |
} |
break; |
case L'i': |
if (infcount == 0 && zeroes == 0 |
&& (flags & (NDIGITS | DPTOK | EXPOK)) == |
(NDIGITS | DPTOK | EXPOK)) |
{ |
flags &= ~(SIGNOK | DPTOK | EXPOK | NDIGITS); |
infcount = 1; |
goto fok; |
} |
if (infcount == 3 || infcount == 5) |
{ |
infcount++; |
goto fok; |
} |
break; |
case L'f': |
case L'F': |
if (infcount == 2) |
{ |
infcount = 3; |
goto fok; |
} |
break; |
case L't': |
case L'T': |
if (infcount == 6) |
{ |
infcount = 7; |
goto fok; |
} |
break; |
case L'y': |
case L'Y': |
if (infcount == 7) |
{ |
infcount = 8; |
goto fok; |
} |
break; |
case L'e': |
case L'E': |
/* no exponent without some digits */ |
if ((flags & (NDIGITS | EXPOK)) == EXPOK |
|| ((flags & EXPOK) && zeroes)) |
{ |
if (! (flags & DPTOK)) |
{ |
exp_adjust = zeroes - leading_zeroes; |
exp_start = p; |
} |
flags = |
(flags & ~(EXPOK | DPTOK)) | |
SIGNOK | NDIGITS; |
zeroes = 0; |
goto fok; |
} |
break; |
default: |
if ((wchar_t) c == decpt && (flags & DPTOK)) |
{ |
flags &= ~(SIGNOK | DPTOK); |
leading_zeroes = zeroes; |
goto fok; |
} |
break; |
} |
if (c != WEOF) |
_ungetwc_r (rptr, c, fp); |
break; |
fok: |
*p++ = c; |
fskip: |
width--; |
++nread; |
} |
if (zeroes) |
flags &= ~NDIGITS; |
/* We may have a 'N' or possibly even [sign] 'N' 'a' as the |
start of 'NaN', only to run out of chars before it was |
complete (or having encountered a non-matching char). So |
check here if we have an outstanding nancount, and if so |
put back the chars we did swallow and treat as a failed |
match. |
FIXME - we still don't handle NAN([0xdigits]). */ |
if (nancount - 1U < 2U) /* nancount && nancount < 3 */ |
{ |
/* Newlib's ungetc works even if we called __srefill in |
the middle of a partial parse, but POSIX does not |
guarantee that in all implementations of ungetc. */ |
while (p > buf) |
{ |
_ungetwc_r (rptr, *--p, fp); /* [-+nNaA] */ |
--nread; |
} |
goto match_failure; |
} |
/* Likewise for 'inf' and 'infinity'. But be careful that |
'infinite' consumes only 3 characters, leaving the stream |
at the second 'i'. */ |
if (infcount - 1U < 7U) /* infcount && infcount < 8 */ |
{ |
if (infcount >= 3) /* valid 'inf', but short of 'infinity' */ |
while (infcount-- > 3) |
{ |
_ungetwc_r (rptr, *--p, fp); /* [iInNtT] */ |
--nread; |
} |
else |
{ |
while (p > buf) |
{ |
_ungetwc_r (rptr, *--p, fp); /* [-+iInN] */ |
--nread; |
} |
goto match_failure; |
} |
} |
/* |
* If no digits, might be missing exponent digits |
* (just give back the exponent) or might be missing |
* regular digits, but had sign and/or decimal point. |
*/ |
if (flags & NDIGITS) |
{ |
if (flags & EXPOK) |
{ |
/* no digits at all */ |
while (p > buf) |
{ |
_ungetwc_r (rptr, *--p, fp); /* [-+.] */ |
--nread; |
} |
goto match_failure; |
} |
/* just a bad exponent (e and maybe sign) */ |
c = *--p; |
--nread; |
if (c != L'e' && c != L'E') |
{ |
_ungetwc_r (rptr, c, fp); /* [-+] */ |
c = *--p; |
--nread; |
} |
_ungetwc_r (rptr, c, fp); /* [eE] */ |
} |
if ((flags & SUPPRESS) == 0) |
{ |
double res = 0; |
#ifdef _NO_LONGDBL |
#define QUAD_RES res; |
#else /* !_NO_LONG_DBL */ |
long double qres = 0; |
#define QUAD_RES qres; |
#endif /* !_NO_LONG_DBL */ |
long new_exp = 0; |
*p = 0; |
if ((flags & (DPTOK | EXPOK)) == EXPOK) |
{ |
exp_adjust = zeroes - leading_zeroes; |
new_exp = -exp_adjust; |
exp_start = p; |
} |
else if (exp_adjust) |
new_exp = _wcstol_r (rptr, (exp_start + 1), NULL, 10) - exp_adjust; |
if (exp_adjust) |
{ |
/* If there might not be enough space for the new exponent, |
truncate some trailing digits to make room. */ |
if (exp_start >= buf + sizeof (buf) - MAX_LONG_LEN) |
exp_start = buf + sizeof (buf) - MAX_LONG_LEN - 1; |
swprintf (exp_start, MAX_LONG_LEN, L"e%ld", new_exp); |
} |
/* FIXME: We don't have wcstold yet. */ |
#if 0//ndef _NO_LONGDBL /* !_NO_LONGDBL */ |
if (flags & LONGDBL) |
qres = _wcstold_r (rptr, buf, NULL); |
else |
#endif |
res = _wcstod_r (rptr, buf, NULL); |
if (flags & LONG) |
{ |
dp = GET_ARG (N, ap, double *); |
*dp = res; |
} |
else if (flags & LONGDBL) |
{ |
ldp = GET_ARG (N, ap, _LONG_DOUBLE *); |
*ldp = QUAD_RES; |
} |
else |
{ |
flp = GET_ARG (N, ap, float *); |
if (isnan (res)) |
*flp = nanf (NULL); |
else |
*flp = res; |
} |
nassigned++; |
} |
break; |
} |
#endif /* FLOATING_POINT */ |
} |
} |
input_failure: |
/* On read failure, return EOF failure regardless of matches; errno |
should have been set prior to here. On EOF failure (including |
invalid format string), return EOF if no matches yet, else number |
of matches made prior to failure. */ |
_newlib_flockfile_exit (fp); |
return nassigned && !(fp->_flags & __SERR) ? nassigned : EOF; |
match_failure: |
all_done: |
/* Return number of matches, which can be 0 on match failure. */ |
_newlib_flockfile_end (fp); |
return nassigned; |
} |
#ifndef _NO_POS_ARGS |
/* Process all intermediate arguments. Fortunately, with wscanf, all |
intermediate arguments are sizeof(void*), so we don't need to scan |
ahead in the format string. */ |
static void * |
get_arg (int n, va_list *ap, int *numargs_p, void **args) |
{ |
int numargs = *numargs_p; |
while (n >= numargs) |
args[numargs++] = va_arg (*ap, void *); |
*numargs_p = numargs; |
return args[n]; |
} |
#endif /* !_NO_POS_ARGS */ |
/contrib/sdk/sources/newlib/libc/stdio/vswprintf.c |
---|
0,0 → 1,82 |
/* |
* Copyright (c) 1990 The Regents of the University of California. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms are permitted |
* provided that the above copyright notice and this paragraph are |
* duplicated in all such forms and that any documentation, |
* advertising materials, and other materials related to such |
* distribution and use acknowledge that the software was developed |
* by the University of California, Berkeley. The name of the |
* University may not be used to endorse or promote products derived |
* from this software without specific prior written permission. |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
*/ |
/* doc in vfwprintf.c */ |
#if defined(LIBC_SCCS) && !defined(lint) |
static char sccsid[] = "%W% (Berkeley) %G%"; |
#endif /* LIBC_SCCS and not lint */ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include <limits.h> |
#include <stdarg.h> |
#include <errno.h> |
#include "local.h" |
int |
_DEFUN(_vswprintf_r, (ptr, str, size, fmt, ap), |
struct _reent *ptr _AND |
wchar_t *str _AND |
size_t size _AND |
const wchar_t *fmt _AND |
va_list ap) |
{ |
int ret; |
FILE f; |
if (size > INT_MAX / sizeof (wchar_t)) |
{ |
ptr->_errno = EOVERFLOW; /* POSIX extension */ |
return EOF; |
} |
f._flags = __SWR | __SSTR; |
f._bf._base = f._p = (unsigned char *) str; |
f._bf._size = f._w = (size > 0 ? (size - 1) * sizeof (wchar_t) : 0); |
f._file = -1; /* No file. */ |
ret = _svfwprintf_r (ptr, &f, fmt, ap); |
/* _svfwprintf_r() does not put in a terminating NUL, so add one if |
* appropriate, which is whenever size is > 0. _svfwprintf_r() stops |
* after n-1, so always just put at the end. */ |
if (size > 0) { |
*(wchar_t *)f._p = L'\0'; /* terminate the string */ |
} |
if(ret >= size) { |
/* _svfwprintf_r() returns how many wide characters it would have printed |
* if there were enough space. Return an error if too big to fit in str, |
* unlike snprintf, which returns the size needed. */ |
ptr->_errno = EOVERFLOW; /* POSIX extension */ |
ret = -1; |
} |
return ret; |
} |
#ifndef _REENT_ONLY |
int |
_DEFUN(vswprintf, (str, size, fmt, ap), |
wchar_t *__restrict str _AND |
size_t size _AND |
const wchar_t *__restrict fmt _AND |
va_list ap) |
{ |
return _vswprintf_r (_REENT, str, size, fmt, ap); |
} |
#endif /* !_REENT_ONLY */ |
/contrib/sdk/sources/newlib/libc/stdio/vswscanf.c |
---|
0,0 → 1,62 |
/* |
* Code created by modifying scanf.c which has following copyright. |
* |
* Copyright (c) 1990 The Regents of the University of California. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms are permitted |
* provided that the above copyright notice and this paragraph are |
* duplicated in all such forms and that any documentation, |
* advertising materials, and other materials related to such |
* distribution and use acknowledge that the software was developed |
* by the University of California, Berkeley. The name of the |
* University may not be used to endorse or promote products derived |
* from this software without specific prior written permission. |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
*/ |
/* Doc in vfwscanf.c */ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include <string.h> |
#ifdef _HAVE_STDC |
#include <stdarg.h> |
#else |
#include <varargs.h> |
#endif |
#include "local.h" |
/* |
* vsscanf |
*/ |
#ifndef _REENT_ONLY |
int |
vswscanf (_CONST wchar_t *__restrict str, _CONST wchar_t * __restrict fmt, |
va_list ap) |
{ |
return _vswscanf_r (_REENT, str, fmt, ap); |
} |
#endif /* !_REENT_ONLY */ |
int |
_vswscanf_r (struct _reent *ptr, _CONST wchar_t *str, _CONST wchar_t *fmt, |
va_list ap) |
{ |
FILE f; |
f._flags = __SRD | __SSTR; |
f._bf._base = f._p = (unsigned char *) str; |
f._bf._size = f._r = wcslen (str) * sizeof (wchar_t); |
f._read = __seofread; |
f._ub._base = NULL; |
f._lb._base = NULL; |
f._file = -1; /* No file. */ |
return __ssvfwscanf_r (ptr, &f, fmt, ap); |
} |
/contrib/sdk/sources/newlib/libc/stdio/vwprintf.c |
---|
0,0 → 1,49 |
/* |
* Copyright (c) 1990 The Regents of the University of California. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms are permitted |
* provided that the above copyright notice and this paragraph are |
* duplicated in all such forms and that any documentation, |
* advertising materials, and other materials related to such |
* distribution and use acknowledge that the software was developed |
* by the University of California, Berkeley. The name of the |
* University may not be used to endorse or promote products derived |
* from this software without specific prior written permission. |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
*/ |
/* doc in vfwprintf.c */ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include <stdarg.h> |
#include "local.h" |
#ifndef _REENT_ONLY |
int |
_DEFUN(vwprintf, (fmt, ap), |
_CONST wchar_t *__restrict fmt _AND |
va_list ap) |
{ |
struct _reent *reent = _REENT; |
_REENT_SMALL_CHECK_INIT (reent); |
return _vfwprintf_r (reent, _stdout_r (reent), fmt, ap); |
} |
#endif /* !_REENT_ONLY */ |
int |
_DEFUN(_vwprintf_r, (ptr, fmt, ap), |
struct _reent *ptr _AND |
_CONST wchar_t *fmt _AND |
va_list ap) |
{ |
_REENT_SMALL_CHECK_INIT (ptr); |
return _vfwprintf_r (ptr, _stdout_r (ptr), fmt, ap); |
} |
/contrib/sdk/sources/newlib/libc/stdio/vwscanf.c |
---|
0,0 → 1,51 |
/*- |
* Code created by modifying scanf.c which has following copyright. |
* |
* Copyright (c) 1990 The Regents of the University of California. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms are permitted |
* provided that the above copyright notice and this paragraph are |
* duplicated in all such forms and that any documentation, |
* advertising materials, and other materials related to such |
* distribution and use acknowledge that the software was developed |
* by the University of California, Berkeley. The name of the |
* University may not be used to endorse or promote products derived |
* from this software without specific prior written permission. |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
*/ |
/* Doc in vfwscanf.c */ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#ifdef _HAVE_STDC |
#include <stdarg.h> |
#else |
#include <varargs.h> |
#endif |
#include "local.h" |
#ifndef _REENT_ONLY |
int |
vwscanf (_CONST wchar_t *__restrict fmt, va_list ap) |
{ |
struct _reent *reent = _REENT; |
_REENT_SMALL_CHECK_INIT (reent); |
return __svfwscanf_r (reent, _stdin_r (reent), fmt, ap); |
} |
#endif /* !_REENT_ONLY */ |
int |
_vwscanf_r (struct _reent *ptr, _CONST wchar_t *fmt, va_list ap) |
{ |
_REENT_SMALL_CHECK_INIT (ptr); |
return __svfwscanf_r (ptr, _stdin_r (ptr), fmt, ap); |
} |
/contrib/sdk/sources/newlib/libc/stdio/wprintf.c |
---|
0,0 → 1,58 |
/* |
* Copyright (c) 1990 The Regents of the University of California. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms are permitted |
* provided that the above copyright notice and this paragraph are |
* duplicated in all such forms and that any documentation, |
* advertising materials, and other materials related to such |
* distribution and use acknowledge that the software was developed |
* by the University of California, Berkeley. The name of the |
* University may not be used to endorse or promote products derived |
* from this software without specific prior written permission. |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
*/ |
/* doc in swprintf.c */ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include <stdarg.h> |
#include "local.h" |
int |
_DEFUN(_wprintf_r, (ptr, fmt), |
struct _reent *ptr _AND |
const wchar_t *fmt _DOTS) |
{ |
int ret; |
va_list ap; |
_REENT_SMALL_CHECK_INIT (ptr); |
va_start (ap, fmt); |
ret = _vfwprintf_r (ptr, _stdout_r (ptr), fmt, ap); |
va_end (ap); |
return ret; |
} |
#ifndef _REENT_ONLY |
int |
_DEFUN(wprintf, (fmt), |
const wchar_t *__restrict fmt _DOTS) |
{ |
int ret; |
va_list ap; |
struct _reent *ptr = _REENT; |
_REENT_SMALL_CHECK_INIT (ptr); |
va_start (ap, fmt); |
ret = _vfwprintf_r (ptr, _stdout_r (ptr), fmt, ap); |
va_end (ap); |
return ret; |
} |
#endif /* ! _REENT_ONLY */ |
/contrib/sdk/sources/newlib/libc/stdio/wscanf.c |
---|
0,0 → 1,56 |
/* |
* Copyright (c) 1990 The Regents of the University of California. |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms are permitted |
* provided that the above copyright notice and this paragraph are |
* duplicated in all such forms and that any documentation, |
* advertising materials, and other materials related to such |
* distribution and use acknowledge that the software was developed |
* by the University of California, Berkeley. The name of the |
* University may not be used to endorse or promote products derived |
* from this software without specific prior written permission. |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
*/ |
/* Doc in swscanf.c */ |
#include <_ansi.h> |
#include <reent.h> |
#include <stdio.h> |
#include <wchar.h> |
#include <stdarg.h> |
#include "local.h" |
#ifndef _REENT_ONLY |
int |
wscanf(_CONST wchar_t *__restrict fmt, ...) |
{ |
int ret; |
va_list ap; |
struct _reent *reent = _REENT; |
_REENT_SMALL_CHECK_INIT (reent); |
va_start (ap, fmt); |
ret = _vfwscanf_r (reent, _stdin_r (reent), fmt, ap); |
va_end (ap); |
return ret; |
} |
#endif /* !_REENT_ONLY */ |
int |
_wscanf_r(struct _reent *ptr, _CONST wchar_t *fmt, ...) |
{ |
int ret; |
va_list ap; |
_REENT_SMALL_CHECK_INIT (ptr); |
va_start (ap, fmt); |
ret = _vfwscanf_r (ptr, _stdin_r (ptr), fmt, ap); |
va_end (ap); |
return (ret); |
} |