X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Funistr%2Fu16-to-u32.c;h=bcf2e63081e6f6c689ee89769f56952070ecd607;hb=b65bfcd7ba0be84de3d96f22103103f21679a721;hp=3926deef3919dd64e99e7ac7588a11f7f4a1e3e2;hpb=c87e97db238e6ceaf5cb80c296e31df6c3772bb1;p=gnulib.git diff --git a/lib/unistr/u16-to-u32.c b/lib/unistr/u16-to-u32.c index 3926deef3..bcf2e6308 100644 --- a/lib/unistr/u16-to-u32.c +++ b/lib/unistr/u16-to-u32.c @@ -1,21 +1,19 @@ /* Convert UTF-16 string to UTF-32 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2011 Free Software Foundation, Inc. Written by Bruno Haible , 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 . */ #include @@ -60,57 +58,57 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) int count; /* Fetch a Unicode character from the input string. */ - count = u16_mbtouc (&uc, s, s_end - s); + count = u16_mbtoucr (&uc, s, s_end - s); if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } s += count; /* Store it in the output string. */ if (length + 1 > allocated) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 1 > allocated) - allocated = length + 1; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 1 > allocated) + allocated = length + 1; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + } result[length++] = uc; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -119,7 +117,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length;