From 7ff136ec954654bc8e9814ea2eb07b69082cf797 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 21 Dec 2008 12:05:35 +0100 Subject: [PATCH] Work around a portability problem. --- ChangeLog | 6 ++++++ doc/posix-functions/mbsrtowcs.texi | 7 +++++++ tests/test-mbsrtowcs.c | 13 +++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5670e7647d..1b8092cf0b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-12-21 Bruno Haible + + 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 * lib/wchar.in.h (mbsrtowcs): Redefine if REPLACE_MBSRTOWCS is set. diff --git a/doc/posix-functions/mbsrtowcs.texi b/doc/posix-functions/mbsrtowcs.texi index 72682c66a7..a17eb15951 100644 --- a/doc/posix-functions/mbsrtowcs.texi +++ b/doc/posix-functions/mbsrtowcs.texi @@ -18,4 +18,11 @@ Portability problems not fixed by Gnulib: @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 diff --git a/tests/test-mbsrtowcs.c b/tests/test-mbsrtowcs.c index 27fd58ce19..639ff57c86 100644 --- a/tests/test-mbsrtowcs.c +++ b/tests/test-mbsrtowcs.c @@ -88,6 +88,7 @@ main (int argc, char *argv[]) #define BUFSIZE 10 wchar_t buf[BUFSIZE]; const char *src; + mbstate_t temp_state; { size_t i; @@ -118,7 +119,8 @@ main (int argc, char *argv[]) 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 @@ main (int argc, char *argv[]) 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 @@ main (int argc, char *argv[]) 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 @@ main (int argc, char *argv[]) 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)); -- 2.30.2