newlib: wide char support
git-svn-id: svn://kolibrios.org@6607 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
33
contrib/sdk/sources/newlib/libc/stdlib/btowc.c
Normal file
33
contrib/sdk/sources/newlib/libc/stdlib/btowc.c
Normal 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;
|
||||
}
|
3868
contrib/sdk/sources/newlib/libc/stdlib/ldtoa.c
Normal file
3868
contrib/sdk/sources/newlib/libc/stdlib/ldtoa.c
Normal file
File diff suppressed because it is too large
Load Diff
81
contrib/sdk/sources/newlib/libc/stdlib/mblen.c
Normal file
81
contrib/sdk/sources/newlib/libc/stdlib/mblen.c
Normal 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 */
|
77
contrib/sdk/sources/newlib/libc/stdlib/mblen_r.c
Normal file
77
contrib/sdk/sources/newlib/libc/stdlib/mblen_r.c
Normal 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 */
|
||||
}
|
||||
|
22
contrib/sdk/sources/newlib/libc/stdlib/mbrlen.c
Normal file
22
contrib/sdk/sources/newlib/libc/stdlib/mbrlen.c
Normal 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);
|
||||
}
|
14
contrib/sdk/sources/newlib/libc/stdlib/mbsinit.c
Normal file
14
contrib/sdk/sources/newlib/libc/stdlib/mbsinit.c
Normal 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;
|
||||
}
|
182
contrib/sdk/sources/newlib/libc/stdlib/mbsnrtowcs.c
Normal file
182
contrib/sdk/sources/newlib/libc/stdlib/mbsnrtowcs.c
Normal 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 */
|
31
contrib/sdk/sources/newlib/libc/stdlib/mbsrtowcs.c
Normal file
31
contrib/sdk/sources/newlib/libc/stdlib/mbsrtowcs.c
Normal 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 */
|
83
contrib/sdk/sources/newlib/libc/stdlib/mbstowcs.c
Normal file
83
contrib/sdk/sources/newlib/libc/stdlib/mbstowcs.c
Normal 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 */
|
38
contrib/sdk/sources/newlib/libc/stdlib/mbstowcs_r.c
Normal file
38
contrib/sdk/sources/newlib/libc/stdlib/mbstowcs_r.c
Normal 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;
|
||||
}
|
@@ -1,96 +1,96 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<mbtowc>>---minimal multibyte to wide char converter
|
||||
|
||||
INDEX
|
||||
mbtowc
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
int mbtowc(wchar_t *restrict <[pwc]>, const char *restrict <[s]>, size_t <[n]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
int mbtowc(<[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 <<mbtowc>>. In this case,
|
||||
only ``multi-byte character sequences'' recognized are single bytes,
|
||||
and they are ``converted'' to themselves.
|
||||
Each call to <<mbtowc>> copies one character from <<*<[s]>>> to
|
||||
<<*<[pwc]>>>, unless <[s]> is a null pointer. The argument n
|
||||
is ignored.
|
||||
|
||||
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 <<mbtowc>> returns <<0>> if
|
||||
<[s]> is <<NULL>> or is the empty string;
|
||||
it returns <<1>> if not _MB_CAPABLE or
|
||||
the character is a single-byte character; it returns <<-1>>
|
||||
if n is <<0>> or the multi-byte character is invalid;
|
||||
otherwise it returns the number of bytes in the multibyte character.
|
||||
If the return value is -1, no changes are made to the <<pwc>>
|
||||
output string. If the input is the empty string, a wchar_t nul
|
||||
is placed in the output string and 0 is returned. If the input
|
||||
has a length of 0, no changes are made to the <<pwc>> output string.
|
||||
|
||||
PORTABILITY
|
||||
<<mbtowc>> is required in the ANSI C standard. However, the precise
|
||||
effects vary with the locale.
|
||||
|
||||
<<mbtowc>> requires no supporting OS subroutines.
|
||||
*/
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
#include <newlib.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include "local.h"
|
||||
|
||||
int
|
||||
_DEFUN (mbtowc, (pwc, s, n),
|
||||
wchar_t *__restrict pwc _AND
|
||||
const char *__restrict s _AND
|
||||
size_t n)
|
||||
{
|
||||
#ifdef _MB_CAPABLE
|
||||
int retval = 0;
|
||||
struct _reent *reent = _REENT;
|
||||
mbstate_t *ps;
|
||||
|
||||
_REENT_CHECK_MISC(reent);
|
||||
ps = &(_REENT_MBTOWC_STATE(reent));
|
||||
|
||||
retval = __mbtowc (reent, pwc, s, n, __locale_charset (), ps);
|
||||
|
||||
if (retval < 0)
|
||||
{
|
||||
ps->__count = 0;
|
||||
return -1;
|
||||
}
|
||||
return retval;
|
||||
#else /* not _MB_CAPABLE */
|
||||
if (s == NULL)
|
||||
return 0;
|
||||
if (n == 0)
|
||||
return -1;
|
||||
if (pwc)
|
||||
*pwc = (wchar_t) *s;
|
||||
return (*s != '\0');
|
||||
#endif /* not _MB_CAPABLE */
|
||||
}
|
||||
|
||||
#endif /* !_REENT_ONLY */
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
FUNCTION
|
||||
<<mbtowc>>---minimal multibyte to wide char converter
|
||||
|
||||
INDEX
|
||||
mbtowc
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
int mbtowc(wchar_t *restrict <[pwc]>, const char *restrict <[s]>, size_t <[n]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
int mbtowc(<[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 <<mbtowc>>. In this case,
|
||||
only ``multi-byte character sequences'' recognized are single bytes,
|
||||
and they are ``converted'' to themselves.
|
||||
Each call to <<mbtowc>> copies one character from <<*<[s]>>> to
|
||||
<<*<[pwc]>>>, unless <[s]> is a null pointer. The argument n
|
||||
is ignored.
|
||||
|
||||
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 <<mbtowc>> returns <<0>> if
|
||||
<[s]> is <<NULL>> or is the empty string;
|
||||
it returns <<1>> if not _MB_CAPABLE or
|
||||
the character is a single-byte character; it returns <<-1>>
|
||||
if n is <<0>> or the multi-byte character is invalid;
|
||||
otherwise it returns the number of bytes in the multibyte character.
|
||||
If the return value is -1, no changes are made to the <<pwc>>
|
||||
output string. If the input is the empty string, a wchar_t nul
|
||||
is placed in the output string and 0 is returned. If the input
|
||||
has a length of 0, no changes are made to the <<pwc>> output string.
|
||||
|
||||
PORTABILITY
|
||||
<<mbtowc>> is required in the ANSI C standard. However, the precise
|
||||
effects vary with the locale.
|
||||
|
||||
<<mbtowc>> requires no supporting OS subroutines.
|
||||
*/
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
#include <newlib.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include "local.h"
|
||||
|
||||
int
|
||||
_DEFUN (mbtowc, (pwc, s, n),
|
||||
wchar_t *__restrict pwc _AND
|
||||
const char *__restrict s _AND
|
||||
size_t n)
|
||||
{
|
||||
#ifdef _MB_CAPABLE
|
||||
int retval = 0;
|
||||
struct _reent *reent = _REENT;
|
||||
mbstate_t *ps;
|
||||
|
||||
_REENT_CHECK_MISC(reent);
|
||||
ps = &(_REENT_MBTOWC_STATE(reent));
|
||||
|
||||
retval = __mbtowc (reent, pwc, s, n, __locale_charset (), ps);
|
||||
|
||||
if (retval < 0)
|
||||
{
|
||||
ps->__count = 0;
|
||||
return -1;
|
||||
}
|
||||
return retval;
|
||||
#else /* not _MB_CAPABLE */
|
||||
if (s == NULL)
|
||||
return 0;
|
||||
if (n == 0)
|
||||
return -1;
|
||||
if (pwc)
|
||||
*pwc = (wchar_t) *s;
|
||||
return (*s != '\0');
|
||||
#endif /* not _MB_CAPABLE */
|
||||
}
|
||||
|
||||
#endif /* !_REENT_ONLY */
|
||||
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,64 +1,64 @@
|
||||
#ifndef MALLOC_PROVIDED
|
||||
/*
|
||||
FUNCTION
|
||||
<<__malloc_lock>>, <<__malloc_unlock>>---lock malloc pool
|
||||
|
||||
INDEX
|
||||
__malloc_lock
|
||||
INDEX
|
||||
__malloc_unlock
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <malloc.h>
|
||||
void __malloc_lock (struct _reent *<[reent]>);
|
||||
void __malloc_unlock (struct _reent *<[reent]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
void __malloc_lock(<[reent]>)
|
||||
struct _reent *<[reent]>;
|
||||
|
||||
void __malloc_unlock(<[reent]>)
|
||||
struct _reent *<[reent]>;
|
||||
|
||||
DESCRIPTION
|
||||
The <<malloc>> family of routines call these functions when they need to lock
|
||||
the memory pool. The version of these routines supplied in the library use
|
||||
the lock API defined in sys/lock.h. If multiple threads of execution can
|
||||
call <<malloc>>, or if <<malloc>> can be called reentrantly, then you need to
|
||||
define your own versions of these functions in order to safely lock the
|
||||
memory pool during a call. If you do not, the memory pool may become
|
||||
corrupted.
|
||||
|
||||
A call to <<malloc>> may call <<__malloc_lock>> recursively; that is,
|
||||
the sequence of calls may go <<__malloc_lock>>, <<__malloc_lock>>,
|
||||
<<__malloc_unlock>>, <<__malloc_unlock>>. Any implementation of these
|
||||
routines must be careful to avoid causing a thread to wait for a lock
|
||||
that it already holds.
|
||||
*/
|
||||
|
||||
#include <malloc.h>
|
||||
#include <sys/lock.h>
|
||||
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__LOCK_INIT_RECURSIVE(static, __malloc_lock_object);
|
||||
#endif
|
||||
|
||||
void
|
||||
__malloc_lock (ptr)
|
||||
struct _reent *ptr;
|
||||
{
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__lock_acquire_recursive (__malloc_lock_object);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
__malloc_unlock (ptr)
|
||||
struct _reent *ptr;
|
||||
{
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__lock_release_recursive (__malloc_lock_object);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifndef MALLOC_PROVIDED
|
||||
/*
|
||||
FUNCTION
|
||||
<<__malloc_lock>>, <<__malloc_unlock>>---lock malloc pool
|
||||
|
||||
INDEX
|
||||
__malloc_lock
|
||||
INDEX
|
||||
__malloc_unlock
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <malloc.h>
|
||||
void __malloc_lock (struct _reent *<[reent]>);
|
||||
void __malloc_unlock (struct _reent *<[reent]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
void __malloc_lock(<[reent]>)
|
||||
struct _reent *<[reent]>;
|
||||
|
||||
void __malloc_unlock(<[reent]>)
|
||||
struct _reent *<[reent]>;
|
||||
|
||||
DESCRIPTION
|
||||
The <<malloc>> family of routines call these functions when they need to lock
|
||||
the memory pool. The version of these routines supplied in the library use
|
||||
the lock API defined in sys/lock.h. If multiple threads of execution can
|
||||
call <<malloc>>, or if <<malloc>> can be called reentrantly, then you need to
|
||||
define your own versions of these functions in order to safely lock the
|
||||
memory pool during a call. If you do not, the memory pool may become
|
||||
corrupted.
|
||||
|
||||
A call to <<malloc>> may call <<__malloc_lock>> recursively; that is,
|
||||
the sequence of calls may go <<__malloc_lock>>, <<__malloc_lock>>,
|
||||
<<__malloc_unlock>>, <<__malloc_unlock>>. Any implementation of these
|
||||
routines must be careful to avoid causing a thread to wait for a lock
|
||||
that it already holds.
|
||||
*/
|
||||
|
||||
#include <malloc.h>
|
||||
#include <sys/lock.h>
|
||||
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__LOCK_INIT_RECURSIVE(static, __malloc_lock_object);
|
||||
#endif
|
||||
|
||||
void
|
||||
__malloc_lock (ptr)
|
||||
struct _reent *ptr;
|
||||
{
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__lock_acquire_recursive (__malloc_lock_object);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
__malloc_unlock (ptr)
|
||||
struct _reent *ptr;
|
||||
{
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__lock_release_recursive (__malloc_lock_object);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
82
contrib/sdk/sources/newlib/libc/stdlib/random.c
Normal file
82
contrib/sdk/sources/newlib/libc/stdlib/random.c
Normal 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 */
|
188
contrib/sdk/sources/newlib/libc/stdlib/wcsnrtombs.c
Normal file
188
contrib/sdk/sources/newlib/libc/stdlib/wcsnrtombs.c
Normal 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 */
|
28
contrib/sdk/sources/newlib/libc/stdlib/wcsrtombs.c
Normal file
28
contrib/sdk/sources/newlib/libc/stdlib/wcsrtombs.c
Normal 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 */
|
232
contrib/sdk/sources/newlib/libc/stdlib/wcstod.c
Normal file
232
contrib/sdk/sources/newlib/libc/stdlib/wcstod.c
Normal 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
|
227
contrib/sdk/sources/newlib/libc/stdlib/wcstol.c
Normal file
227
contrib/sdk/sources/newlib/libc/stdlib/wcstol.c
Normal 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
|
108
contrib/sdk/sources/newlib/libc/stdlib/wcstold.c
Normal file
108
contrib/sdk/sources/newlib/libc/stdlib/wcstold.c
Normal 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 */
|
||||
}
|
139
contrib/sdk/sources/newlib/libc/stdlib/wcstoll.c
Normal file
139
contrib/sdk/sources/newlib/libc/stdlib/wcstoll.c
Normal 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
|
140
contrib/sdk/sources/newlib/libc/stdlib/wcstoll_r.c
Normal file
140
contrib/sdk/sources/newlib/libc/stdlib/wcstoll_r.c
Normal 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__ */
|
83
contrib/sdk/sources/newlib/libc/stdlib/wcstombs.c
Normal file
83
contrib/sdk/sources/newlib/libc/stdlib/wcstombs.c
Normal 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 */
|
48
contrib/sdk/sources/newlib/libc/stdlib/wcstombs_r.c
Normal file
48
contrib/sdk/sources/newlib/libc/stdlib/wcstombs_r.c
Normal 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;
|
||||
}
|
||||
}
|
207
contrib/sdk/sources/newlib/libc/stdlib/wcstoul.c
Normal file
207
contrib/sdk/sources/newlib/libc/stdlib/wcstoul.c
Normal 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
|
140
contrib/sdk/sources/newlib/libc/stdlib/wcstoull.c
Normal file
140
contrib/sdk/sources/newlib/libc/stdlib/wcstoull.c
Normal 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
|
130
contrib/sdk/sources/newlib/libc/stdlib/wcstoull_r.c
Normal file
130
contrib/sdk/sources/newlib/libc/stdlib/wcstoull_r.c
Normal 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__ */
|
26
contrib/sdk/sources/newlib/libc/stdlib/wctob.c
Normal file
26
contrib/sdk/sources/newlib/libc/stdlib/wctob.c
Normal 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;
|
||||
}
|
81
contrib/sdk/sources/newlib/libc/stdlib/wctomb.c
Normal file
81
contrib/sdk/sources/newlib/libc/stdlib/wctomb.c
Normal 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 */
|
Reference in New Issue
Block a user