summaryrefslogtreecommitdiff
path: root/lib/unistr/u32-to-u16.c
diff options
context:
space:
mode:
authorAndreas Rottmann <a.rottmann@gmx.at>2010-05-27 18:23:15 +0200
committerAndreas Rottmann <a.rottmann@gmx.at>2010-05-27 18:23:15 +0200
commit3e0814cd9862b89c7a39672672937477bd87ddfb (patch)
tree159134a624e51509f40ed8823249f09a70d1dda3 /lib/unistr/u32-to-u16.c
parent3bebb94360f1c2333feb8d504a9fa4f96984d8b7 (diff)
Imported Upstream version 0.9.3upstream/0.9.3
Diffstat (limited to 'lib/unistr/u32-to-u16.c')
-rw-r--r--lib/unistr/u32-to-u16.c90
1 files changed, 45 insertions, 45 deletions
diff --git a/lib/unistr/u32-to-u16.c b/lib/unistr/u32-to-u16.c
index 3a32162c..be327703 100644
--- a/lib/unistr/u32-to-u16.c
+++ b/lib/unistr/u32-to-u16.c
@@ -1,5 +1,5 @@
/* Convert UTF-32 string to UTF-16 string.
- Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2006-2007, 2009-2010 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
@@ -60,60 +60,60 @@ 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, because
- u16_uctomb will verify uc anyway. */
+ u16_uctomb will verify uc anyway. */
/* Store it in the output string. */
count = u16_uctomb (result + length, uc, allocated - length);
if (count == -1)
- {
- if (!(result == resultbuf || result == NULL))
- free (result);
- errno = EILSEQ;
- return NULL;
- }
+ {
+ if (!(result == resultbuf || result == NULL))
+ free (result);
+ errno = EILSEQ;
+ return NULL;
+ }
if (count == -2)
- {
- DST_UNIT *memory;
-
- allocated = (allocated > 0 ? 2 * allocated : 12);
- if (length + 2 > allocated)
- allocated = length + 2;
- 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;
- count = u16_uctomb (result + length, uc, allocated - length);
- if (count < 0)
- abort ();
- }
+ {
+ DST_UNIT *memory;
+
+ allocated = (allocated > 0 ? 2 * allocated : 12);
+ if (length + 2 > allocated)
+ allocated = length + 2;
+ 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;
+ count = u16_uctomb (result + length, uc, allocated - length);
+ if (count < 0)
+ abort ();
+ }
length += count;
}
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)
{
@@ -122,7 +122,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;