Enforce the use of gnulib modules for unportable <string.h> functions.
authorBruno Haible <bruno@clisp.org>
Thu, 1 Feb 2007 00:29:52 +0000 (00:29 +0000)
committerBruno Haible <bruno@clisp.org>
Thu, 1 Feb 2007 00:29:52 +0000 (00:29 +0000)
18 files changed:
ChangeLog
lib/string_.h
modules/memmem
modules/mempcpy
modules/memrchr
modules/stpcpy
modules/stpncpy
modules/strcase
modules/strcasestr
modules/strchrnul
modules/strdup
modules/string
modules/strndup
modules/strnlen
modules/strpbrk
modules/strsep
modules/strstr
modules/strtok_r

index a3096ce7fda45140b84423f4b3e9f4875a2179e2..ab851dcbe052b260799b2ca1b9271d95d880f1b0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,29 @@
-2007-01-31  Jean-Louis Martineau <martineau@zmanda.com>  (tiny change)
+2007-01-27  Bruno Haible  <bruno@clisp.org>
+
+       Enforce the use of gnulib modules for unportable <string.h> functions.
+       * m4/string_h.m4 (gl_STRING_MODULE_INDICATOR): New macro.
+       (gl_STRING_MODULE_INDICATOR_DEFAULTS): New macro.
+       (gl_HEADER_STRING_H_BODY): Require it.
+       * lib/string_.h: If the gnulib module XYZ is not present, redefine
+       the symbol XYZ to one that gives a link error.
+       * modules/string (Makefile.am): Also substitute the GNULIB_* variables.
+       * modules/memmem (configure.ac): Invoke gl_STRING_MODULE_INDICATOR.
+       * modules/mempcpy (configure.ac): Likewise.
+       * modules/memrchr (configure.ac): Likewise.
+       * modules/stpcpy (configure.ac): Likewise.
+       * modules/stpncpy (configure.ac): Likewise.
+       * modules/strcase (configure.ac): Likewise.
+       * modules/strcasestr (configure.ac): Likewise.
+       * modules/strchrnul (configure.ac): Likewise.
+       * modules/strdup (configure.ac): Likewise.
+       * modules/strndup (configure.ac): Likewise.
+       * modules/strnlen (configure.ac): Likewise.
+       * modules/strpbrk (configure.ac): Likewise.
+       * modules/strsep (configure.ac): Likewise.
+       * modules/strstr (configure.ac): Likewise.
+       * modules/strtok_r (configure.ac): Likewise.
+
+2007-01-31  Jean-Louis Martineau  <martineau@zmanda.com>  (tiny change)
 
        * lib/gai_strerror.c (values): Add EAI_OVERFLOW.
 
