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

@ -165,6 +165,8 @@ STDLIB_SRCS= \
atof.c \
atoi.c \
atol.c \
btowc.c \
calloc.c \
cxa_atexit.c \
cxa_finalize.c \
div.c \
@ -180,18 +182,28 @@ STDLIB_SRCS= \
getenv.c \
getenv_r.c \
itoa.c \
ldiv.c \
labs.c \
mprec.c \
mbtowc.c \
mbtowc_r.c \
mbrtowc.c \
mlock.c \
calloc.c \
ldtoa.c \
malloc.c \
mallocr.c \
mblen.c \
mblen_r.c \
mbrlen.c \
mbrtowc.c \
mbsinit.c \
mbsnrtowcs.c \
mbsrtowcs.c \
mbstowcs.c \
mbstowcs_r.c \
mbtowc.c \
mbtowc_r.c \
mlock.c \
mprec.c \
rand.c \
rand_r.c \
rand48.c \
random.c \
realloc.c \
seed48.c \
srand48.c \
@ -208,6 +220,20 @@ STDLIB_SRCS= \
system.c \
utoa.c \
wcrtomb.c \
wcsnrtombs.c \
wcsrtombs.c \
wcstod.c \
wcstol.c \
wcstold.c \
wcstoll.c \
wcstoll_r.c \
wcstombs.c \
wcstombs_r.c \
wcstoul.c \
wcstoull.c \
wcstoull_r.c \
wctob.c \
wctomb.c \
wctomb_r.c
@ -322,6 +348,10 @@ STDIO_SRCS= \
fgetpos.c \
fgets.c \
fgets_u.c \
fgetwc.c \
fgetwc_u.c \
fgetws.c \
fgetws_u.c \
fileno.c \
fileno_u.c \
findfp.c \
@ -338,6 +368,9 @@ STDIO_SRCS= \
fputs.c \
fputs_u.c \
fputwc.c \
fputwc_u.c \
fputws.c \
fputws_u.c \
fsetpos.c \
funopen.c \
fread.c \
@ -352,8 +385,10 @@ STDIO_SRCS= \
fvwrite.c \
fwalk.c \
fwide.c \
fwprintf.c \
fwrite.c \
fwrite_u.c \
fwscanf.c \
getc.c \
getc_u.c \
getchar.c \
@ -361,10 +396,14 @@ STDIO_SRCS= \
getdelim.c \
getline.c \
gets.c \
getw.c \
getwc.c \
getwc_u.c \
getwchar.c \
getwchar_u.c \
iprintf.c \
iscanf.c \
makebuf.c \
mbstowcs.c \
mktemp.c \
open_memstream.c \
perror.c \
@ -374,6 +413,11 @@ STDIO_SRCS= \
putchar.c \
putchar_u.c \
puts.c \
putw.c \
putwc.c \
putwc_u.c \
putwchar.c \
putwchar_u.c \
refill.c \
remove.c \
rename.c \
@ -393,15 +437,19 @@ STDIO_SRCS= \
sscanf.c \
stdio.c \
stdio_ext.c \
swprintf.c \
swscanf.c \
tmpfile.c \
tmpnam.c \
ungetc.c \
ungetwc.c \
vasiprintf.c \
vasniprintf.c \
vasnprintf.c \
vasprintf.c \
vdiprintf.c \
vdprintf.c \
vfwscanf.c \
viprintf.c \
viscanf.c \
vprintf.c \
@ -412,8 +460,14 @@ STDIO_SRCS= \
vsniprintf.c \
vsnprintf.c \
vsscanf.c \
wsetup.c \
wbuf.c
vswprintf.c \
vswscanf.c \
vwprintf.c \
vwscanf.c \
wbuf.c \
wprintf.c \
wscanf.c \
wsetup.c
MATH_SRCS = e_acos.c e_acosh.c e_asin.c e_atan2.c e_atanh.c e_cosh.c e_exp.c e_fmod.c \
@ -481,10 +535,16 @@ PRINTF_OBJS= stdio/vfprintf.o \
stdio/vfiprintf.o \
stdio/svfprintf.o \
stdio/svfiprintf.o \
stdio/svfiwprintf.o \
stdio/svfwprintf.o \
stdio/vfiwprintf.o \
stdio/vfwprintf.o \
stdio/vfscanf.o \
stdio/vfiscanf.o \
stdio/svscanf.o \
stdio/svfiscanf.o
stdio/svfiscanf.o \
stdio/svfiwscanf.o \
stdio/svfwscanf.o
ifeq ($(findstring static,$(MAKECMDGOALS)),static)
@ -561,6 +621,17 @@ stdio/vfiprintf.o: stdio/vfprintf.c
stdio/vfprintf.o: stdio/vfprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums stdio/vfprintf.c -o $@
stdio/svfiwprintf.o: stdio/vfwprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums -DINTEGER_ONLY -DSTRING_ONLY stdio/vfwprintf.c -o $@
stdio/svfwprintf.o: stdio/vfwprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums -DSTRING_ONLY stdio/vfwprintf.c -o $@
stdio/vfiwprintf.o: stdio/vfwprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums -DINTEGER_ONLY stdio/vfwprintf.c -o $@
stdio/vfwprintf.o: stdio/vfwprintf.c
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -fshort-enums stdio/vfwprintf.c -o $@
stdio/svfiscanf.o: stdio/vfscanf.c
$(CC) $(CFLAGS) $(DEFINES) -DINTEGER_ONLY -DSTRING_ONLY $(INCLUDES) stdio/vfscanf.c -o $@
@ -574,7 +645,14 @@ stdio/vfscanf.o: stdio/vfscanf.c
stdio/vfiscanf.o: stdio/vfscanf.c
$(CC) $(CFLAGS) $(DEFINES) -DINTEGER_ONLY $(INCLUDES) stdio/vfscanf.c -o $@
stdio/svfiwscanf.o: stdio/vfwscanf.c
$(CC) $(CFLAGS) $(DEFINES) -DINTEGER_ONLY -DSTRING_ONLY $(INCLUDES) stdio/vfwscanf.c -o $@
stdio/svfwscanf.o: stdio/vfwscanf.c
$(CC) $(CFLAGS) $(DEFINES) -DSTRING_ONLY $(INCLUDES) stdio/vfwscanf.c -o $@
stdio/vfiwscanf.o: stdio/vfwscanf.c
$(CC) $(CFLAGS) $(DEFINES) -DINTEGER_ONLY $(INCLUDES) stdio/vfwscanf.c -o $@

View File

@ -56,7 +56,7 @@
#define _ATEXIT_DYNAMIC_ALLOC 1
/* True if long double supported. */
//#define _HAVE_LONG_DOUBLE 1
#define _HAVE_LONG_DOUBLE 1
/* Define if compiler supports -fno-tree-loop-distribute-patterns. */
#define _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL 1

View File

