mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-18 15:09:32 +08:00
Cygwin: wcitombs: like wcstombs, just for wint_t
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
4449f3a11d
commit
c47a998d0a
@ -44,6 +44,10 @@ extern wctomb_f __utf8_wctomb;
|
|||||||
for surrogate pairs, plus a wchar_t NUL. */
|
for surrogate pairs, plus a wchar_t NUL. */
|
||||||
void wcintowcs (wchar_t *, wint_t *, size_t);
|
void wcintowcs (wchar_t *, wint_t *, size_t);
|
||||||
|
|
||||||
|
/* replacement function for wcstombs, converting a UTF-32 string to
|
||||||
|
a multibyte string. */
|
||||||
|
size_t wcitombs (char *, const wint_t *, size_t);
|
||||||
|
|
||||||
/* replacement function for wcrtomb, converting a UTF-32 char to a
|
/* replacement function for wcrtomb, converting a UTF-32 char to a
|
||||||
multibyte string. */
|
multibyte string. */
|
||||||
size_t wirtomb (char *, wint_t, mbstate_t *);
|
size_t wirtomb (char *, wint_t, mbstate_t *);
|
||||||
|
@ -129,6 +129,49 @@ wcintowcs (wchar_t *dest, wint_t *src, size_t len)
|
|||||||
*dest = '\0';
|
*dest = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* replacement function for wcstombs, converting a UTF-32 string to
|
||||||
|
a multibyte string. */
|
||||||
|
extern "C" size_t
|
||||||
|
wcitombs (char *dest, const wint_t *src, size_t n)
|
||||||
|
{
|
||||||
|
char *ptr = dest;
|
||||||
|
size_t max = n;
|
||||||
|
char buf[8];
|
||||||
|
size_t i, bytes, num_to_copy;
|
||||||
|
mbstate_t state;
|
||||||
|
|
||||||
|
if (dest == NULL)
|
||||||
|
{
|
||||||
|
size_t num_bytes = 0;
|
||||||
|
while (*src != '\0')
|
||||||
|
{
|
||||||
|
bytes = wirtomb (buf, *src++, &state);
|
||||||
|
if (bytes == (size_t) -1)
|
||||||
|
return (size_t) -1;
|
||||||
|
num_bytes += bytes;
|
||||||
|
}
|
||||||
|
return num_bytes;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
bytes = wirtomb (buf, *src++, &state);
|
||||||
|
if (bytes == (size_t) -1)
|
||||||
|
return (size_t) -1;
|
||||||
|
num_to_copy = (n > bytes ? bytes : (int)n);
|
||||||
|
for (i = 0; i < num_to_copy; ++i)
|
||||||
|
*ptr++ = buf[i];
|
||||||
|
|
||||||
|
if (*src == '\0')
|
||||||
|
return ptr - dest - (n >= bytes);
|
||||||
|
++src;
|
||||||
|
n -= num_to_copy;
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* replacement function for wcrtomb, converting a UTF-32 char to a
|
/* replacement function for wcrtomb, converting a UTF-32 char to a
|
||||||
multibyte string. */
|
multibyte string. */
|
||||||
extern "C" size_t
|
extern "C" size_t
|
||||||
|
Loading…
x
Reference in New Issue
Block a user