Mercurial > hg > octave-lyh > gnulib-hg
changeset 10927:d95b547d4655
Work around a portability problem.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 21 Dec 2008 12:05:35 +0100 |
parents | 36aff2e768db |
children | ae4a7d0b5e51 |
files | ChangeLog doc/posix-functions/mbsrtowcs.texi tests/test-mbsrtowcs.c |
diffstat | 3 files changed, 22 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +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.
--- a/doc/posix-functions/mbsrtowcs.texi +++ b/doc/posix-functions/mbsrtowcs.texi @@ -18,4 +18,11 @@ @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
--- a/tests/test-mbsrtowcs.c +++ b/tests/test-mbsrtowcs.c @@ -88,6 +88,7 @@ #define BUFSIZE 10 wchar_t buf[BUFSIZE]; const char *src; + mbstate_t temp_state; { size_t i; @@ -118,7 +119,8 @@ 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)); @@ -162,7 +164,8 @@ 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)); @@ -215,7 +218,8 @@ 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)); @@ -259,7 +263,8 @@ 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));