+2010-08-14 Bruno Haible <bruno@clisp.org>
+
+ Rename module 'memxfrm' to 'amemxfrm'.
+ * lib/amemxfrm.h: Renamed from lib/memxfrm.h.
+ (amemxfrm): Renamed from memxfrm.
+ * lib/amemxfrm.c: Renamed from lib/memxfrm.h. Include amemxfrm.h.
+ (amemxfrm): Renamed from memxfrm.
+ * modules/amemxfrm: Renamed from modules/memxfrm. Update.
+ * NEWS: Mention the change.
+ * MODULES.html.sh (String handling <string.h>): Update.
+ * lib/unicase/u-casexfrm.h: Invoke amemxfrm instead of memxfrm.
+ * lib/unicase/u8-casexfrm.c: Include amemxfrm.h instead of memxfrm.h.
+ * lib/unicase/u16-casexfrm.c: Likewise.
+ * lib/unicase/u32-casexfrm.c: Likewise.
+ * lib/uninorm/u-normxfrm.h: Invoke amemxfrm instead of memxfrm.
+ * lib/uninorm/u8-normxfrm.c: Include amemxfrm.h instead of memxfrm.h.
+ * lib/uninorm/u16-normxfrm.c: Likewise.
+ * lib/uninorm/u32-normxfrm.c: Likewise.
+ * modules/unicase/u8-casexfrm (Depends-on): Add amemxfrm, remove
+ memxfrm.
+ * modules/unicase/u16-casexfrm (Depends-on): Likewise.
+ * modules/unicase/u32-casexfrm (Depends-on): Likewise.
+ * modules/uninorm/u8-normxfrm (Depends-on): Likewise.
+ * modules/uninorm/u16-normxfrm (Depends-on): Likewise.
+ * modules/uninorm/u32-normxfrm (Depends-on): Likewise.
+ Suggested by Paul Eggert.
+
2010-08-14 Bruno Haible <bruno@clisp.org>
Tests for module 'astrxfrm'.
func_module memmem-simple
func_module mempcpy
func_module memrchr
- func_module memxfrm
+ func_module amemxfrm
func_module rawmemchr
func_module stpcpy
func_module stpncpy
Date Modules Changes
+2010-08-14 memxfrm This module is renamed to amemxfrm. The include
+ file is renamed to "amemxfrm.h". The function is
+ renamed to amemxfrm.
+
2010-08-09 symlinkat This module now only provides symlinkat; use the
new module 'readlinkat' if needed.
--- /dev/null
+/* Locale dependent memory area transformation for comparison.
+ Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2009.
+
+ 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
+ Lesser General Public License for more details.
+
+ 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>
+
+/* Specification. */
+#include "amemxfrm.h"
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *
+amemxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp)
+{
+ /* Result accumulator. */
+ char *result;
+ size_t length;
+ size_t allocated;
+
+ char orig_sentinel;
+
+ /* Initial memory allocation. */
+ if (resultbuf != NULL && *lengthp > 0)
+ {
+ result = resultbuf;
+ allocated = *lengthp;
+ }
+ else
+ {
+ allocated = (n > 0 ? n : 1);
+ result = (char *) malloc (allocated);
+ if (result == NULL)
+ goto out_of_memory_2;
+ }
+ length = 0;
+
+ /* Add sentinel.byte. */
+ orig_sentinel = s[n];
+ s[n] = '\0';
+
+ /* Iterate through S, transforming each NUL terminated segment.
+ Accumulate the resulting transformed segments in result, separated by
+ NULs. */
+ {
+ const char *p_end = s + n + 1;
+ const char *p;
+
+ p = s;
+ for (;;)
+ {
+ /* Search next NUL byte. */
+ size_t l = strlen (p);
+
+ for (;;)
+ {
+ size_t k;
+
+ /* A call to strxfrm costs about 20 times more than a call to
+ strdup of the result. Therefore it is worth to try to avoid
+ calling strxfrm more than once on a given string, by making
+ enough room before calling strxfrm.
+ The size of the strxfrm result, k, is likely to be between
+ l and 3 * l. */
+ if (3 * l >= allocated - length)
+ {
+ /* Grow the result buffer. */
+ size_t new_allocated;
+ char *new_result;
+
+ new_allocated = length + 3 * l + 1;
+ if (new_allocated < 2 * allocated)
+ new_allocated = 2 * allocated;
+ if (new_allocated < 64)
+ new_allocated = 64;
+ if (result == resultbuf)
+ new_result = (char *) malloc (new_allocated);
+ else
+ new_result = (char *) realloc (result, new_allocated);
+ if (new_result != NULL)
+ {
+ allocated = new_allocated;
+ result = new_result;
+ }
+ }
+
+ errno = 0;
+ k = strxfrm (result + length, p, allocated - length);
+ if (errno != 0)
+ goto fail;
+ if (k >= allocated - length)
+ {
+ /* Grow the result buffer. */
+ size_t new_allocated;
+ char *new_result;
+
+ new_allocated = length + k + 1;
+ if (new_allocated < 2 * allocated)
+ new_allocated = 2 * allocated;
+ if (new_allocated < 64)
+ new_allocated = 64;
+ if (result == resultbuf)
+ new_result = (char *) malloc (new_allocated);
+ else
+ new_result = (char *) realloc (result, new_allocated);
+ if (new_result == NULL)
+ goto out_of_memory_1;
+ allocated = new_allocated;
+ result = new_result;
+ }
+ else
+ {
+ length += k;
+ break;
+ }
+ }
+
+ p = p + l + 1;
+ if (p == p_end)
+ break;
+ result[length] = '\0';
+ length++;
+ }
+ }
+
+ /* Shrink the allocated memory if possible.
+ It is not worth calling realloc when length + 1 == allocated; it would
+ save just one byte. */
+ if (result != resultbuf && length + 1 < allocated)
+ {
+ if ((length > 0 ? length : 1) <= *lengthp)
+ {
+ memcpy (resultbuf, result, length);
+ free (result);
+ result = resultbuf;
+ }
+ else
+ {
+ char *memory = (char *) realloc (result, length > 0 ? length : 1);
+ if (memory != NULL)
+ result = memory;
+ }
+ }
+
+ s[n] = orig_sentinel;
+ *lengthp = length;
+ return result;
+
+ fail:
+ {
+ int saved_errno = errno;
+ if (result != resultbuf)
+ free (result);
+ s[n] = orig_sentinel;
+ errno = saved_errno;
+ return NULL;
+ }
+
+ out_of_memory_1:
+ if (result != resultbuf)
+ free (result);
+ s[n] = orig_sentinel;
+ out_of_memory_2:
+ errno = ENOMEM;
+ return NULL;
+}
--- /dev/null
+/* Locale dependent memory area transformation for comparison.
+ Copyright (C) 2009-2010 Free Software Foundation, Inc.
+
+ 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
+ Lesser General Public License for more details.
+
+ 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/>. */
+
+#ifndef AMEMXFRM_H
+#define AMEMXFRM_H
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Generalization of strxfrm() to strings with embedded NUL bytes. */
+
+/* Transform the memory area [S..S+N-1] to a memory area, in such a way that
+ comparing (S1,N1) and (S2,N2) with memcoll() is equivalent to comparing
+ amemxfrm(S1,N1) and amemxfrm(S2,N2) with memcmp2().
+ The byte S[N] may be temporarily overwritten by this function, but will be
+ restored before this function returns.
+ The result of this function depends on the LC_COLLATE category of the
+ current locale.
+ If successful: If resultbuf is not NULL and the result fits into *lengthp
+ bytes, it is put in resultbuf, and resultbuf is returned. Otherwise, a
+ freshly allocated string is returned. In both cases, *lengthp is set to the
+ length of the returned string.
+ Upon failure, return NULL, with errno set. */
+extern char * amemxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* AMEMXFRM_H */
+++ /dev/null
-/* Locale dependent memory area transformation for comparison.
- Copyright (C) 2009, 2010 Free Software Foundation, Inc.
- Written by Bruno Haible <bruno@clisp.org>, 2009.
-
- 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
- Lesser General Public License for more details.
-
- 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>
-
-/* Specification. */
-#include "memxfrm.h"
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-char *
-memxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp)
-{
- /* Result accumulator. */
- char *result;
- size_t length;
- size_t allocated;
-
- char orig_sentinel;
-
- /* Initial memory allocation. */
- if (resultbuf != NULL && *lengthp > 0)
- {
- result = resultbuf;
- allocated = *lengthp;
- }
- else
- {
- allocated = (n > 0 ? n : 1);
- result = (char *) malloc (allocated);
- if (result == NULL)
- goto out_of_memory_2;
- }
- length = 0;
-
- /* Add sentinel.byte. */
- orig_sentinel = s[n];
- s[n] = '\0';
-
- /* Iterate through S, transforming each NUL terminated segment.
- Accumulate the resulting transformed segments in result, separated by
- NULs. */
- {
- const char *p_end = s + n + 1;
- const char *p;
-
- p = s;
- for (;;)
- {
- /* Search next NUL byte. */
- size_t l = strlen (p);
-
- for (;;)
- {
- size_t k;
-
- /* A call to strxfrm costs about 20 times more than a call to
- strdup of the result. Therefore it is worth to try to avoid
- calling strxfrm more than once on a given string, by making
- enough room before calling strxfrm.
- The size of the strxfrm result, k, is likely to be between
- l and 3 * l. */
- if (3 * l >= allocated - length)
- {
- /* Grow the result buffer. */
- size_t new_allocated;
- char *new_result;
-
- new_allocated = length + 3 * l + 1;
- if (new_allocated < 2 * allocated)
- new_allocated = 2 * allocated;
- if (new_allocated < 64)
- new_allocated = 64;
- if (result == resultbuf)
- new_result = (char *) malloc (new_allocated);
- else
- new_result = (char *) realloc (result, new_allocated);
- if (new_result != NULL)
- {
- allocated = new_allocated;
- result = new_result;
- }
- }
-
- errno = 0;
- k = strxfrm (result + length, p, allocated - length);
- if (errno != 0)
- goto fail;
- if (k >= allocated - length)
- {
- /* Grow the result buffer. */
- size_t new_allocated;
- char *new_result;
-
- new_allocated = length + k + 1;
- if (new_allocated < 2 * allocated)
- new_allocated = 2 * allocated;
- if (new_allocated < 64)
- new_allocated = 64;
- if (result == resultbuf)
- new_result = (char *) malloc (new_allocated);
- else
- new_result = (char *) realloc (result, new_allocated);
- if (new_result == NULL)
- goto out_of_memory_1;
- allocated = new_allocated;
- result = new_result;
- }
- else
- {
- length += k;
- break;
- }
- }
-
- p = p + l + 1;
- if (p == p_end)
- break;
- result[length] = '\0';
- length++;
- }
- }
-
- /* Shrink the allocated memory if possible.
- It is not worth calling realloc when length + 1 == allocated; it would
- save just one byte. */
- if (result != resultbuf && length + 1 < allocated)
- {
- if ((length > 0 ? length : 1) <= *lengthp)
- {
- memcpy (resultbuf, result, length);
- free (result);
- result = resultbuf;
- }
- else
- {
- char *memory = (char *) realloc (result, length > 0 ? length : 1);
- if (memory != NULL)
- result = memory;
- }
- }
-
- s[n] = orig_sentinel;
- *lengthp = length;
- return result;
-
- fail:
- {
- int saved_errno = errno;
- if (result != resultbuf)
- free (result);
- s[n] = orig_sentinel;
- errno = saved_errno;
- return NULL;
- }
-
- out_of_memory_1:
- if (result != resultbuf)
- free (result);
- s[n] = orig_sentinel;
- out_of_memory_2:
- errno = ENOMEM;
- return NULL;
-}
+++ /dev/null
-/* Locale dependent memory area transformation for comparison.
- Copyright (C) 2009, 2010 Free Software Foundation, Inc.
-
- 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
- Lesser General Public License for more details.
-
- 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/>. */
-
-#ifndef MEMXFRM_H
-#define MEMXFRM_H
-
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* Generalization of strxfrm() to strings with embedded NUL bytes. */
-
-/* Transform the memory area [S..S+N-1] to a memory area, in such a way that
- comparing (S1,N1) and (S2,N2) with memcoll() is equivalent to comparing
- memxfrm(S1,N1) and memxfrm(S2,N2) with memcmp2().
- The byte S[N] may be temporarily overwritten by this function, but will be
- restored before this function returns.
- The result of this function depends on the LC_COLLATE category of the
- current locale.
- If successful: If resultbuf is not NULL and the result fits into *lengthp
- bytes, it is put in resultbuf, and resultbuf is returned. Otherwise, a
- freshly allocated string is returned. In both cases, *lengthp is set to the
- length of the returned string.
- Upon failure, return NULL, with errno set. */
-extern char * memxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* MEMXFRM_H */
}
/* Apply locale dependent transformations for comparison. */
- result = memxfrm (convs, convs_length, resultbuf, lengthp);
+ result = amemxfrm (convs, convs_length, resultbuf, lengthp);
if (result == NULL)
{
if (convs != convsbuf)
#include "localcharset.h"
#include "uniconv.h"
-#include "memxfrm.h"
+#include "amemxfrm.h"
#define FUNC u16_casexfrm
#define UNIT uint16_t
#include "localcharset.h"
#include "uniconv.h"
-#include "memxfrm.h"
+#include "amemxfrm.h"
#define FUNC u32_casexfrm
#define UNIT uint32_t
#include "localcharset.h"
#include "uniconv.h"
-#include "memxfrm.h"
+#include "amemxfrm.h"
#define FUNC u8_casexfrm
#define UNIT uint8_t
}
/* Apply locale dependent transformations for comparison. */
- result = memxfrm (convs, convs_length, resultbuf, lengthp);
+ result = amemxfrm (convs, convs_length, resultbuf, lengthp);
if (result == NULL)
{
if (convs != convsbuf)
#include "localcharset.h"
#include "uniconv.h"
-#include "memxfrm.h"
+#include "amemxfrm.h"
#define FUNC u16_normxfrm
#define UNIT uint16_t
#include "localcharset.h"
#include "uniconv.h"
-#include "memxfrm.h"
+#include "amemxfrm.h"
#define FUNC u32_normxfrm
#define UNIT uint32_t
#include "localcharset.h"
#include "uniconv.h"
-#include "memxfrm.h"
+#include "amemxfrm.h"
#define FUNC u8_normxfrm
#define UNIT uint8_t
--- /dev/null
+Description:
+Locale dependent memory area transformation for comparison.
+
+Files:
+lib/amemxfrm.h
+lib/amemxfrm.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += amemxfrm.c
+
+Include:
+"amemxfrm.h"
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+++ /dev/null
-Description:
-Locale dependent memory area transformation for comparison.
-
-Files:
-lib/memxfrm.h
-lib/memxfrm.c
-
-Depends-on:
-
-configure.ac:
-
-Makefile.am:
-lib_SOURCES += memxfrm.c
-
-Include:
-"memxfrm.h"
-
-License:
-LGPL
-
-Maintainer:
-Bruno Haible
unicase/u16-casefold
uniconv/u16-conv-to-enc
localcharset
-memxfrm
+amemxfrm
configure.ac:
gl_LIBUNISTRING_MODULE([0.9.1], [unicase/u16-casexfrm])
unicase/u32-casefold
uniconv/u32-conv-to-enc
localcharset
-memxfrm
+amemxfrm
configure.ac:
gl_LIBUNISTRING_MODULE([0.9.1], [unicase/u32-casexfrm])
unicase/u8-casefold
uniconv/u8-conv-to-enc
localcharset
-memxfrm
+amemxfrm
configure.ac:
gl_LIBUNISTRING_MODULE([0.9.1], [unicase/u8-casexfrm])
uninorm/u16-normalize
uniconv/u16-conv-to-enc
localcharset
-memxfrm
+amemxfrm
configure.ac:
gl_LIBUNISTRING_MODULE([0.9], [uninorm/u16-normxfrm])
uninorm/u32-normalize
uniconv/u32-conv-to-enc
localcharset
-memxfrm
+amemxfrm
configure.ac:
gl_LIBUNISTRING_MODULE([0.9], [uninorm/u32-normxfrm])
uninorm/u8-normalize
uniconv/u8-conv-to-enc
localcharset
-memxfrm
+amemxfrm
configure.ac:
gl_LIBUNISTRING_MODULE([0.9], [uninorm/u8-normxfrm])