| www.delorie.com/djgpp/bugs/show.cgi | search |
According to the documentation, the following should work
len = mbstowcs(NULL, s, 0);
However, this is implemented in libc/ansi/locale/mbstowcs.c, which is:
size_t
mbstowcs(wchar_t *wcs, const char *s, size_t n)
{
int i;
for (i=0; s[i] && (i<n-1); i++)
wcs[i] = s[i];
wcs[i] = 0;
return i;
}
and should be
size_t
mbstowcs(wchar_t *wcs, const char *s, size_t n)
{
int i;
for (i=0; s[i] && (i<n-1); i++)
if (wcs) wcs[i] = s[i];
if (wcs) wcs[i] = 0;
return i;
}size_t
mbstowcs(wchar_t *wcs, const char *s, size_t n)
{
int i;
for (i=0; s[i] && (i<n-1); i++)
if (wcs) wcs[i] = s[i];
if (wcs) wcs[i] = 0;
return i;
}Or maybe, the solution should be
size_t
mbstowcs(wchar_t *wcs, const char *s, size_t n)
{
int i;
for (i=0; s[i]; i++)
if ((wcs) && (i<n-1)) wcs[i] = s[i];
if (wcs)
if (i<n-1) wcs[i] = 0; else wcs[n-1] = 0;
return i;
}| webmaster donations bookstore | delorie software privacy |
| Copyright © 2010 by DJ Delorie | Updated Jul 2010 |