From: Bruno Haible Date: Sat, 14 Aug 2010 22:42:00 +0000 (+0200) Subject: Rename module 'memxfrm' to 'amemxfrm'. X-Git-Tag: v0.1~3930 X-Git-Url: http://erislabs.net/gitweb/?p=gnulib.git;a=commitdiff_plain;h=a6e3f90ba60482e679b8c60a2e2658058715da12 Rename module 'memxfrm' to 'amemxfrm'. --- diff --git a/ChangeLog b/ChangeLog index 97646f420..d86bbc37e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,32 @@ 2010-08-14 Bruno Haible + 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 ): 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 + Tests for module 'astrxfrm'. * modules/astrxfrm-tests: New file. * tests/test-astrxfrm.c: New file. diff --git a/MODULES.html.sh b/MODULES.html.sh index 76574ffea..7fc6b79fa 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -1778,7 +1778,7 @@ func_all_modules () 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 diff --git a/NEWS b/NEWS index ff3bfb6c2..3f08cc49a 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,10 @@ User visible incompatible changes 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. diff --git a/lib/amemxfrm.c b/lib/amemxfrm.c new file mode 100644 index 000000000..3823ce454 --- /dev/null +++ b/lib/amemxfrm.c @@ -0,0 +1,180 @@ +/* Locale dependent memory area transformation for comparison. + Copyright (C) 2009, 2010 Free Software Foundation, Inc. + Written by Bruno Haible , 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 . */ + +#include + +/* Specification. */ +#include "amemxfrm.h" + +#include +#include +#include + +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; +} diff --git a/lib/amemxfrm.h b/lib/amemxfrm.h new file mode 100644 index 000000000..2edf535ad --- /dev/null +++ b/lib/amemxfrm.h @@ -0,0 +1,48 @@ +/* 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 . */ + +#ifndef AMEMXFRM_H +#define AMEMXFRM_H + +#include + +#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 */ diff --git a/lib/memxfrm.c b/lib/memxfrm.c deleted file mode 100644 index d0a3c78ef..000000000 --- a/lib/memxfrm.c +++ /dev/null @@ -1,180 +0,0 @@ -/* Locale dependent memory area transformation for comparison. - Copyright (C) 2009, 2010 Free Software Foundation, Inc. - Written by Bruno Haible , 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 . */ - -#include - -/* Specification. */ -#include "memxfrm.h" - -#include -#include -#include - -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; -} diff --git a/lib/memxfrm.h b/lib/memxfrm.h deleted file mode 100644 index 8b7284a65..000000000 --- a/lib/memxfrm.h +++ /dev/null @@ -1,48 +0,0 @@ -/* 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 . */ - -#ifndef MEMXFRM_H -#define MEMXFRM_H - -#include - -#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 */ diff --git a/lib/unicase/u-casexfrm.h b/lib/unicase/u-casexfrm.h index 5c7430c0f..b2725d4a6 100644 --- a/lib/unicase/u-casexfrm.h +++ b/lib/unicase/u-casexfrm.h @@ -70,7 +70,7 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, uninorm_t nf, } /* 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) diff --git a/lib/unicase/u16-casexfrm.c b/lib/unicase/u16-casexfrm.c index 661902fc3..63fe67495 100644 --- a/lib/unicase/u16-casexfrm.c +++ b/lib/unicase/u16-casexfrm.c @@ -26,7 +26,7 @@ #include "localcharset.h" #include "uniconv.h" -#include "memxfrm.h" +#include "amemxfrm.h" #define FUNC u16_casexfrm #define UNIT uint16_t diff --git a/lib/unicase/u32-casexfrm.c b/lib/unicase/u32-casexfrm.c index bd54497b1..c65df7265 100644 --- a/lib/unicase/u32-casexfrm.c +++ b/lib/unicase/u32-casexfrm.c @@ -26,7 +26,7 @@ #include "localcharset.h" #include "uniconv.h" -#include "memxfrm.h" +#include "amemxfrm.h" #define FUNC u32_casexfrm #define UNIT uint32_t diff --git a/lib/unicase/u8-casexfrm.c b/lib/unicase/u8-casexfrm.c index b3e0c664b..cd6f45ed4 100644 --- a/lib/unicase/u8-casexfrm.c +++ b/lib/unicase/u8-casexfrm.c @@ -26,7 +26,7 @@ #include "localcharset.h" #include "uniconv.h" -#include "memxfrm.h" +#include "amemxfrm.h" #define FUNC u8_casexfrm #define UNIT uint8_t diff --git a/lib/uninorm/u-normxfrm.h b/lib/uninorm/u-normxfrm.h index ce84ff675..1e0e53da6 100644 --- a/lib/uninorm/u-normxfrm.h +++ b/lib/uninorm/u-normxfrm.h @@ -69,7 +69,7 @@ FUNC (const UNIT *s, size_t n, uninorm_t nf, } /* 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) diff --git a/lib/uninorm/u16-normxfrm.c b/lib/uninorm/u16-normxfrm.c index 41d274ab0..d4af5ee33 100644 --- a/lib/uninorm/u16-normxfrm.c +++ b/lib/uninorm/u16-normxfrm.c @@ -25,7 +25,7 @@ #include "localcharset.h" #include "uniconv.h" -#include "memxfrm.h" +#include "amemxfrm.h" #define FUNC u16_normxfrm #define UNIT uint16_t diff --git a/lib/uninorm/u32-normxfrm.c b/lib/uninorm/u32-normxfrm.c index 7e953f98a..0d1629d76 100644 --- a/lib/uninorm/u32-normxfrm.c +++ b/lib/uninorm/u32-normxfrm.c @@ -25,7 +25,7 @@ #include "localcharset.h" #include "uniconv.h" -#include "memxfrm.h" +#include "amemxfrm.h" #define FUNC u32_normxfrm #define UNIT uint32_t diff --git a/lib/uninorm/u8-normxfrm.c b/lib/uninorm/u8-normxfrm.c index 47d4fdc0d..2564f1cf9 100644 --- a/lib/uninorm/u8-normxfrm.c +++ b/lib/uninorm/u8-normxfrm.c @@ -25,7 +25,7 @@ #include "localcharset.h" #include "uniconv.h" -#include "memxfrm.h" +#include "amemxfrm.h" #define FUNC u8_normxfrm #define UNIT uint8_t diff --git a/modules/amemxfrm b/modules/amemxfrm new file mode 100644 index 000000000..a5fb244ce --- /dev/null +++ b/modules/amemxfrm @@ -0,0 +1,22 @@ +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 diff --git a/modules/memxfrm b/modules/memxfrm deleted file mode 100644 index 8c9033ca6..000000000 --- a/modules/memxfrm +++ /dev/null @@ -1,22 +0,0 @@ -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 diff --git a/modules/unicase/u16-casexfrm b/modules/unicase/u16-casexfrm index 78774e2a7..a79d16375 100644 --- a/modules/unicase/u16-casexfrm +++ b/modules/unicase/u16-casexfrm @@ -11,7 +11,7 @@ unicase/base unicase/u16-casefold uniconv/u16-conv-to-enc localcharset -memxfrm +amemxfrm configure.ac: gl_LIBUNISTRING_MODULE([0.9.1], [unicase/u16-casexfrm]) diff --git a/modules/unicase/u32-casexfrm b/modules/unicase/u32-casexfrm index 6fb660eab..0f86654c2 100644 --- a/modules/unicase/u32-casexfrm +++ b/modules/unicase/u32-casexfrm @@ -11,7 +11,7 @@ unicase/base unicase/u32-casefold uniconv/u32-conv-to-enc localcharset -memxfrm +amemxfrm configure.ac: gl_LIBUNISTRING_MODULE([0.9.1], [unicase/u32-casexfrm]) diff --git a/modules/unicase/u8-casexfrm b/modules/unicase/u8-casexfrm index 968dd59be..bc029125d 100644 --- a/modules/unicase/u8-casexfrm +++ b/modules/unicase/u8-casexfrm @@ -11,7 +11,7 @@ unicase/base unicase/u8-casefold uniconv/u8-conv-to-enc localcharset -memxfrm +amemxfrm configure.ac: gl_LIBUNISTRING_MODULE([0.9.1], [unicase/u8-casexfrm]) diff --git a/modules/uninorm/u16-normxfrm b/modules/uninorm/u16-normxfrm index 9305b55e4..82ba01e94 100644 --- a/modules/uninorm/u16-normxfrm +++ b/modules/uninorm/u16-normxfrm @@ -10,7 +10,7 @@ uninorm/base uninorm/u16-normalize uniconv/u16-conv-to-enc localcharset -memxfrm +amemxfrm configure.ac: gl_LIBUNISTRING_MODULE([0.9], [uninorm/u16-normxfrm]) diff --git a/modules/uninorm/u32-normxfrm b/modules/uninorm/u32-normxfrm index 9cb06413e..8e4635b6a 100644 --- a/modules/uninorm/u32-normxfrm +++ b/modules/uninorm/u32-normxfrm @@ -10,7 +10,7 @@ uninorm/base uninorm/u32-normalize uniconv/u32-conv-to-enc localcharset -memxfrm +amemxfrm configure.ac: gl_LIBUNISTRING_MODULE([0.9], [uninorm/u32-normxfrm]) diff --git a/modules/uninorm/u8-normxfrm b/modules/uninorm/u8-normxfrm index 123d1a7a1..4c90b8ce5 100644 --- a/modules/uninorm/u8-normxfrm +++ b/modules/uninorm/u8-normxfrm @@ -10,7 +10,7 @@ uninorm/base uninorm/u8-normalize uniconv/u8-conv-to-enc localcharset -memxfrm +amemxfrm configure.ac: gl_LIBUNISTRING_MODULE([0.9], [uninorm/u8-normxfrm])