newlib: wide char support

git-svn-id: svn://kolibrios.org@6607 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge)
2016-10-19 01:34:56 +00:00
parent e8b5d31a31
commit d210a76d45
61 changed files with 13918 additions and 823 deletions

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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"

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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"

View File

@@ -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 */

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -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 */

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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 */

View File

@@ -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);
}