@ -20,7 +20,7 @@ void _EXFUN(_exit, (int __status ) _ATTRIBUTE ((__noreturn__)));
int _EXFUN(access,(const char *__path, int __amode ));
unsigned _EXFUN(alarm, (unsigned __secs ));
int _EXFUN(chdir, (const char *__path ));
int _EXFUN(chmod, (const char *__path, mode_t __mode ));
//int _EXFUN(chmod, (const char *__path, mode_t __mode ));
#if !defined(__INSIDE_CYGWIN__)
int _EXFUN(chown, (const char *__path, uid_t __owner, gid_t __group ));
#endif
@ -66,7 +66,7 @@ int _EXFUN(faccessat, (int __dirfd, const char *__path, int __mode, int __flags)
#if __BSD_VISIBLE || __XSI_VISIBLE >= 4
int _EXFUN(fchdir, (int __fildes));
#endif
int _EXFUN(fchmod, (int __fildes, mode_t __mode ));
//int _EXFUN(fchmod, (int __fildes, mode_t __mode ));
#if !defined(__INSIDE_CYGWIN__)
int _EXFUN(fchown, (int __fildes, uid_t __owner, gid_t __group ));
#endif

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

View File

@ -0,0 +1,33 @@
#include <wchar.h>
#include <stdlib.h>
#include <stdio.h>
#include <reent.h>
#include <string.h>
#include "local.h"
wint_t
btowc (int c)
{
mbstate_t mbs;
int retval = 0;
wchar_t pwc;
unsigned char b;
if (c == EOF)
return WEOF;
b = (unsigned char)c;
/* Put mbs in initial state. */
memset (&mbs, '\0', sizeof (mbs));
_REENT_CHECK_MISC(_REENT);
retval = __mbtowc (_REENT, &pwc, (const char *) &b, 1,
__locale_charset (), &mbs);
if (retval != 0 && retval != 1)
return WEOF;
return (wint_t)pwc;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,81 @@
/*
FUNCTION
<<mblen>>---minimal multibyte length function
INDEX
mblen
ANSI_SYNOPSIS
#include <stdlib.h>
int mblen(const char *<[s]>, size_t <[n]>);
TRAD_SYNOPSIS
#include <stdlib.h>
int mblen(<[s]>, <[n]>)
const char *<[s]>;
size_t <[n]>;
DESCRIPTION
When _MB_CAPABLE is not defined, this is a minimal ANSI-conforming
implementation of <<mblen>>. In this case, the
only ``multi-byte character sequences'' recognized are single bytes,
and thus <<1>> is returned unless <[s]> is the null pointer or
has a length of 0 or is the empty string.
When _MB_CAPABLE is defined, this routine calls <<_mbtowc_r>> to perform
the conversion, passing a state variable to allow state dependent
decoding. The result is based on the locale setting which may
be restricted to a defined set of locales.
RETURNS
This implementation of <<mblen>> returns <<0>> if
<[s]> is <<NULL>> or the empty string; it returns <<1>> if not _MB_CAPABLE or
the character is a single-byte character; it returns <<-1>>
if the multi-byte character is invalid; otherwise it returns
the number of bytes in the multibyte character.
PORTABILITY
<<mblen>> is required in the ANSI C standard. However, the precise
effects vary with the locale.
<<mblen>> requires no supporting OS subroutines.
*/
#ifndef _REENT_ONLY
#include <newlib.h>
#include <stdlib.h>
#include <wchar.h>
#include "local.h"
int
_DEFUN (mblen, (s, n),
const char *s _AND
size_t n)
{
#ifdef _MB_CAPABLE
int retval = 0;
struct _reent *reent = _REENT;
mbstate_t *state;
_REENT_CHECK_MISC(reent);
state = &(_REENT_MBLEN_STATE(reent));
retval = __mbtowc (reent, NULL, s, n, __locale_charset (), state);
if (retval < 0)
{
state->__count = 0;
return -1;
}
else
return retval;
#else /* not _MB_CAPABLE */
if (s == NULL || *s == '\0')
return 0;
if (n == 0)
return -1;
return 1;
#endif /* not _MB_CAPABLE */
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,77 @@
/*
FUNCTION
<<_mblen_r>>---reentrant minimal multibyte length function
INDEX
_mblen_r
ANSI_SYNOPSIS
#include <stdlib.h>
int _mblen_r(struct _reent *<[r]>, const char *<[s]>, size_t <[n]>, int *<[state]>);
TRAD_SYNOPSIS
#include <stdlib.h>
int _mblen_r(<[r]>, <[s]>, <[n]>, <[state]>)
struct _reent *<[r]>;
const char *<[s]>;
size_t <[n]>;
int *<[state]>;
DESCRIPTION
When _MB_CAPABLE is not defined, this is a minimal ANSI-conforming
implementation of <<_mblen_r>>. In this case, the
only ``multi-byte character sequences'' recognized are single bytes,
and thus <<1>> is returned unless <[s]> is the null pointer or
has a length of 0 or is the empty string.
When _MB_CAPABLE is defined, this routine calls <<_mbtowc_r>> to perform
the conversion, passing a state variable to allow state dependent
decoding. The result is based on the locale setting which may
be restricted to a defined set of locales.
RETURNS
This implementation of <<_mblen_r>> returns <<0>> if
<[s]> is <<NULL>> or the empty string; it returns <<1>> if not _MB_CAPABLE or
the character is a single-byte character; it returns <<-1>>
if the multi-byte character is invalid; otherwise it returns
the number of bytes in the multibyte character.
PORTABILITY
<<_mblen>> is required in the ANSI C standard. However, the precise
effects vary with the locale.
<<_mblen_r>> requires no supporting OS subroutines.
*/
#include <newlib.h>
#include <stdlib.h>
#include <wchar.h>
#include "local.h"
int
_DEFUN (_mblen_r, (r, s, n, state),
struct _reent *r _AND
const char *s _AND
size_t n _AND
mbstate_t *state)
{
#ifdef _MB_CAPABLE
int retval;
retval = __mbtowc (r, NULL, s, n, __locale_charset (), state);
if (retval < 0)
{
state->__count = 0;
return -1;
}
return retval;
#else /* not _MB_CAPABLE */
if (s == NULL || *s == '\0')
return 0;
if (n == 0)
return -1;
return 1;
#endif /* not _MB_CAPABLE */
}

View File

@ -0,0 +1,22 @@
#include <reent.h>
#include <newlib.h>
#include <wchar.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
size_t
mbrlen(const char *__restrict s, size_t n, mbstate_t *__restrict ps)
{
#ifdef _MB_CAPABLE
if (ps == NULL)
{
struct _reent *reent = _REENT;
_REENT_CHECK_MISC(reent);
ps = &(_REENT_MBRLEN_STATE(reent));
}
#endif
return mbrtowc(NULL, s, n, ps);
}

View File

@ -0,0 +1,14 @@
#include <reent.h>
#include <wchar.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
int
mbsinit(const mbstate_t *ps)
{
if (ps == NULL || ps->__count == 0)
return 1;
else
return 0;
}

View File

@ -0,0 +1,182 @@
/*
FUNCTION
<<mbsrtowcs>>, <<mbsnrtowcs>>---convert a character string to a wide-character string
INDEX
mbsrtowcs
INDEX
_mbsrtowcs_r
INDEX
mbsnrtowcs
INDEX
_mbsnrtowcs_r
ANSI_SYNOPSIS
#include <wchar.h>
size_t mbsrtowcs(wchar_t *__restrict <[dst]>,
const char **__restrict <[src]>,
size_t <[len]>,
mbstate_t *__restrict <[ps]>);
#include <wchar.h>
size_t _mbsrtowcs_r(struct _reent *<[ptr]>, wchar_t *<[dst]>,
const char **<[src]>, size_t <[len]>,
mbstate_t *<[ps]>);
#include <wchar.h>
size_t mbsnrtowcs(wchar_t *__ restrict <[dst]>,
const char **__restrict <[src]>, size_t <[nms]>,
size_t <[len]>, mbstate_t *__restrict <[ps]>);
#include <wchar.h>
size_t _mbsnrtowcs_r(struct _reent *<[ptr]>, wchar_t *<[dst]>,
const char **<[src]>, size_t <[nms]>,
size_t <[len]>, mbstate_t *<[ps]>);
TRAD_SYNOPSIS
#include <wchar.h>
size_t mbsrtowcs(<[dst]>, <[src]>, <[len]>, <[ps]>)
wchar_t *__restrict <[dst]>;
const char **__restrict <[src]>;
size_t <[len]>;
mbstate_t *__restrict <[ps]>;
#include <wchar.h>
size_t _mbsrtowcs_r(<[ptr]>, <[dst]>, <[src]>, <[len]>, <[ps]>)
struct _reent *<[ptr]>;
wchar_t *<[dst]>;
const char **<[src]>;
size_t <[len]>;
mbstate_t *<[ps]>;
#include <wchar.h>
size_t mbsnrtowcs(<[dst]>, <[src]>, <[nms]>, <[len]>, <[ps]>)
wchar_t *__restrict <[dst]>;
const char **__restrict <[src]>;
size_t <[nms]>;
size_t <[len]>;
mbstate_t *__restrict <[ps]>;
#include <wchar.h>
size_t _mbsnrtowcs_r(<[ptr]>, <[dst]>, <[src]>, <[nms]>, <[len]>, <[ps]>)
struct _reent *<[ptr]>;
wchar_t *<[dst]>;
const char **<[src]>;
size_t <[nms]>;
size_t <[len]>;
mbstate_t *<[ps]>;
DESCRIPTION
The <<mbsrtowcs>> function converts a sequence of multibyte characters
pointed to indirectly by <[src]> into a sequence of corresponding wide
characters and stores at most <[len]> of them in the wchar_t array pointed
to by <[dst]>, until it encounters a terminating null character ('\0').
If <[dst]> is NULL, no characters are stored.
If <[dst]> is not NULL, the pointer pointed to by <[src]> is updated to point
to the character after the one that conversion stopped at. If conversion
stops because a null character is encountered, *<[src]> is set to NULL.
The mbstate_t argument, <[ps]>, is used to keep track of the shift state. If
it is NULL, <<mbsrtowcs>> uses an internal, static mbstate_t object, which
is initialized to the initial conversion state at program startup.
The <<mbsnrtowcs>> function behaves identically to <<mbsrtowcs>>, except that
conversion stops after reading at most <[nms]> bytes from the buffer pointed
to by <[src]>.
RETURNS
The <<mbsrtowcs>> and <<mbsnrtowcs>> functions return the number of wide
characters stored in the array pointed to by <[dst]> if successful, otherwise
it returns (size_t)-1.
PORTABILITY
<<mbsrtowcs>> is defined by the C99 standard.
<<mbsnrtowcs>> is defined by the POSIX.1-2008 standard.
*/
#include <reent.h>
#include <newlib.h>
#include <wchar.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
size_t
_DEFUN (_mbsnrtowcs_r, (r, dst, src, nms, len, ps),
struct _reent *r _AND
wchar_t *dst _AND
const char **src _AND
size_t nms _AND
size_t len _AND
mbstate_t *ps)
{
wchar_t *ptr = dst;
const char *tmp_src;
size_t max;
size_t count = 0;
int bytes;
#ifdef _MB_CAPABLE
if (ps == NULL)
{
_REENT_CHECK_MISC(r);
ps = &(_REENT_MBSRTOWCS_STATE(r));
}
#endif
if (dst == NULL)
{
/* Ignore original len value and do not alter src pointer if the
dst pointer is NULL. */
len = (size_t)-1;
tmp_src = *src;
src = &tmp_src;
}
max = len;
while (len > 0)
{
bytes = _mbrtowc_r (r, ptr, *src, nms, ps);
if (bytes > 0)
{
*src += bytes;
nms -= bytes;
++count;
ptr = (dst == NULL) ? NULL : ptr + 1;
--len;
}
else if (bytes == -2)
{
*src += nms;
return count;
}
else if (bytes == 0)
{
*src = NULL;
return count;
}
else
{
ps->__count = 0;
r->_errno = EILSEQ;
return (size_t)-1;
}
}
return (size_t)max;
}
#ifndef _REENT_ONLY
size_t
_DEFUN (mbsnrtowcs, (dst, src, nms, len, ps),
wchar_t *__restrict dst _AND
const char **__restrict src _AND
size_t nms _AND
size_t len _AND
mbstate_t *__restrict ps)
{
return _mbsnrtowcs_r (_REENT, dst, src, nms, len, ps);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,31 @@
/* doc in mbsnrtowcs.c */
#include <reent.h>
#include <newlib.h>
#include <wchar.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
size_t
_DEFUN (_mbsrtowcs_r, (r, dst, src, len, ps),
struct _reent *r _AND
wchar_t *dst _AND
const char **src _AND
size_t len _AND
mbstate_t *ps)
{
return _mbsnrtowcs_r (r, dst, src, (size_t) -1, len, ps);
}
#ifndef _REENT_ONLY
size_t
_DEFUN (mbsrtowcs, (dst, src, len, ps),
wchar_t *__restrict dst _AND
const char **__restrict src _AND
size_t len _AND
mbstate_t *__restrict ps)
{
return _mbsnrtowcs_r (_REENT, dst, src, (size_t) -1, len, ps);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,83 @@
/*
FUNCTION
<<mbstowcs>>---minimal multibyte string to wide char converter
INDEX
mbstowcs
ANSI_SYNOPSIS
#include <stdlib.h>
int mbstowcs(wchar_t *restrict <[pwc]>, const char *restrict <[s]>, size_t <[n]>);
TRAD_SYNOPSIS
#include <stdlib.h>
int mbstowcs(<[pwc]>, <[s]>, <[n]>)
wchar_t *<[pwc]>;
const char *<[s]>;
size_t <[n]>;
DESCRIPTION
When _MB_CAPABLE is not defined, this is a minimal ANSI-conforming
implementation of <<mbstowcs>>. In this case, the
only ``multi-byte character sequences'' recognized are single bytes,
and they are ``converted'' to wide-char versions simply by byte
extension.
When _MB_CAPABLE is defined, this routine calls <<_mbstowcs_r>> to perform
the conversion, passing a state variable to allow state dependent
decoding. The result is based on the locale setting which may
be restricted to a defined set of locales.
RETURNS
This implementation of <<mbstowcs>> returns <<0>> if
<[s]> is <<NULL>> or is the empty string;
it returns <<-1>> if _MB_CAPABLE and one of the
multi-byte characters is invalid or incomplete;
otherwise it returns the minimum of: <<n>> or the
number of multi-byte characters in <<s>> plus 1 (to
compensate for the nul character).
If the return value is -1, the state of the <<pwc>> string is
indeterminate. If the input has a length of 0, the output
string will be modified to contain a wchar_t nul terminator.
PORTABILITY
<<mbstowcs>> is required in the ANSI C standard. However, the precise
effects vary with the locale.
<<mbstowcs>> requires no supporting OS subroutines.
*/
#ifndef _REENT_ONLY
#include <newlib.h>
#include <stdlib.h>
#include <wchar.h>
size_t
_DEFUN (mbstowcs, (pwcs, s, n),
wchar_t *__restrict pwcs _AND
const char *__restrict s _AND
size_t n)
{
#ifdef _MB_CAPABLE
mbstate_t state;
state.__count = 0;
return _mbstowcs_r (_REENT, pwcs, s, n, &state);
#else /* not _MB_CAPABLE */
int count = 0;
if (n != 0) {
do {
if ((*pwcs++ = (wchar_t) *s++) == 0)
break;
count++;
} while (--n != 0);
}
return count;
#endif /* not _MB_CAPABLE */
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,38 @@
#include <stdlib.h>
#include <wchar.h>
#include "local.h"
size_t
_DEFUN (_mbstowcs_r, (reent, pwcs, s, n, state),
struct _reent *r _AND
wchar_t *__restrict pwcs _AND
const char *__restrict s _AND
size_t n _AND
mbstate_t *state)
{
size_t ret = 0;
char *t = (char *)s;
int bytes;
if (!pwcs)
n = (size_t) 1; /* Value doesn't matter as long as it's not 0. */
while (n > 0)
{
bytes = __mbtowc (r, pwcs, t, MB_CUR_MAX, __locale_charset (), state);
if (bytes < 0)
{
state->__count = 0;
return -1;
}
else if (bytes == 0)
break;
t += bytes;
++ret;
if (pwcs)
{
++pwcs;
--n;
}
}
return ret;
}

View File

@ -0,0 +1,82 @@
/*
FUNCTION
<<random>>, <<srandom>>---pseudo-random numbers
INDEX
random
INDEX
srandom
ANSI_SYNOPSIS
#define _XOPEN_SOURCE 500
#include <stdlib.h>
long int random(void);
void srandom(unsigned int <[seed]>);
DESCRIPTION
<<random>> returns a different integer each time it is called; each
integer is chosen by an algorithm designed to be unpredictable, so
that you can use <<random>> when you require a random number.
The algorithm depends on a static variable called the ``random seed'';
starting with a given value of the random seed always produces the
same sequence of numbers in successive calls to <<random>>.
You can set the random seed using <<srandom>>; it does nothing beyond
storing its argument in the static variable used by <<rand>>. You can
exploit this to make the pseudo-random sequence less predictable, if
you wish, by using some other unpredictable value (often the least
significant parts of a time-varying value) as the random seed before
beginning a sequence of calls to <<rand>>; or, if you wish to ensure
(for example, while debugging) that successive runs of your program
use the same ``random'' numbers, you can use <<srandom>> to set the same
random seed at the outset.
RETURNS
<<random>> returns the next pseudo-random integer in sequence; it is a
number between <<0>> and <<RAND_MAX>> (inclusive).
<<srandom>> does not return a result.
NOTES
<<random>> and <<srandom>> are unsafe for multi-threaded applications.
_XOPEN_SOURCE may be any value >= 500.
PORTABILITY
<<random>> is required by XSI. This implementation uses the same
algorithm as <<rand>>.
<<random>> requires no supporting OS subroutines.
*/
#ifndef _REENT_ONLY
#include <stdlib.h>
#include <reent.h>
void
_DEFUN (srandom, (seed), unsigned int seed)
{
struct _reent *reent = _REENT;
_REENT_CHECK_RAND48(reent);
_REENT_RAND_NEXT(reent) = seed;
}
long int
_DEFUN_VOID (random)
{
struct _reent *reent = _REENT;
/* This multiplier was obtained from Knuth, D.E., "The Art of
Computer Programming," Vol 2, Seminumerical Algorithms, Third
Edition, Addison-Wesley, 1998, p. 106 (line 26) & p. 108 */
_REENT_CHECK_RAND48(reent);
_REENT_RAND_NEXT(reent) =
_REENT_RAND_NEXT(reent) * __extension__ 6364136223846793005LL + 1;
return (long int)((_REENT_RAND_NEXT(reent) >> 32) & RAND_MAX);
}
#endif /* _REENT_ONLY */

View File

@ -0,0 +1,188 @@
/*
FUNCTION
<<wcsrtombs>>, <<wcsnrtombs>>---convert a wide-character string to a character string
INDEX
wcsrtombs
INDEX
_wcsrtombs_r
INDEX
wcsnrtombs
INDEX
_wcsnrtombs_r
ANSI_SYNOPSIS
#include <wchar.h>
size_t wcsrtombs(char *__restrict <[dst]>,
const wchar_t **__restrict <[src]>, size_t <[len]>,
mbstate_t *__restrict <[ps]>);
#include <wchar.h>
size_t _wcsrtombs_r(struct _reent *<[ptr]>, char *<[dst]>,
const wchar_t **<[src]>, size_t <[len]>,
mbstate_t *<[ps]>);
#include <wchar.h>
size_t wcsnrtombs(char *__restrict <[dst]>,
const wchar_t **__restrict <[src]>,
size_t <[nwc]>, size_t <[len]>,
mbstate_t *__restrict <[ps]>);
#include <wchar.h>
size_t _wcsnrtombs_r(struct _reent *<[ptr]>, char *<[dst]>,
const wchar_t **<[src]>, size_t <[nwc]>,
size_t <[len]>, mbstate_t *<[ps]>);
TRAD_SYNOPSIS
#include <wchar.h>
size_t wcsrtombs(<[dst]>, <[src]>, <[len]>, <[ps]>)
char *__restrict <[dst]>;
const wchar_t **__restrict <[src]>;
size_t <[len]>;
mbstate_t *__restrict <[ps]>;
#include <wchar.h>
size_t _wcsrtombs_r(<[ptr]>, <[dst]>, <[src]>, <[len]>, <[ps]>)
struct _rent *<[ptr]>;
char *<[dst]>;
const wchar_t **<[src]>;
size_t <[len]>;
mbstate_t *<[ps]>;
#include <wchar.h>
size_t wcsnrtombs(<[dst]>, <[src]>, <[nwc]>, <[len]>, <[ps]>)
char *__restrict <[dst]>;
const wchar_t **__restrict <[src]>;
size_t <[nwc]>;
size_t <[len]>;
mbstate_t *__restrict <[ps]>;
#include <wchar.h>
size_t _wcsnrtombs_r(<[ptr]>, <[dst]>, <[src]>, <[nwc]>, <[len]>, <[ps]>)
struct _rent *<[ptr]>;
char *<[dst]>;
const wchar_t **<[src]>;
size_t <[nwc]>;
size_t <[len]>;
mbstate_t *<[ps]>;
DESCRIPTION
The <<wcsrtombs>> function converts a string of wide characters indirectly
pointed to by <[src]> to a corresponding multibyte character string stored in
the array pointed to by <[dst]>. No more than <[len]> bytes are written to
<[dst]>.
If <[dst]> is NULL, no characters are stored.
If <[dst]> is not NULL, the pointer pointed to by <[src]> is updated to point
to the character after the one that conversion stopped at. If conversion
stops because a null character is encountered, *<[src]> is set to NULL.
The mbstate_t argument, <[ps]>, is used to keep track of the shift state. If
it is NULL, <<wcsrtombs>> uses an internal, static mbstate_t object, which
is initialized to the initial conversion state at program startup.
The <<wcsnrtombs>> function behaves identically to <<wcsrtombs>>, except that
conversion stops after reading at most <[nwc]> characters from the buffer
pointed to by <[src]>.
RETURNS
The <<wcsrtombs>> and <<wcsnrtombs>> functions return the number of bytes
stored in the array pointed to by <[dst]> (not including any terminating
null), if successful, otherwise it returns (size_t)-1.
PORTABILITY
<<wcsrtombs>> is defined by C99 standard.
<<wcsnrtombs>> is defined by the POSIX.1-2008 standard.
*/
#include <reent.h>
#include <newlib.h>
#include <wchar.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include "local.h"
size_t
_DEFUN (_wcsnrtombs_r, (r, dst, src, nwc, len, ps),
struct _reent *r _AND
char *dst _AND
const wchar_t **src _AND
size_t nwc _AND
size_t len _AND
mbstate_t *ps)
{
char *ptr = dst;
char buff[10];
wchar_t *pwcs;
size_t n;
int i;
#ifdef _MB_CAPABLE
if (ps == NULL)
{
_REENT_CHECK_MISC(r);
ps = &(_REENT_WCSRTOMBS_STATE(r));
}
#endif
/* If no dst pointer, treat len as maximum possible value. */
if (dst == NULL)
len = (size_t)-1;
n = 0;
pwcs = (wchar_t *)(*src);
while (n < len && nwc-- > 0)
{
int count = ps->__count;
wint_t wch = ps->__value.__wch;
int bytes = __wctomb (r, buff, *pwcs, __locale_charset (), ps);
if (bytes == -1)
{
r->_errno = EILSEQ;
ps->__count = 0;
return (size_t)-1;
}
if (n + bytes <= len)
{
n += bytes;
if (dst)
{
for (i = 0; i < bytes; ++i)
*ptr++ = buff[i];
++(*src);
}
if (*pwcs++ == 0x00)
{
if (dst)
*src = NULL;
ps->__count = 0;
return n - 1;
}
}
else
{
/* not enough room, we must back up state to before __wctomb call */
ps->__count = count;
ps->__value.__wch = wch;
len = 0;
}
}
return n;
}
#ifndef _REENT_ONLY
size_t
_DEFUN (wcsnrtombs, (dst, src, nwc, len, ps),
char *__restrict dst _AND
const wchar_t **__restrict src _AND
size_t nwc _AND
size_t len _AND
mbstate_t *__restrict ps)
{
return _wcsnrtombs_r (_REENT, dst, src, nwc, len, ps);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,28 @@
/* Doc in wcsnrtombs.c */
#include <reent.h>
#include <newlib.h>
#include <wchar.h>
size_t
_DEFUN (_wcsrtombs_r, (r, dst, src, len, ps),
struct _reent *r _AND
char *dst _AND
const wchar_t **src _AND
size_t len _AND
mbstate_t *ps)
{
return _wcsnrtombs_r (r, dst, src, (size_t) -1, len, ps);
}
#ifndef _REENT_ONLY
size_t
_DEFUN (wcsrtombs, (dst, src, len, ps),
char *__restrict dst _AND
const wchar_t **__restrict src _AND
size_t len _AND
mbstate_t *__restrict ps)
{
return _wcsnrtombs_r (_REENT, dst, src, (size_t) -1, len, ps);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,232 @@
/*
FUNCTION
<<wcstod>>, <<wcstof>>---wide char string to double or float
INDEX
wcstod
INDEX
_wcstod_r
INDEX
wcstof
INDEX
_wcstof_r
ANSI_SYNOPSIS
#include <stdlib.h>
double wcstod(const wchar_t *__restrict <[str]>,
wchar_t **__restrict <[tail]>);
float wcstof(const wchar_t *__restrict <[str]>,
wchar_t **__restrict <[tail]>);
double _wcstod_r(void *<[reent]>,
const wchar_t *<[str]>, wchar_t **<[tail]>);
float _wcstof_r(void *<[reent]>,
const wchar_t *<[str]>, wchar_t **<[tail]>);
TRAD_SYNOPSIS
#include <stdlib.h>
double wcstod(<[str]>,<[tail]>)
wchar_t *__restrict <[str]>;
wchar_t **__restrict <[tail]>;
float wcstof(<[str]>,<[tail]>)
wchar_t *__restrict <[str]>;
wchar_t **__restrict <[tail]>;
double _wcstod_r(<[reent]>,<[str]>,<[tail]>)
wchar_t *<[reent]>;
wchar_t *<[str]>;
wchar_t **<[tail]>;
float _wcstof_r(<[reent]>,<[str]>,<[tail]>)
wchar_t *<[reent]>;
wchar_t *<[str]>;
wchar_t **<[tail]>;
DESCRIPTION
The function <<wcstod>> parses the wide character string <[str]>,
producing a substring which can be converted to a double
value. The substring converted is the longest initial
subsequence of <[str]>, beginning with the first
non-whitespace character, that has one of these formats:
.[+|-]<[digits]>[.[<[digits]>]][(e|E)[+|-]<[digits]>]
.[+|-].<[digits]>[(e|E)[+|-]<[digits]>]
.[+|-](i|I)(n|N)(f|F)[(i|I)(n|N)(i|I)(t|T)(y|Y)]
.[+|-](n|N)(a|A)(n|N)[<(>[<[hexdigits]>]<)>]
.[+|-]0(x|X)<[hexdigits]>[.[<[hexdigits]>]][(p|P)[+|-]<[digits]>]
.[+|-]0(x|X).<[hexdigits]>[(p|P)[+|-]<[digits]>]
The substring contains no characters if <[str]> is empty, consists
entirely of whitespace, or if the first non-whitespace
character is something other than <<+>>, <<->>, <<.>>, or a
digit, and cannot be parsed as infinity or NaN. If the platform
does not support NaN, then NaN is treated as an empty substring.
If the substring is empty, no conversion is done, and
the value of <[str]> is stored in <<*<[tail]>>>. Otherwise,
the substring is converted, and a pointer to the final string
(which will contain at least the terminating null character of
<[str]>) is stored in <<*<[tail]>>>. If you want no
assignment to <<*<[tail]>>>, pass a null pointer as <[tail]>.
<<wcstof>> is identical to <<wcstod>> except for its return type.
This implementation returns the nearest machine number to the
input decimal string. Ties are broken by using the IEEE
round-even rule. However, <<wcstof>> is currently subject to
double rounding errors.
The alternate functions <<_wcstod_r>> and <<_wcstof_r>> are
reentrant versions of <<wcstod>> and <<wcstof>>, respectively.
The extra argument <[reent]> is a pointer to a reentrancy structure.
RETURNS
Return the converted substring value, if any. If
no conversion could be performed, 0 is returned. If the
correct value is out of the range of representable values,
plus or minus <<HUGE_VAL>> is returned, and <<ERANGE>> is
stored in errno. If the correct value would cause underflow, 0
is returned and <<ERANGE>> is stored in errno.
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
/*-
* 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 <errno.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
#include <locale.h>
#include <math.h>
double
_DEFUN (_wcstod_r, (ptr, nptr, endptr),
struct _reent *ptr _AND
_CONST wchar_t *nptr _AND
wchar_t **endptr)
{
static const mbstate_t initial;
mbstate_t mbs;
double val;
char *buf, *end;
const wchar_t *wcp;
size_t len;
while (iswspace(*nptr))
nptr++;
/*
* Convert the supplied numeric wide char. string to multibyte.
*
* We could attempt to find the end of the numeric portion of the
* wide char. string to avoid converting unneeded characters but
* choose not to bother; optimising the uncommon case where
* the input string contains a lot of text after the number
* duplicates a lot of strtod()'s functionality and slows down the
* most common cases.
*/
wcp = nptr;
mbs = initial;
if ((len = _wcsrtombs_r(ptr, NULL, &wcp, 0, &mbs)) == (size_t)-1) {
if (endptr != NULL)
*endptr = (wchar_t *)nptr;
return (0.0);
}
if ((buf = _malloc_r(ptr, len + 1)) == NULL)
return (0.0);
mbs = initial;
_wcsrtombs_r(ptr, buf, &wcp, len + 1, &mbs);
/* Let strtod() do most of the work for us. */
val = _strtod_r(ptr, buf, &end);
/*
* We only know where the number ended in the _multibyte_
* representation of the string. If the caller wants to know
* where it ended, count multibyte characters to find the
* corresponding position in the wide char string.
*/
if (endptr != NULL) {
/* The only valid multibyte char in a float converted by
strtod/wcstod is the radix char. What we do here is,
figure out if the radix char was in the valid leading
float sequence in the incoming string. If so, the
multibyte float string is strlen(radix char) - 1 bytes
longer than the incoming wide char string has characters.
To fix endptr, reposition end as if the radix char was
just one byte long. The resulting difference (end - buf)
is then equivalent to the number of valid wide characters
in the input string. */
len = strlen (_localeconv_r (ptr)->decimal_point);
if (len > 1) {
char *d = strstr (buf,
_localeconv_r (ptr)->decimal_point);
if (d && d < end)
end -= len - 1;
}
*endptr = (wchar_t *)nptr + (end - buf);
}
_free_r(ptr, buf);
return (val);
}
float
_DEFUN (_wcstof_r, (ptr, nptr, endptr),
struct _reent *ptr _AND
_CONST wchar_t *nptr _AND
wchar_t **endptr)
{
double retval = _wcstod_r (ptr, nptr, endptr);
if (isnan (retval))
return nanf (NULL);
return (float)retval;
}
#ifndef _REENT_ONLY
double
_DEFUN (wcstod, (nptr, endptr),
_CONST wchar_t *__restrict nptr _AND wchar_t **__restrict endptr)
{
return _wcstod_r (_REENT, nptr, endptr);
}
float
_DEFUN (wcstof, (nptr, endptr),
_CONST wchar_t *__restrict nptr _AND
wchar_t **__restrict endptr)
{
double retval = _wcstod_r (_REENT, nptr, endptr);
if (isnan (retval))
return nanf (NULL);
return (float)retval;
}
#endif

View File

@ -0,0 +1,227 @@
/*
FUNCTION
<<wcstol>>---wide string to long
INDEX
wcstol
INDEX
_wcstol_r
ANSI_SYNOPSIS
#include <wchar.h>
long wcstol(const wchar_t *__restrict <[s]>,
wchar_t **__restrict <[ptr]>,int <[base]>);
long _wcstol_r(void *<[reent]>,
const wchar_t *<[s]>, wchar_t **<[ptr]>,int <[base]>);
TRAD_SYNOPSIS
#include <stdlib.h>
long wcstol (<[s]>, <[ptr]>, <[base]>)
wchar_t *__restrict <[s]>;
wchar_t **__restrict <[ptr]>;
int <[base]>;
long _wcstol_r (<[reent]>, <[s]>, <[ptr]>, <[base]>)
struct _reent *<[reent]>;
wchar_t *<[s]>;
wchar_t **<[ptr]>;
int <[base]>;
DESCRIPTION
The function <<wcstol>> converts the wide string <<*<[s]>>> to
a <<long>>. First, it breaks down the string into three parts:
leading whitespace, which is ignored; a subject string consisting
of characters resembling an integer in the radix specified by <[base]>;
and a trailing portion consisting of zero or more unparseable characters,
and always including the terminating null character. Then, it attempts
to convert the subject string into a <<long>> and returns the
result.
If the value of <[base]> is 0, the subject string is expected to look
like a normal C integer constant: an optional sign, a possible `<<0x>>'
indicating a hexadecimal base, and a number. If <[base]> is between
2 and 36, the expected form of the subject is a sequence of letters
and digits representing an integer in the radix specified by <[base]>,
with an optional plus or minus sign. The letters <<a>>--<<z>> (or,
equivalently, <<A>>--<<Z>>) are used to signify values from 10 to 35;
only letters whose ascribed values are less than <[base]> are
permitted. If <[base]> is 16, a leading <<0x>> is permitted.
The subject sequence is the longest initial sequence of the input
string that has the expected form, starting with the first
non-whitespace character. If the string is empty or consists entirely
of whitespace, or if the first non-whitespace character is not a
permissible letter or digit, the subject string is empty.
If the subject string is acceptable, and the value of <[base]> is zero,
<<wcstol>> attempts to determine the radix from the input string. A
string with a leading <<0x>> is treated as a hexadecimal value; a string with
a leading 0 and no <<x>> is treated as octal; all other strings are
treated as decimal. If <[base]> is between 2 and 36, it is used as the
conversion radix, as described above. If the subject string begins with
a minus sign, the value is negated. Finally, a pointer to the first
character past the converted subject string is stored in <[ptr]>, if
<[ptr]> is not <<NULL>>.
If the subject string is empty (or not in acceptable form), no conversion
is performed and the value of <[s]> is stored in <[ptr]> (if <[ptr]> is
not <<NULL>>).
The alternate function <<_wcstol_r>> is a reentrant version. The
extra argument <[reent]> is a pointer to a reentrancy structure.
RETURNS
<<wcstol>> returns the converted value, if any. If no conversion was
made, 0 is returned.
<<wcstol>> returns <<LONG_MAX>> or <<LONG_MIN>> if the magnitude of
the converted value is too large, and sets <<errno>> to <<ERANGE>>.
PORTABILITY
<<wcstol>> is ANSI.
No supporting OS subroutines are required.
*/
/*-
* Copyright (c) 1990 The Regents of the University of California.
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <_ansi.h>
#include <limits.h>
#include <wctype.h>
#include <errno.h>
#include <wchar.h>
#include <reent.h>
/*
* Convert a wide string to a long integer.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
long
_DEFUN (_wcstol_r, (rptr, nptr, endptr, base),
struct _reent *rptr _AND
_CONST wchar_t *nptr _AND
wchar_t **endptr _AND
int base)
{
register const wchar_t *s = nptr;
register unsigned long acc;
register int c;
register unsigned long cutoff;
register int neg = 0, any, cutlim;
/*
* Skip white space and pick up leading +/- sign if any.
* If base is 0, allow 0x for hex and 0 for octal, else
* assume decimal; if base is already 16, allow 0x.
*/
do {
c = *s++;
} while (iswspace(c));
if (c == L'-') {
neg = 1;
c = *s++;
} else if (c == L'+')
c = *s++;
if ((base == 0 || base == 16) &&
c == L'0' && (*s == L'x' || *s == L'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == L'0' ? 8 : 10;
/*
* Compute the cutoff value between legal numbers and illegal
* numbers. That is the largest legal value, divided by the
* base. An input number that is greater than this value, if
* followed by a legal input character, is too big. One that
* is equal to this value may be valid or not; the limit
* between valid and invalid numbers is then based on the last
* digit. For instance, if the range for longs is
* [-2147483648..2147483647] and the input base is 10,
* cutoff will be set to 214748364 and cutlim to either
* 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
* a value > 214748364, or equal but the next digit is > 7 (or 8),
* the number is too big, and we will return a range error.
*
* Set any if any `digits' consumed; make it negative to indicate
* overflow.
*/
cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
cutlim = cutoff % (unsigned long)base;
cutoff /= (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) {
if (iswdigit(c))
c -= L'0';
else if (iswalpha(c))
c -= iswupper(c) ? L'A' - 10 : L'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else {
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0) {
acc = neg ? LONG_MIN : LONG_MAX;
rptr->_errno = ERANGE;
} else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = (wchar_t *) (any ? s - 1 : nptr);
return (acc);
}
#ifndef _REENT_ONLY
long
_DEFUN (wcstol, (s, ptr, base),
_CONST wchar_t *__restrict s _AND
wchar_t **__restrict ptr _AND
int base)
{
return _wcstol_r (_REENT, s, ptr, base);
}
#endif

View File

@ -0,0 +1,108 @@
/*
(C) Copyright IBM Corp. 2009
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of IBM nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 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 <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <wctype.h>
#include <locale.h>
#include "local.h"
long double
wcstold (const wchar_t *__restrict nptr, wchar_t **__restrict endptr)
{
#ifdef _LDBL_EQ_DBL
/* On platforms where long double is as wide as double. */
return wcstod(nptr, endptr);
#else /* This is a duplicate of the code in wcstod.c, but converted to long double. */
static const mbstate_t initial;
mbstate_t mbs;
long double val;
char *buf, *end;
const wchar_t *wcp;
size_t len;
while (iswspace (*nptr))
nptr++;
/* Convert the supplied numeric wide char string to multibyte. */
wcp = nptr;
mbs = initial;
if ((len = wcsrtombs (NULL, &wcp, 0, &mbs)) == (size_t)-1)
{
if (endptr != NULL)
*endptr = (wchar_t *) nptr;
return 0.0L;
}
if ((buf = malloc (len + 1)) == NULL)
return 0.0L;
mbs = initial;
wcsrtombs (buf, &wcp, len + 1, &mbs);
val = strtold (buf, &end);
/* We only know where the number ended in the _multibyte_
representation of the string. If the caller wants to know
where it ended, count multibyte characters to find the
corresponding position in the wide char string. */
if (endptr != NULL)
{
/* The only valid multibyte char in a float converted by
strtold/wcstold is the radix char. What we do here is,
figure out if the radix char was in the valid leading
float sequence in the incoming string. If so, the
multibyte float string is strlen (radix char) - 1 bytes
longer than the incoming wide char string has characters.
To fix endptr, reposition end as if the radix char was
just one byte long. The resulting difference (end - buf)
is then equivalent to the number of valid wide characters
in the input string. */
len = strlen (localeconv ()->decimal_point);
if (len > 1)
{
char *d = strstr (buf, localeconv ()->decimal_point);
if (d && d < end)
end -= len - 1;
}
*endptr = (wchar_t *) nptr + (end - buf);
}
free (buf);
return val;
#endif /* _LDBL_EQ_DBL */
}

View File

@ -0,0 +1,139 @@
/*
FUNCTION
<<wcstoll>>---wide string to long long
INDEX
wcstoll
INDEX
_wcstoll_r
ANSI_SYNOPSIS
#include <wchar.h>
long long wcstoll(const wchar_t *__restrict <[s]>,
wchar_t **__restrict <[ptr]>,int <[base]>);
long long _wcstoll_r(void *<[reent]>,
const wchar_t *<[s]>, wchar_t **<[ptr]>,int <[base]>);
TRAD_SYNOPSIS
#include <stdlib.h>
long long wcstoll (<[s]>, <[ptr]>, <[base]>)
const wchar_t *__restrict <[s]>;
wchar_t **__restrict <[ptr]>;
int <[base]>;
long long _wcstoll_r (<[reent]>, <[s]>, <[ptr]>, <[base]>)
wchar_t *<[reent]>;
const wchar_t *<[s]>;
wchar_t **<[ptr]>;
int <[base]>;
DESCRIPTION
The function <<wcstoll>> converts the wide string <<*<[s]>>> to
a <<long long>>. First, it breaks down the string into three parts:
leading whitespace, which is ignored; a subject string consisting
of characters resembling an integer in the radix specified by <[base]>;
and a trailing portion consisting of zero or more unparseable characters,
and always including the terminating null character. Then, it attempts
to convert the subject string into a <<long long>> and returns the
result.
If the value of <[base]> is 0, the subject string is expected to look
like a normal C integer constant: an optional sign, a possible `<<0x>>'
indicating a hexadecimal base, and a number. If <[base]> is between
2 and 36, the expected form of the subject is a sequence of letters
and digits representing an integer in the radix specified by <[base]>,
with an optional plus or minus sign. The letters <<a>>--<<z>> (or,
equivalently, <<A>>--<<Z>>) are used to signify values from 10 to 35;
only letters whose ascribed values are less than <[base]> are
permitted. If <[base]> is 16, a leading <<0x>> is permitted.
The subject sequence is the longest initial sequence of the input
string that has the expected form, starting with the first
non-whitespace character. If the string is empty or consists entirely
of whitespace, or if the first non-whitespace character is not a
permissible letter or digit, the subject string is empty.
If the subject string is acceptable, and the value of <[base]> is zero,
<<wcstoll>> attempts to determine the radix from the input string. A
string with a leading <<0x>> is treated as a hexadecimal value; a string with
a leading 0 and no <<x>> is treated as octal; all other strings are
treated as decimal. If <[base]> is between 2 and 36, it is used as the
conversion radix, as described above. If the subject string begins with
a minus sign, the value is negated. Finally, a pointer to the first
character past the converted subject string is stored in <[ptr]>, if
<[ptr]> is not <<NULL>>.
If the subject string is empty (or not in acceptable form), no conversion
is performed and the value of <[s]> is stored in <[ptr]> (if <[ptr]> is
not <<NULL>>).
The alternate function <<_wcstoll_r>> is a reentrant version. The
extra argument <[reent]> is a pointer to a reentrancy structure.
RETURNS
<<wcstoll>> returns the converted value, if any. If no conversion was
made, 0 is returned.
<<wcstoll>> returns <<LONG_LONG_MAX>> or <<LONG_LONG_MIN>> if the magnitude of
the converted value is too large, and sets <<errno>> to <<ERANGE>>.
PORTABILITY
<<wcstoll>> is ANSI.
No supporting OS subroutines are required.
*/
/*-
* Copyright (c) 1990 The Regents of the University of California.
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <_ansi.h>
#include <limits.h>
#include <wctype.h>
#include <errno.h>
#include <wchar.h>
#include <reent.h>
#ifndef _REENT_ONLY
long long
_DEFUN (wcstoll, (s, ptr, base),
_CONST wchar_t *__restrict s _AND
wchar_t **__restrict ptr _AND
int base)
{
return _wcstoll_r (_REENT, s, ptr, base);
}
#endif

View File

@ -0,0 +1,140 @@
/*
This code is based on strtoul.c which has the following copyright.
It is used to convert a wide string into a signed long long.
long long _wcstoll_r (struct _reent *rptr, const wchar_t *s,
wchar_t **ptr, int base);
*/
/*-
* Copyright (c) 1990 The Regents of the University of California.
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef __GNUC__
#define _GNU_SOURCE
#include <_ansi.h>
#include <limits.h>
#include <wctype.h>
#include <errno.h>
#include <wchar.h>
#include <reent.h>
/*
* Convert a wide string to a long long integer.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
long long
_DEFUN (_wcstoll_r, (rptr, nptr, endptr, base),
struct _reent *rptr _AND
_CONST wchar_t *nptr _AND
wchar_t **endptr _AND
int base)
{
register const wchar_t *s = nptr;
register unsigned long long acc;
register int c;
register unsigned long long cutoff;
register int neg = 0, any, cutlim;
/*
* Skip white space and pick up leading +/- sign if any.
* If base is 0, allow 0x for hex and 0 for octal, else
* assume decimal; if base is already 16, allow 0x.
*/
do {
c = *s++;
} while (iswspace(c));
if (c == L'-') {
neg = 1;
c = *s++;
} else if (c == L'+')
c = *s++;
if ((base == 0 || base == 16) &&
c == L'0' && (*s == L'x' || *s == L'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == L'0' ? 8 : 10;
/*
* Compute the cutoff value between legal numbers and illegal
* numbers. That is the largest legal value, divided by the
* base. An input number that is greater than this value, if
* followed by a legal input character, is too big. One that
* is equal to this value may be valid or not; the limit
* between valid and invalid numbers is then based on the last
* digit. For instance, if the range for longs is
* [-2147483648..2147483647] and the input base is 10,
* cutoff will be set to 214748364 and cutlim to either
* 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
* a value > 214748364, or equal but the next digit is > 7 (or 8),
* the number is too big, and we will return a range error.
*
* Set any if any `digits' consumed; make it negative to indicate
* overflow.
*/
cutoff = neg ? -(unsigned long long)LONG_LONG_MIN : LONG_LONG_MAX;
cutlim = cutoff % (unsigned long long)base;
cutoff /= (unsigned long long)base;
for (acc = 0, any = 0;; c = *s++) {
if (iswdigit(c))
c -= L'0';
else if (iswalpha(c))
c -= iswupper(c) ? L'A' - 10 : L'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else {
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0) {
acc = neg ? LONG_LONG_MIN : LONG_LONG_MAX;
rptr->_errno = ERANGE;
} else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = (wchar_t *) (any ? s - 1 : nptr);
return (acc);
}
#endif /* __GNUC__ */

View File

@ -0,0 +1,83 @@
/*
FUNCTION
<<wcstombs>>---minimal wide char string to multibyte string converter
INDEX
wcstombs
ANSI_SYNOPSIS
#include <stdlib.h>
size_t wcstombs(char *restrict <[s]>, const wchar_t *restrict <[pwc]>, size_t <[n]>);
TRAD_SYNOPSIS
#include <stdlib.h>
size_t wcstombs(<[s]>, <[pwc]>, <[n]>)
char *<[s]>;
const wchar_t *<[pwc]>;
size_t <[n]>;
DESCRIPTION
When _MB_CAPABLE is not defined, this is a minimal ANSI-conforming
implementation of <<wcstombs>>. In this case,
all wide-characters are expected to represent single bytes and so
are converted simply by casting to char.
When _MB_CAPABLE is defined, this routine calls <<_wcstombs_r>> to perform
the conversion, passing a state variable to allow state dependent
decoding. The result is based on the locale setting which may
be restricted to a defined set of locales.
RETURNS
This implementation of <<wcstombs>> returns <<0>> if
<[s]> is <<NULL>> or is the empty string;
it returns <<-1>> if _MB_CAPABLE and one of the
wide-char characters does not represent a valid multi-byte character;
otherwise it returns the minimum of: <<n>> or the
number of bytes that are transferred to <<s>>, not including the
nul terminator.
If the return value is -1, the state of the <<pwc>> string is
indeterminate. If the input has a length of 0, the output
string will be modified to contain a wchar_t nul terminator if
<<n>> > 0.
PORTABILITY
<<wcstombs>> is required in the ANSI C standard. However, the precise
effects vary with the locale.
<<wcstombs>> requires no supporting OS subroutines.
*/
#ifndef _REENT_ONLY
#include <newlib.h>
#include <stdlib.h>
#include <wchar.h>
size_t
_DEFUN (wcstombs, (s, pwcs, n),
char *__restrict s _AND
const wchar_t *__restrict pwcs _AND
size_t n)
{
#ifdef _MB_CAPABLE
mbstate_t state;
state.__count = 0;
return _wcstombs_r (_REENT, s, pwcs, n, &state);
#else /* not _MB_CAPABLE */
int count = 0;
if (n != 0) {
do {
if ((*s++ = (char) *pwcs++) == 0)
break;
count++;
} while (--n != 0);
}
return count;
#endif /* not _MB_CAPABLE */
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,48 @@
#include <stdlib.h>
#include <wchar.h>
#include "local.h"
size_t
_DEFUN (_wcstombs_r, (reent, s, pwcs, n, state),
struct _reent *r _AND
char *__restrict s _AND
const wchar_t *__restrict pwcs _AND
size_t n _AND
mbstate_t *state)
{
char *ptr = s;
size_t max = n;
char buff[8];
int i, bytes, num_to_copy;
if (s == NULL)
{
size_t num_bytes = 0;
while (*pwcs != 0)
{
bytes = __wctomb (r, buff, *pwcs++, __locale_charset (), state);
if (bytes == -1)
return -1;
num_bytes += bytes;
}
return num_bytes;
}
else
{
while (n > 0)
{
bytes = __wctomb (r, buff, *pwcs, __locale_charset (), state);
if (bytes == -1)
return -1;
num_to_copy = (n > bytes ? bytes : (int)n);
for (i = 0; i < num_to_copy; ++i)
*ptr++ = buff[i];
if (*pwcs == 0x00)
return ptr - s - (n >= bytes);
++pwcs;
n -= num_to_copy;
}
return max;
}
}

View File

@ -0,0 +1,207 @@
/*
FUNCTION
<<wcstoul>>---wide string to unsigned long
INDEX
wcstoul
INDEX
_wcstoul_r
ANSI_SYNOPSIS
#include <wchar.h>
unsigned long wcstoul(const wchar_t *__restrict <[s]>,
wchar_t **__restrict <[ptr]>, int <[base]>);
unsigned long _wcstoul_r(void *<[reent]>, const wchar_t *<[s]>,
wchar_t **<[ptr]>, int <[base]>);
TRAD_SYNOPSIS
#include <wchar.h>
unsigned long wcstoul(<[s]>, <[ptr]>, <[base]>)
wchar_t *__restrict <[s]>;
wchar_t **__restrict <[ptr]>;
int <[base]>;
unsigned long _wcstoul_r(<[reent]>, <[s]>, <[ptr]>, <[base]>)
wchar_t *<[reent]>;
wchar_t *<[s]>;
wchar_t **<[ptr]>;
int <[base]>;
DESCRIPTION
The function <<wcstoul>> converts the wide string <<*<[s]>>> to
an <<unsigned long>>. First, it breaks down the string into three parts:
leading whitespace, which is ignored; a subject string consisting
of the digits meaningful in the radix specified by <[base]>
(for example, <<0>> through <<7>> if the value of <[base]> is 8);
and a trailing portion consisting of one or more unparseable characters,
which always includes the terminating null character. Then, it attempts
to convert the subject string into an unsigned long integer, and returns the
result.
If the value of <[base]> is zero, the subject string is expected to look
like a normal C integer constant (save that no optional sign is permitted):
a possible <<0x>> indicating hexadecimal radix, and a number.
If <[base]> is between 2 and 36, the expected form of the subject is a
sequence of digits (which may include letters, depending on the
base) representing an integer in the radix specified by <[base]>.
The letters <<a>>--<<z>> (or <<A>>--<<Z>>) are used as digits valued from
10 to 35. If <[base]> is 16, a leading <<0x>> is permitted.
The subject sequence is the longest initial sequence of the input
string that has the expected form, starting with the first
non-whitespace character. If the string is empty or consists entirely
of whitespace, or if the first non-whitespace character is not a
permissible digit, the subject string is empty.
If the subject string is acceptable, and the value of <[base]> is zero,
<<wcstoul>> attempts to determine the radix from the input string. A
string with a leading <<0x>> is treated as a hexadecimal value; a string with
a leading <<0>> and no <<x>> is treated as octal; all other strings are
treated as decimal. If <[base]> is between 2 and 36, it is used as the
conversion radix, as described above. Finally, a pointer to the first
character past the converted subject string is stored in <[ptr]>, if
<[ptr]> is not <<NULL>>.
If the subject string is empty (that is, if <<*>><[s]> does not start
with a substring in acceptable form), no conversion
is performed and the value of <[s]> is stored in <[ptr]> (if <[ptr]> is
not <<NULL>>).
The alternate function <<_wcstoul_r>> is a reentrant version. The
extra argument <[reent]> is a pointer to a reentrancy structure.
RETURNS
<<wcstoul>> returns the converted value, if any. If no conversion was
made, <<0>> is returned.
<<wcstoul>> returns <<ULONG_MAX>> if the magnitude of the converted
value is too large, and sets <<errno>> to <<ERANGE>>.
PORTABILITY
<<wcstoul>> is ANSI.
<<wcstoul>> requires no supporting OS subroutines.
*/
/*
* Copyright (c) 1990 Regents of the University of California.
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <_ansi.h>
#include <limits.h>
#include <wctype.h>
#include <wchar.h>
#include <errno.h>
#include <stdlib.h>
#include <reent.h>
/*
* Convert a wide string to an unsigned long integer.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
unsigned long
_DEFUN (_wcstoul_r, (rptr, nptr, endptr, base),
struct _reent *rptr _AND
_CONST wchar_t *nptr _AND
wchar_t **endptr _AND
int base)
{
register const wchar_t *s = nptr;
register unsigned long acc;
register int c;
register unsigned long cutoff;
register int neg = 0, any, cutlim;
/*
* See strtol for comments as to the logic used.
*/
do {
c = *s++;
} while (iswspace(c));
if (c == L'-') {
neg = 1;
c = *s++;
} else if (c == L'+')
c = *s++;
if ((base == 0 || base == 16) &&
c == L'0' && (*s == L'x' || *s == L'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == L'0' ? 8 : 10;
cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) {
if (iswdigit(c))
c -= L'0';
else if (iswalpha(c))
c -= iswupper(c) ? L'A' - 10 : L'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else {
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0) {
acc = ULONG_MAX;
rptr->_errno = ERANGE;
} else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = (wchar_t *) (any ? s - 1 : nptr);
return (acc);
}
#ifndef _REENT_ONLY
unsigned long
_DEFUN (wcstoul, (s, ptr, base),
_CONST wchar_t *__restrict s _AND
wchar_t **__restrict ptr _AND
int base)
{
return _wcstoul_r (_REENT, s, ptr, base);
}
#endif

View File

@ -0,0 +1,140 @@
/*
FUNCTION
<<wcstoull>>---wide string to unsigned long long
INDEX
wcstoull
INDEX
_wcstoull_r
ANSI_SYNOPSIS
#include <wchar.h>
unsigned long long wcstoull(const wchar_t *__restrict <[s]>,
wchar_t **__restrict <[ptr]>, int <[base]>);
unsigned long long _wcstoull_r(void *<[reent]>, const wchar_t *<[s]>,
wchar_t **<[ptr]>, int <[base]>);
TRAD_SYNOPSIS
#include <wchar.h>
unsigned long long wcstoull(<[s]>, <[ptr]>, <[base]>)
wchar_t *__restrict <[s]>;
wchar_t **__restrict <[ptr]>;
int <[base]>;
unsigned long long _wcstoull_r(<[reent]>, <[s]>, <[ptr]>, <[base]>)
wchar_t *<[reent]>;
wchar_t *<[s]>;
wchar_t **<[ptr]>;
int <[base]>;
DESCRIPTION
The function <<wcstoull>> converts the wide string <<*<[s]>>> to
an <<unsigned long long>>. First, it breaks down the string into three parts:
leading whitespace, which is ignored; a subject string consisting
of the digits meaningful in the radix specified by <[base]>
(for example, <<0>> through <<7>> if the value of <[base]> is 8);
and a trailing portion consisting of one or more unparseable characters,
which always includes the terminating null character. Then, it attempts
to convert the subject string into an unsigned long long integer, and returns the
result.
If the value of <[base]> is zero, the subject string is expected to look
like a normal C integer constant: an optional sign (<<+>> or <<->>),
a possible <<0x>> indicating hexadecimal radix or a possible <0> indicating
octal radix, and a number.
If <[base]> is between 2 and 36, the expected form of the subject is a
sequence of digits (which may include letters, depending on the
base) representing an integer in the radix specified by <[base]>.
The letters <<a>>--<<z>> (or <<A>>--<<Z>>) are used as digits valued from
10 to 35. If <[base]> is 16, a leading <<0x>> is permitted.
The subject sequence is the longest initial sequence of the input
string that has the expected form, starting with the first
non-whitespace character. If the string is empty or consists entirely
of whitespace, or if the first non-whitespace character is not a
permissible digit, the subject string is empty.
If the subject string is acceptable, and the value of <[base]> is zero,
<<wcstoull>> attempts to determine the radix from the input string. A
string with a leading <<0x>> is treated as a hexadecimal value; a string with
a leading <<0>> and no <<x>> is treated as octal; all other strings are
treated as decimal. If <[base]> is between 2 and 36, it is used as the
conversion radix, as described above. Finally, a pointer to the first
character past the converted subject string is stored in <[ptr]>, if
<[ptr]> is not <<NULL>>.
If the subject string is empty (that is, if <<*>><[s]> does not start
with a substring in acceptable form), no conversion
is performed and the value of <[s]> is stored in <[ptr]> (if <[ptr]> is
not <<NULL>>).
The alternate function <<_wcstoull_r>> is a reentrant version. The
extra argument <[reent]> is a pointer to a reentrancy structure.
RETURNS
<<wcstoull>> returns <<0>> and sets <<errno>> to <<EINVAL>> if the value of
<[base]> is not supported.
<<wcstoull>> returns the converted value, if any. If no conversion was
made, <<0>> is returned.
<<wcstoull>> returns <<ULLONG_MAX>> if the magnitude of the converted
value is too large, and sets <<errno>> to <<ERANGE>>.
PORTABILITY
<<wcstoull>> is ANSI.
<<wcstoull>> requires no supporting OS subroutines.
*/
/*
* Copyright (c) 1990 Regents of the University of California.
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <_ansi.h>
#include <wchar.h>
#include <reent.h>
#ifndef _REENT_ONLY
unsigned long long
_DEFUN (wcstoull, (s, ptr, base),
_CONST wchar_t *__restrict s _AND
wchar_t **__restrict ptr _AND
int base)
{
return _wcstoull_r (_REENT, s, ptr, base);
}
#endif

View File

@ -0,0 +1,130 @@
/*
This code is based on wcstoul.c which has the following copyright.
It is used to convert a wide string into an unsigned long long.
unsigned long long _wcstoull_r (struct _reent *rptr, const wchar_t *s,
wchar_t **ptr, int base);
*/
/*
* Copyright (c) 1990 Regents of the University of California.
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef __GNUC__
#define _GNU_SOURCE
#include <_ansi.h>
#include <limits.h>
#include <wchar.h>
#include <wctype.h>
#include <errno.h>
#include <reent.h>
/* Make up for older non-compliant limits.h. (This is a C99/POSIX function,
* and both require ULLONG_MAX in limits.h.) */
#if !defined(ULLONG_MAX)
# define ULLONG_MAX ULONG_LONG_MAX
#endif
/*
* Convert a wide string to an unsigned long long integer.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
unsigned long long
_DEFUN (_wcstoull_r, (rptr, nptr, endptr, base),
struct _reent *rptr _AND
_CONST wchar_t *nptr _AND
wchar_t **endptr _AND
int base)
{
register const wchar_t *s = nptr;
register unsigned long long acc;
register int c;
register unsigned long long cutoff;
register int neg = 0, any, cutlim;
if(base < 0 || base == 1 || base > 36) {
rptr->_errno = EINVAL;
return(0ULL);
}
/*
* See strtol for comments as to the logic used.
*/
do {
c = *s++;
} while (iswspace(c));
if (c == L'-') {
neg = 1;
c = *s++;
} else if (c == L'+')
c = *s++;
if ((base == 0 || base == 16) &&
c == L'0' && (*s == L'x' || *s == L'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == L'0' ? 8 : 10;
cutoff = (unsigned long long)ULLONG_MAX / (unsigned long long)base;
cutlim = (unsigned long long)ULLONG_MAX % (unsigned long long)base;
for (acc = 0, any = 0;; c = *s++) {
if (iswdigit(c))
c -= L'0';
else if (iswalpha(c))
c -= iswupper(c) ? L'A' - 10 : L'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
any = -1;
else {
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0) {
acc = ULLONG_MAX;
rptr->_errno = ERANGE;
} else if (neg)
acc = -acc;
if (endptr != 0)
*endptr = (wchar_t *) (any ? s - 1 : nptr);
return (acc);
}
#endif /* __GNUC__ */

View File

@ -0,0 +1,26 @@
#include <reent.h>
#include <wchar.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "local.h"
int
wctob (wint_t wc)
{
struct _reent *reent;
mbstate_t mbs;
unsigned char pmb[MB_LEN_MAX];
if (wc == WEOF)
return EOF;
/* Put mbs in initial state. */
memset (&mbs, '\0', sizeof (mbs));
reent = _REENT;
_REENT_CHECK_MISC(reent);
return __wctomb (reent, (char *) pmb, wc, __locale_charset (), &mbs) == 1
? (int) pmb[0] : EOF;
}

View File

@ -0,0 +1,81 @@
/*
FUNCTION
<<wctomb>>---minimal wide char to multibyte converter
INDEX
wctomb
ANSI_SYNOPSIS
#include <stdlib.h>
int wctomb(char *<[s]>, wchar_t <[wchar]>);
TRAD_SYNOPSIS
#include <stdlib.h>
int wctomb(<[s]>, <[wchar]>)
char *<[s]>;
wchar_t <[wchar]>;
DESCRIPTION
When _MB_CAPABLE is not defined, this is a minimal ANSI-conforming
implementation of <<wctomb>>. The
only ``wide characters'' recognized are single bytes,
and they are ``converted'' to themselves.
When _MB_CAPABLE is defined, this routine calls <<_wctomb_r>> to perform
the conversion, passing a state variable to allow state dependent
decoding. The result is based on the locale setting which may
be restricted to a defined set of locales.
Each call to <<wctomb>> modifies <<*<[s]>>> unless <[s]> is a null
pointer or _MB_CAPABLE is defined and <[wchar]> is invalid.
RETURNS
This implementation of <<wctomb>> returns <<0>> if
<[s]> is <<NULL>>; it returns <<-1>> if _MB_CAPABLE is enabled
and the wchar is not a valid multi-byte character, it returns <<1>>
if _MB_CAPABLE is not defined or the wchar is in reality a single
byte character, otherwise it returns the number of bytes in the
multi-byte character.
PORTABILITY
<<wctomb>> is required in the ANSI C standard. However, the precise
effects vary with the locale.
<<wctomb>> requires no supporting OS subroutines.
*/
#ifndef _REENT_ONLY
#include <newlib.h>
#include <stdlib.h>
#include <errno.h>
#include "local.h"
int
_DEFUN (wctomb, (s, wchar),
char *s _AND
wchar_t wchar)
{
#ifdef _MB_CAPABLE
struct _reent *reent = _REENT;
_REENT_CHECK_MISC(reent);
return __wctomb (reent, s, wchar, __locale_charset (),
&(_REENT_WCTOMB_STATE(reent)));
#else /* not _MB_CAPABLE */
if (s == NULL)
return 0;
/* Verify that wchar is a valid single-byte character. */
if ((size_t)wchar >= 0x100) {
errno = EILSEQ;
return -1;
}
*s = (char) wchar;
return 1;
#endif /* not _MB_CAPABLE */
}
#endif /* !_REENT_ONLY */