2005-04-24 13:30:27 +02:00
|
|
|
#include "mb_wc_common.h"
|
|
|
|
#include <wchar.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
|
|
|
|
static int __MINGW_ATTRIB_NONNULL(1)
|
|
|
|
__wcrtomb_cp (char *dst, wchar_t wc, const unsigned int cp,
|
|
|
|
const unsigned int mb_max)
|
|
|
|
{
|
|
|
|
if (cp == 0)
|
|
|
|
{
|
2006-05-17 09:49:39 +02:00
|
|
|
if (wc > 255)
|
|
|
|
{
|
|
|
|
errno = EILSEQ;
|
|
|
|
return -1;
|
|
|
|
}
|
2005-04-24 13:30:27 +02:00
|
|
|
*dst = (char) wc;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int invalid_char = 0;
|
|
|
|
|
2006-05-17 09:49:39 +02:00
|
|
|
int size = WideCharToMultiByte (cp, 0 /* Is this correct flag? */,
|
|
|
|
&wc, 1, dst, mb_max,
|
|
|
|
NULL, &invalid_char);
|
2005-04-24 13:30:27 +02:00
|
|
|
if (size == 0 || invalid_char)
|
|
|
|
{
|
|
|
|
errno = EILSEQ;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
wcrtomb (char *dst, wchar_t wc, mbstate_t * __UNUSED_PARAM (ps))
|
|
|
|
{
|
|
|
|
char byte_bucket [MB_LEN_MAX];
|
|
|
|
char* tmp_dst = dst ? dst : byte_bucket;
|
Import David Gay's gdtoa library.
* mingwex/gdtoa: New directory.
* mingwex/gdtoa/(arithchk.c, dmisc.c, dtoa.c, g__fmt.c, g_dfmt.c,
g_ffmt.c, g_xfmt.c, gd_arith.h, gd_qnan.h, gdtoa.c, gdtoa.h,
gdtoaimp.h, gethex.c, gmisc.c, hd_init.c, hexnan.c, misc.c, qnan.c,
README, smisc.c, strtodg.c, strtodnrp.c, strtof.c, strtopx.c, sum.c,
ulp.c): New files.
* mingwex/(strtof.c, strtold.c, ldtoa.c): Remove files.
* mingwex/math/(cephes-emath.c, cephes-emath.h): Remove files.
* mingwex/mb_wc_common.h (get_cp_from_locale); Rename to get_codepage().
* mingwex/(btowc.c, wctob.c, mbrtowc.c, wcrtomb.c): Adjust call to get_codepage().
* mingwex/wcstold.c: Avoid using strtold internals.
* mingwex/wcstof.c: Rewrite.
* mingwex/Makefile.in (GDTOA_DISTFILES): Add to distribution.
(GDTOA_OBJS): Add to library.
(DISTFILES): Remove strtof.c strtold.c ldtoa.c cephes-emath.c cephes-emath.h.
(STDLIB_OBJS): Remove.
(STDLIB_STUB_OBJS): Remove strtof.o wcstof,o.
(Q8_OBJS): Add wcstof.o wcstold.o.
* include/stdlib.h (strtof): Remove inline definition.
(wcstof): Likewise.
* include/wchar.h (wcstof): Remove inline definition.
2006-09-01 01:48:56 +02:00
|
|
|
return (size_t)__wcrtomb_cp (tmp_dst, wc, get_codepage (),
|
2005-04-24 13:30:27 +02:00
|
|
|
MB_CUR_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t wcsrtombs (char *dst, const wchar_t **src, size_t len,
|
|
|
|
mbstate_t * __UNUSED_PARAM (ps))
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
size_t n = 0;
|
Import David Gay's gdtoa library.
* mingwex/gdtoa: New directory.
* mingwex/gdtoa/(arithchk.c, dmisc.c, dtoa.c, g__fmt.c, g_dfmt.c,
g_ffmt.c, g_xfmt.c, gd_arith.h, gd_qnan.h, gdtoa.c, gdtoa.h,
gdtoaimp.h, gethex.c, gmisc.c, hd_init.c, hexnan.c, misc.c, qnan.c,
README, smisc.c, strtodg.c, strtodnrp.c, strtof.c, strtopx.c, sum.c,
ulp.c): New files.
* mingwex/(strtof.c, strtold.c, ldtoa.c): Remove files.
* mingwex/math/(cephes-emath.c, cephes-emath.h): Remove files.
* mingwex/mb_wc_common.h (get_cp_from_locale); Rename to get_codepage().
* mingwex/(btowc.c, wctob.c, mbrtowc.c, wcrtomb.c): Adjust call to get_codepage().
* mingwex/wcstold.c: Avoid using strtold internals.
* mingwex/wcstof.c: Rewrite.
* mingwex/Makefile.in (GDTOA_DISTFILES): Add to distribution.
(GDTOA_OBJS): Add to library.
(DISTFILES): Remove strtof.c strtold.c ldtoa.c cephes-emath.c cephes-emath.h.
(STDLIB_OBJS): Remove.
(STDLIB_STUB_OBJS): Remove strtof.o wcstof,o.
(Q8_OBJS): Add wcstof.o wcstold.o.
* include/stdlib.h (strtof): Remove inline definition.
(wcstof): Likewise.
* include/wchar.h (wcstof): Remove inline definition.
2006-09-01 01:48:56 +02:00
|
|
|
const unsigned int cp = get_codepage();
|
2005-04-24 13:30:27 +02:00
|
|
|
const unsigned int mb_max = MB_CUR_MAX;
|
2006-06-26 02:53:34 +02:00
|
|
|
const wchar_t *pwc = *src;
|
|
|
|
|
2005-04-24 13:30:27 +02:00
|
|
|
if (src == NULL || *src == NULL) /* undefined behavior */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (dst != NULL)
|
|
|
|
{
|
2006-06-26 02:53:34 +02:00
|
|
|
while (n < len)
|
2005-04-24 13:30:27 +02:00
|
|
|
{
|
2006-06-26 02:53:34 +02:00
|
|
|
if ((ret = __wcrtomb_cp (dst, *pwc, cp, mb_max)) <= 0)
|
2005-04-24 13:30:27 +02:00
|
|
|
return (size_t) -1;
|
|
|
|
n += ret;
|
|
|
|
dst += ret;
|
|
|
|
if (*(dst - 1) == '\0')
|
|
|
|
{
|
2006-06-26 02:53:34 +02:00
|
|
|
*src = (wchar_t*) NULL;;
|
2005-04-24 13:30:27 +02:00
|
|
|
return (n - 1);
|
|
|
|
}
|
2006-06-26 02:53:34 +02:00
|
|
|
pwc++;
|
2005-04-24 13:30:27 +02:00
|
|
|
}
|
2006-06-26 02:53:34 +02:00
|
|
|
*src = pwc;
|
2005-04-24 13:30:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char byte_bucket [MB_LEN_MAX];
|
|
|
|
while (n < len)
|
|
|
|
{
|
2006-06-26 02:53:34 +02:00
|
|
|
if ((ret = __wcrtomb_cp (byte_bucket, *pwc, cp, mb_max))
|
2005-04-24 13:30:27 +02:00
|
|
|
<= 0)
|
|
|
|
return (size_t) -1;
|
|
|
|
n += ret;
|
|
|
|
if (byte_bucket [ret - 1] == '\0')
|
|
|
|
return (n - 1);
|
2006-06-26 02:53:34 +02:00
|
|
|
pwc++;
|
2005-04-24 13:30:27 +02:00
|
|
|
}
|
|
|
|
}
|
2006-06-26 02:53:34 +02:00
|
|
|
|
2005-04-24 13:30:27 +02:00
|
|
|
return n;
|
|
|
|
}
|