+2008-12-21 Bruno Haible <bruno@clisp.org>
+
+ Work around a portability problem.
+ * tests/test-mbsrtowcs.c (main): Use a temporary conversion state.
+ * doc/posix-functions/mbsrtowcs.texi: Document the portability problem.
+
2008-12-20 Bruno Haible <bruno@clisp.org>
* lib/wchar.in.h (mbsrtowcs): Redefine if REPLACE_MBSRTOWCS is set.
@item
On Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot
accommodate all Unicode characters.
+@item
+The specification is not clear about whether this function should update the
+conversion state when the first argument (the destination pointer) is NULL.
+The glibc implementation does not update the state in this case; the MacOS X
+and FreeBSD implementations do.
+For portability, when passing a NULL destination argument, it is best to pass
+a pointer to a temporary copy of the conversion state.
@end itemize
#define BUFSIZE 10
wchar_t buf[BUFSIZE];
const char *src;
+ mbstate_t temp_state;
{
size_t i;
input[1] = '\0';
src = input + 2;
- ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 1, &state);
+ temp_state = state;
+ ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 1, &temp_state);
ASSERT (ret == 3);
ASSERT (src == input + 2);
ASSERT (mbsinit (&state));
input[1] = '\0';
src = input + 2;
- ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &state);
+ temp_state = state;
+ ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state);
ASSERT (ret == 4);
ASSERT (src == input + 2);
ASSERT (!mbsinit (&state));
input[3] = '\0';
src = input + 4;
- ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &state);
+ temp_state = state;
+ ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state);
ASSERT (ret == 3);
ASSERT (src == input + 4);
ASSERT (!mbsinit (&state));
input[1] = '\0';
src = input + 2;
- ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &state);
+ temp_state = state;
+ ret = mbsrtowcs (NULL, &src, unlimited ? BUFSIZE : 2, &temp_state);
ASSERT (ret == 4);
ASSERT (src == input + 2);
ASSERT (!mbsinit (&state));