Work around a portability problem.
authorBruno Haible <bruno@clisp.org>
Sun, 21 Dec 2008 11:05:35 +0000 (12:05 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 21 Dec 2008 11:05:35 +0000 (12:05 +0100)
ChangeLog
doc/posix-functions/mbsrtowcs.texi
tests/test-mbsrtowcs.c

index 5670e7647d125c4d64d2385b8ab6538ed82df9d9..1b8092cf0b270594eaad5977a704d267238c0fa4 100644 (file)
--- 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.
index 72682c66a71deddd8299b779ad7515e240780692..a17eb15951240ae5d4140971b86ff9eeb1941ff5 100644 (file)
@@ -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
index 27fd58ce19d3c912a833568b0ca98a27cab48f43..639ff57c86b949957e5cfcb504f4c6d4065e96e5 100644 (file)
@@ -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));