index 94d991cf06ec2c06bb205f799fb147d6f5602751..86701d41953e033b4b6a0e0d0110d915d9557475 100644 (file)
@@ -26,34 +26,54 @@ extern "C" {
 #endif
 
 /* Return the first occurrence of NEEDLE in HAYSTACK.  */
-#if ! @HAVE_DECL_MEMMEM@
+#if @GNULIB_MEMMEM@
+# if ! @HAVE_DECL_MEMMEM@
 extern void *memmem (void const *__haystack, size_t __haystack_len,
                     void const *__needle, size_t __needle_len);
+# endif
+#else
+# define memmem memmem_is_unportable__use_gnulib_module_memmem_for_portability
 #endif
 
 /* Copy N bytes of SRC to DEST, return pointer to bytes after the
    last written byte.  */
-#if ! @HAVE_MEMPCPY@
+#if @GNULIB_MEMPCPY@
+# if ! @HAVE_MEMPCPY@
 extern void *mempcpy (void *restrict __dest, void const *restrict __src,
                      size_t __n);
+# endif
+#else
+# define mempcpy mempcpy_is_unportable__use_gnulib_module_mempcpy_for_portability
 #endif
 
 /* Search backwards through a block for a byte (specified as an int).  */
-#if ! @HAVE_DECL_MEMRCHR@
+#if @GNULIB_MEMRCHR@
+# if ! @HAVE_DECL_MEMRCHR@
 extern void *memrchr (void const *, int, size_t);
+# endif
+#else
+# define memrchr memrchr_is_unportable__use_gnulib_module_memrchr_for_portability
 #endif
 
 /* Copy SRC to DST, returning the address of the terminating '\0' in DST.  */
-#if ! @HAVE_STPCPY@
+#if @GNULIB_STPCPY@
+# if ! @HAVE_STPCPY@
 extern char *stpcpy (char *restrict __dst, char const *restrict __src);
+# endif
+#else
+# define stpcpy stpcpy_is_unportable__use_gnulib_module_stpcpy_for_portability
 #endif
 
 /* Copy no more than N bytes of SRC to DST, returning a pointer past the
    last non-NUL byte written into DST.  */
-#if ! @HAVE_STPNCPY@
-# define stpncpy gnu_stpncpy
+#if @GNULIB_STPNCPY@
+# if ! @HAVE_STPNCPY@
+#  define stpncpy gnu_stpncpy
 extern char *stpncpy (char *restrict __dst, char const *restrict __src,
                      size_t __n);
+# endif
+#else
+# define stpncpy stpncpy_is_unportable__use_gnulib_module_stpncpy_for_portability
 #endif
 
 /* Compare strings S1 and S2, ignoring case, returning less than, equal to or
@@ -64,48 +84,76 @@ extern char *stpncpy (char *restrict __dst, char const *restrict __src,
    No known system has a strcasecmp() function that works correctly in
    multibyte locales.  Therefore use our version always, if the
    strcase module is available.  */
-#if @REPLACE_STRCASECMP@
-# define strcasecmp rpl_strcasecmp
+#if @GNULIB_STRCASE@
+# if @REPLACE_STRCASECMP@
+#  define strcasecmp rpl_strcasecmp
 extern int strcasecmp (char const *__s1, char const *__s2);
+# endif
+#else
+# define strcasecmp strcasecmp_is_unportable__use_gnulib_module_strcase_for_portability
 #endif
 
 /* Compare no more than N bytes of strings S1 and S2, ignoring case,
    returning less than, equal to or greater than zero if S1 is
    lexicographically less than, equal to or greater than S2.
    Note: This function cannot work correctly in multibyte locales.  */
-#if ! @HAVE_DECL_STRNCASECMP@
+#if @GNULIB_STRCASE@
+# if ! @HAVE_DECL_STRNCASECMP@
 extern int strncasecmp (char const *__s1, char const *__s2, size_t __n);
+# endif
+#else
+# define strncasecmp strncasecmp_is_unportable__use_gnulib_module_strcase_for_portability
 #endif
 
 /* Find the first occurrence of C in S or the final NUL byte.  */
-#if ! @HAVE_STRCHRNUL@
+#if @GNULIB_STRCHRNUL@
+# if ! @HAVE_STRCHRNUL@
 extern char *strchrnul (char const *__s, int __c_in);
+# endif
+#else
+# define strchrnul strchrnul_is_unportable__use_gnulib_module_strchrnul_for_portability
 #endif
 
 /* Duplicate S, returning an identical malloc'd string.  */
-#if ! @HAVE_DECL_STRDUP@ && ! defined strdup
+#if @GNULIB_STRDUP@
+# if ! @HAVE_DECL_STRDUP@ && ! defined strdup
 extern char *strdup (char const *__s);
+# endif
+#else
+# define strdup strdup_is_unportable__use_gnulib_module_strdup_for_portability
 #endif
 
 /* Return a newly allocated copy of at most N bytes of STRING.  */
-#if ! @HAVE_STRNDUP@
-# undef strndup
-# define strndup rpl_strndup
-# if ! @HAVE_DECL_STRNDUP@
+#if @GNULIB_STRNDUP@
+# if ! @HAVE_STRNDUP@
+#  undef strndup
+#  define strndup rpl_strndup
+#  if ! @HAVE_DECL_STRNDUP@
 extern char *strndup (char const *__string, size_t __n);
+#  endif
 # endif
+#else
+# define strndup strndup_is_unportable__use_gnulib_module_strndup_for_portability
 #endif
 
 /* Find the length (number of bytes) of STRING, but scan at most
    MAXLEN bytes.  If no '\0' terminator is found in that many bytes,
    return MAXLEN.  */
-#if ! @HAVE_DECL_STRNLEN@
+#if @GNULIB_STRNLEN@
+# if ! @HAVE_DECL_STRNLEN@
 extern size_t strnlen (char const *__string, size_t __maxlen);
+# endif
+#else
+# define strnlen strnlen_is_unportable__use_gnulib_module_strnlen_for_portability
 #endif
 
 /* Find the first occurrence in S of any character in ACCEPT.  */
-#if ! @HAVE_STRPBRK@
+#if @GNULIB_STRPBRK@
+# if ! @HAVE_STRPBRK@
 extern char *strpbrk (char const *__s, char const *__accept);
+# endif
+#else
+# define strpbrk strpbrk_is_unportable__use_gnulib_module_strpbrk_for_portability
 #endif
 
 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
@@ -124,28 +172,40 @@ extern char *strpbrk (char const *__s, char const *__accept);
            characters are ASCII characters < 0x30.
 
    See also strtok_r().  */
-#if ! @HAVE_STRSEP@
+#if @GNULIB_STRSEP@
+# if ! @HAVE_STRSEP@
 extern char *strsep (char **restrict __stringp, char const *restrict __delim);
+# endif
+#else
+# define strsep strsep_is_unportable__use_gnulib_module_strsep_for_portability
 #endif
 
 /* Find the first occurrence of NEEDLE in HAYSTACK.
    No known system has a strstr() function that works correctly in
    multibyte locales.  Therefore use our version always, if the strstr
    module is available.  */
-#if @REPLACE_STRSTR@
-# undef strstr
-# define strstr rpl_strstr
+#if @GNULIB_STRSTR@
+# if @REPLACE_STRSTR@
+#  undef strstr
+#  define strstr rpl_strstr
 extern char *strstr (char const *__haystack, char const *__needle);
+# endif
+#else
+# define strstr strstr_is_unportable__use_gnulib_module_strstr_for_portability
 #endif
 
 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
    comparison.
    Note: This function may, in multibyte locales, return success even if
    strlen (haystack) < strlen (needle) !  */
-#if @REPLACE_STRCASESTR@
-# undef strcasestr
-# define strcasestr rpl_strcasestr
+#if @GNULIB_STRCASESTR@
+# if @REPLACE_STRCASESTR@
+#  undef strcasestr
+#  define strcasestr rpl_strcasestr
 extern char *strcasestr (const char *haystack, const char *needle);
+# endif
+#else
+# define strcasestr strcasestr_is_unportable__use_gnulib_module_strcasestr_for_portability
 #endif
 
 /* Parse S into tokens separated by characters in DELIM.
@@ -170,9 +230,13 @@ extern char *strcasestr (const char *haystack, const char *needle);
            characters are ASCII characters < 0x30.
 
    See also strsep().  */
-#if ! @HAVE_DECL_STRTOK_R@
+#if @GNULIB_STRTOK_R@
+# if ! @HAVE_DECL_STRTOK_R@
 extern char *strtok_r (char *restrict __s, char const *restrict __sep,
                       char **restrict __lasts);
+# endif
+#else
+# define strtok_r strtok_r_is_unportable__use_gnulib_module_strtok_r_for_portability
 #endif
 
 #ifdef __cplusplus
index 2e8b29838af4bd71a60d1bd62e78f01362e328ec..4586391ea5df6b97a991ab66f53103d42ca40f89 100644 (file)
@@ -10,6 +10,7 @@ string
 
 configure.ac:
 gl_FUNC_MEMMEM
+gl_STRING_MODULE_INDICATOR([memmem])
 
 Makefile.am:
 
index fc093deb3cd39690fb504bb087c103b86aef24db..a49c40ad296bab0f49e128e1021918aa26841d9e 100644 (file)
@@ -10,6 +10,7 @@ string
 
 configure.ac:
 gl_FUNC_MEMPCPY
+gl_STRING_MODULE_INDICATOR([mempcpy])
 
 Makefile.am:
 
index 039b1325d5511b82aed54fd1327f5488efc4f808..54912ccb0b0342653ccc1c1559b47b203bd51225 100644 (file)
@@ -10,6 +10,7 @@ string
 
 configure.ac:
 gl_FUNC_MEMRCHR
+gl_STRING_MODULE_INDICATOR([memrchr])
 
 Makefile.am:
 
index d30c1cf6f72837ff8e4640e11414aec06eaa9c9e..de70b1029281aaccd22201df039e830eb06d0a08 100644 (file)
@@ -10,6 +10,7 @@ string
 
 configure.ac:
 gl_FUNC_STPCPY
+gl_STRING_MODULE_INDICATOR([stpcpy])
 
 Makefile.am:
 
index 87847103d7533d2fd28f959bc3b06246265a7358..6453c80943ffc0812f6bc88ae1ea70222381a983 100644 (file)
@@ -10,6 +10,7 @@ string
 
 configure.ac:
 gl_FUNC_STPNCPY
+gl_STRING_MODULE_INDICATOR([stpncpy])
 
 Makefile.am:
 
index 05c1c921c3155a41070f7a1ea598658a09552d70..77d2f2c7466148c1bdd989384573660241411531 100644 (file)
@@ -13,6 +13,7 @@ string
 
 configure.ac:
 gl_STRCASE
+gl_STRING_MODULE_INDICATOR([strcase])
 
 Makefile.am:
 
index ed7dea72da879e930a70f4dbc5ee6dd6c6435b0d..4a9b922e3cede4a3ef0c78255cfd37b17897be06 100644 (file)
@@ -12,6 +12,7 @@ string
 
 configure.ac:
 gl_FUNC_STRCASESTR
+gl_STRING_MODULE_INDICATOR([strcasestr])
 
 Makefile.am:
 
index ee2307ac3d76fc63b724169aabef6848c616dd15..d79d63eb0229911c4812a1f6b0a38b0dc36779e9 100644 (file)
@@ -10,6 +10,7 @@ string
 
 configure.ac:
 gl_FUNC_STRCHRNUL
+gl_STRING_MODULE_INDICATOR([strchrnul])
 
 Makefile.am:
 
index e267a68a3a56569aaa45012cbdad76f3f8918af9..b953f0fa616dc062feadb176971c0bee9e1a80e3 100644 (file)
@@ -10,6 +10,7 @@ string
 
 configure.ac:
 gl_FUNC_STRDUP
+gl_STRING_MODULE_INDICATOR([strdup])
 
 Makefile.am:
 
index 313613f1820284c65b3672d63e6e4efd163ed16d..526fdebd7fa5626c05040e05efabed3a8eeb12d7 100644 (file)
@@ -21,6 +21,22 @@ string.h: string_.h
        rm -f $@-t $@
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
          sed -e 's|@''ABSOLUTE_STRING_H''@|$(ABSOLUTE_STRING_H)|g' \
+             -e 's|@''GNULIB_MEMMEM''@|$(GNULIB_MEMMEM)|g' \
+             -e 's|@''GNULIB_MEMPCPY''@|$(GNULIB_MEMPCPY)|g' \
+             -e 's|@''GNULIB_MEMRCHR''@|$(GNULIB_MEMRCHR)|g' \
+             -e 's|@''GNULIB_STPCPY''@|$(GNULIB_STPCPY)|g' \
+             -e 's|@''GNULIB_STPNCPY''@|$(GNULIB_STPNCPY)|g' \
+             -e 's|@''GNULIB_STRCASE''@|$(GNULIB_STRCASE)|g' \
+             -e 's|@''GNULIB_STRCASE''@|$(GNULIB_STRCASE)|g' \
+             -e 's|@''GNULIB_STRCHRNUL''@|$(GNULIB_STRCHRNUL)|g' \
+             -e 's|@''GNULIB_STRDUP''@|$(GNULIB_STRDUP)|g' \
+             -e 's|@''GNULIB_STRNDUP''@|$(GNULIB_STRNDUP)|g' \
+             -e 's|@''GNULIB_STRNLEN''@|$(GNULIB_STRNLEN)|g' \
+             -e 's|@''GNULIB_STRPBRK''@|$(GNULIB_STRPBRK)|g' \
+             -e 's|@''GNULIB_STRSEP''@|$(GNULIB_STRSEP)|g' \
+             -e 's|@''GNULIB_STRSTR''@|$(GNULIB_STRSTR)|g' \
+             -e 's|@''GNULIB_STRCASESTR''@|$(GNULIB_STRCASESTR)|g' \
+             -e 's|@''GNULIB_STRTOK_R''@|$(GNULIB_STRTOK_R)|g' \
              -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \
              -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \
              -e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \
index 7246e0af086622590ce79fa614f6d87e638f157b..cfe0dd0c602c47e8db03c8344921011ff52fbe9f 100644 (file)
@@ -11,6 +11,7 @@ strnlen
 
 configure.ac:
 gl_FUNC_STRNDUP
+gl_STRING_MODULE_INDICATOR([strndup])
 
 Makefile.am:
 
index 56f20512b064cce724ee3fe6eeffcd67d6e31d4f..3cc071126eb608500dff7302a208d7e59aa1fb86 100644 (file)
@@ -11,6 +11,7 @@ string
 
 configure.ac:
 gl_FUNC_STRNLEN
+gl_STRING_MODULE_INDICATOR([strnlen])
 
 Makefile.am:
 
index 1222c00b942b5b29a99aac3db235faf0632546f1..016a5795af926508a92a9a65e1c7526bfa4397f4 100644 (file)
@@ -10,6 +10,7 @@ string
 
 configure.ac:
 gl_FUNC_STRPBRK
+gl_STRING_MODULE_INDICATOR([strpbrk])
 
 Makefile.am:
 
index 3510fbacaf7b6fd5b43d629af9b72ac0b76e5a8d..4503a071ca09d9ba03d00cdb3263979057725a39 100644 (file)
@@ -11,6 +11,7 @@ strpbrk
 
 configure.ac:
 gl_FUNC_STRSEP
+gl_STRING_MODULE_INDICATOR([strsep])
 
 Makefile.am:
 
index f4868a4f567d9f73c21411630a11732b6a974c5b..5e3f9fd477d4c96595f63f5113c68e825943eb21 100644 (file)
@@ -12,6 +12,7 @@ string
 
 configure.ac:
 gl_FUNC_STRSTR
+gl_STRING_MODULE_INDICATOR([strstr])
 
 Makefile.am:
 
index e5691d483aed57d1c224f53d36724ff052ecdcec..cfcd0146262aae9e6e389e162b0fe3cfd91ee0b0 100644 (file)
@@ -10,6 +10,7 @@ string
 
 configure.ac:
 gl_FUNC_STRTOK_R
+gl_STRING_MODULE_INDICATOR([strtok_r])
 
 Makefile.am: