New module 'posix_spawnattr_destroy'.
[gnulib.git] / lib / unistr / u32-to-u8.c
index c714a50..4dce896 100644 (file)
@@ -1,21 +1,19 @@
 /* Convert UTF-32 string to UTF-8 string.
-   Copyright (C) 2002, 2006 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2002.
 
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU Library General Public License as published
-   by the Free Software Foundation; either version 2, or (at your option)
-   any later version.
+   This program is free software: you can redistribute it and/or modify it
+   under the terms of the GNU Lesser General Public License as published
+   by the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-   USA.  */
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 
@@ -61,11 +59,11 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
 
       /* Fetch a Unicode character from the input string.  */
       uc = *s++;
-      /* No need to call the safe variant u32_mbtouc_safe, because
+      /* No need to call the safe variant u32_mbtouc, because
         u8_uctomb will verify uc anyway.  */
 
       /* Store it in the output string.  */
-      count = u8_uctomb (result, uc, allocated - length);
+      count = u8_uctomb (result + length, uc, allocated - length);
       if (count == -1)
        {
          if (!(result == resultbuf || result == NULL))
@@ -97,7 +95,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp)
            memcpy ((char *) memory, (char *) result,
                    length * sizeof (DST_UNIT));
          result = memory;
-         count = u8_uctomb (result, uc, allocated - length);
+         count = u8_uctomb (result + length, uc, allocated - length);
          if (count < 0)
            abort ();
        }