diff options
author | Simon Josefsson <simon@josefsson.org> | 2007-02-04 11:28:18 +0000 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2007-02-04 11:28:18 +0000 |
commit | 37b20a82c3aac17b4559b6195180ed413d5e6622 (patch) | |
tree | 82008c106b318964dc5955de680df3f5ad0f3df8 | |
parent | 673da70556585c697380d470058cdde630dc00a6 (diff) | |
download | gnutls-37b20a82c3aac17b4559b6195180ed413d5e6622.tar.gz |
Update.
-rw-r--r-- | gl/gai_strerror.c | 1 | ||||
-rw-r--r-- | gl/gnulib.mk | 19 | ||||
-rw-r--r-- | gl/m4/gnulib-comp.m4 | 3 | ||||
-rw-r--r-- | gl/m4/socklen.m4 | 6 | ||||
-rw-r--r-- | gl/m4/string_h.m4 | 27 | ||||
-rw-r--r-- | gl/string_.h | 170 | ||||
-rw-r--r-- | lgl/Makefile.am | 15 | ||||
-rw-r--r-- | lgl/m4/gnulib-comp.m4 | 1 | ||||
-rw-r--r-- | lgl/m4/socklen.m4 | 6 | ||||
-rw-r--r-- | lgl/m4/string_h.m4 | 27 | ||||
-rw-r--r-- | lgl/string_.h | 170 |
11 files changed, 387 insertions, 58 deletions
diff --git a/gl/gai_strerror.c b/gl/gai_strerror.c index 7f0e034e66..aa733d6cc3 100644 --- a/gl/gai_strerror.c +++ b/gl/gai_strerror.c @@ -52,6 +52,7 @@ values[] = { EAI_SERVICE, N_("Servname not supported for ai_socktype") }, { EAI_SOCKTYPE, N_("ai_socktype not supported") }, { EAI_SYSTEM, N_("System error") }, + { EAI_OVERFLOW, N_("Argument buffer too small") }, #ifdef __USE_GNU { EAI_INPROGRESS, N_("Processing request in progress") }, { EAI_CANCELED, N_("Request canceled") }, diff --git a/gl/gnulib.mk b/gl/gnulib.mk index 85c3104bdc..a1e584fb53 100644 --- a/gl/gnulib.mk +++ b/gl/gnulib.mk @@ -29,7 +29,7 @@ BUILT_SOURCES += $(ARPA_INET_H) # We need the following in order to create <arpa/inet.h> when the system # doesn't have one. arpa/inet.h: - test -d arpa || mkdir arpa + @MKDIR_P@ arpa rm -f $@-t $@ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ echo '#include <sys/socket.h>'; \ @@ -107,7 +107,7 @@ BUILT_SOURCES += $(NETINET_IN_H) # We need the following in order to create <netinet/in.h> when the system # doesn't have one. netinet/in.h: - test -d netinet || mkdir netinet + @MKDIR_P@ netinet rm -f $@-t $@ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ echo '#include <sys/socket.h>'; \ @@ -164,6 +164,21 @@ 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_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' \ diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 index e2bf48a432..356948cf01 100644 --- a/gl/m4/gnulib-comp.m4 +++ b/gl/m4/gnulib-comp.m4 @@ -41,6 +41,7 @@ AC_DEFUN([gl_INIT], gl_cond_libtool=true gl_source_base='gl' gl_HEADER_ARPA_INET + AC_PROG_MKDIR_P dnl gl_USE_SYSTEM_EXTENSIONS must be added quite early to configure.ac. gl_GETADDRINFO gl_FUNC_GETDELIM @@ -49,10 +50,12 @@ AC_DEFUN([gl_INIT], gl_INET_NTOP gl_INET_PTON gl_HEADER_NETINET_IN + AC_PROG_MKDIR_P gl_FUNC_READLINE gl_TYPE_SOCKLEN_T AM_STDBOOL_H gl_FUNC_STRDUP + gl_STRING_MODULE_INDICATOR([strdup]) gl_HEADER_STRING_H gl_HEADER_SYS_SOCKET AC_PROG_MKDIR_P diff --git a/gl/m4/socklen.m4 b/gl/m4/socklen.m4 index 5e3765a64b..e824a09f56 100644 --- a/gl/m4/socklen.m4 +++ b/gl/m4/socklen.m4 @@ -1,5 +1,5 @@ -# socklen.m4 serial 4 -dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc. +# socklen.m4 serial 5 +dnl Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -19,7 +19,7 @@ AC_DEFUN([gl_TYPE_SOCKLEN_T], [AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl AC_CHECK_TYPE([socklen_t], , [AC_MSG_CHECKING([for socklen_t equivalent]) - AC_CACHE_VAL([gl_cv_gl_cv_socklen_t_equiv], + AC_CACHE_VAL([gl_cv_socklen_t_equiv], [# Systems have either "struct sockaddr *" or # "void *" as the second argument to getpeername gl_cv_socklen_t_equiv= diff --git a/gl/m4/string_h.m4 b/gl/m4/string_h.m4 index 84db7a59ba..8e0be44f85 100644 --- a/gl/m4/string_h.m4 +++ b/gl/m4/string_h.m4 @@ -18,6 +18,7 @@ AC_DEFUN([gl_HEADER_STRING_H_BODY], [ AC_REQUIRE([AC_C_RESTRICT]) AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + AC_REQUIRE([gl_STRING_MODULE_INDICATOR_DEFAULTS]) gl_ABSOLUTE_HEADER([string.h]) ABSOLUTE_STRING_H=\"$gl_cv_absolute_string_h\" AC_SUBST([ABSOLUTE_STRING_H]) @@ -44,3 +45,29 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR]) REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR]) ]) + +AC_DEFUN([gl_STRING_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_STRING_MODULE_INDICATOR_DEFAULTS]) + GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 +]) + +AC_DEFUN([gl_STRING_MODULE_INDICATOR_DEFAULTS], +[ + GNULIB_MEMMEM=0; AC_SUBST([GNULIB_MEMMEM]) + GNULIB_MEMPCPY=0; AC_SUBST([GNULIB_MEMPCPY]) + GNULIB_MEMRCHR=0; AC_SUBST([GNULIB_MEMRCHR]) + GNULIB_STPCPY=0; AC_SUBST([GNULIB_STPCPY]) + GNULIB_STPNCPY=0; AC_SUBST([GNULIB_STPNCPY]) + GNULIB_STRCASE=0; AC_SUBST([GNULIB_STRCASE]) + GNULIB_STRCHRNUL=0; AC_SUBST([GNULIB_STRCHRNUL]) + GNULIB_STRDUP=0; AC_SUBST([GNULIB_STRDUP]) + GNULIB_STRNDUP=0; AC_SUBST([GNULIB_STRNDUP]) + GNULIB_STRNLEN=0; AC_SUBST([GNULIB_STRNLEN]) + GNULIB_STRPBRK=0; AC_SUBST([GNULIB_STRPBRK]) + GNULIB_STRSEP=0; AC_SUBST([GNULIB_STRSEP]) + GNULIB_STRSTR=0; AC_SUBST([GNULIB_STRSTR]) + GNULIB_STRCASESTR=0; AC_SUBST([GNULIB_STRCASESTR]) + GNULIB_STRTOK_R=0; AC_SUBST([GNULIB_STRTOK_R]) +]) diff --git a/gl/string_.h b/gl/string_.h index 94d991cf06..3947241815 100644 --- a/gl/string_.h +++ b/gl/string_.h @@ -21,39 +21,95 @@ #include @ABSOLUTE_STRING_H@ + +/* GL_LINK_WARNING("literal string") arranges to emit the literal string as + a linker warning on most glibc systems. + We use a linker warning rather than a preprocessor warning, because + #warning cannot be used inside macros. */ +#ifndef GL_LINK_WARNING + /* This works on platforms with GNU ld and ELF object format. + Testing __GLIBC__ is sufficient for asserting that GNU ld is in use. + Testing __ELF__ guarantees the ELF object format. + Testing __GNUC__ is necessary for the compound expression syntax. */ +# if defined __GLIBC__ && defined __ELF__ && defined __GNUC__ +# define GL_LINK_WARNING(message) \ + GL_LINK_WARNING1 (__FILE__, __LINE__, message) +# define GL_LINK_WARNING1(file, line, message) \ + GL_LINK_WARNING2 (file, line, message) /* macroexpand file and line */ +# define GL_LINK_WARNING2(file, line, message) \ + GL_LINK_WARNING3 (file ":" #line ": " message) +# define GL_LINK_WARNING3(message) \ + ({ static const char warning[sizeof (message)] \ + __attribute__ ((__unused__, \ + __section__ (".gnu.warning"), \ + __aligned__ (1))) \ + = message "\n"; \ + (void)0; \ + }) +# else +# define GL_LINK_WARNING(message) ((void) 0) +# endif +#endif + + #ifdef __cplusplus 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 +#elif defined GNULIB_POSIXCHECK +# undef memmem +# 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 +#elif defined GNULIB_POSIXCHECK +# undef mempcpy +# 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 +#elif defined GNULIB_POSIXCHECK +# undef memrchr +# 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 +#elif defined GNULIB_POSIXCHECK +# undef stpcpy +# 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 +#elif defined GNULIB_POSIXCHECK +# undef stpncpy +# 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 +120,88 @@ 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 +#elif defined GNULIB_POSIXCHECK +# undef strcasecmp +# define strcasecmp(a,b) \ + (GL_LINK_WARNING ("strcasecmp is often incorrectly implemented for multibyte locales - use gnulib module 'strcase' for correct and portable internationalization"), \ + strcasecmp (a, b)) #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 +#endif +#if defined GNULIB_POSIXCHECK +# undef strncasecmp +# define strncasecmp(a,b) \ + (GL_LINK_WARNING ("strncasecmp cannot work correctly in multibyte locales - don't use it if you care about internationalization"), \ + strncasecmp (a, b)) #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 +#elif defined GNULIB_POSIXCHECK +# undef strchrnul +# 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 +#elif defined GNULIB_POSIXCHECK +# undef strdup +# 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 +#elif defined GNULIB_POSIXCHECK +# undef strndup +# 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 +#elif defined GNULIB_POSIXCHECK +# undef strnlen +# 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 +#elif defined GNULIB_POSIXCHECK +# undef strpbrk +# 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 +220,47 @@ 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 +#elif defined GNULIB_POSIXCHECK +# undef strsep +# 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 +#elif defined GNULIB_POSIXCHECK +# undef strstr +# define strstr(a,b) \ + (GL_LINK_WARNING ("strstr is often incorrectly implemented for multibyte locales - use gnulib module 'strstr' for correct and portable internationalization"), \ + strstr (a, b)) #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 +#elif defined GNULIB_POSIXCHECK +# undef strcasestr +# define strcasestr(a,b) \ + (GL_LINK_WARNING ("strcasestr is often incorrectly implemented for multibyte locales - use gnulib module 'strcasestr' for correct and portable internationalization"), \ + strcasestr (a, b)) #endif /* Parse S into tokens separated by characters in DELIM. @@ -170,9 +285,14 @@ 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 +#elif defined GNULIB_POSIXCHECK +# undef strtok_r +# define strtok_r strtok_r_is_unportable__use_gnulib_module_strtok_r_for_portability #endif #ifdef __cplusplus diff --git a/lgl/Makefile.am b/lgl/Makefile.am index 7db8b8dc8e..c977a161ba 100644 --- a/lgl/Makefile.am +++ b/lgl/Makefile.am @@ -281,6 +281,21 @@ 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_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' \ diff --git a/lgl/m4/gnulib-comp.m4 b/lgl/m4/gnulib-comp.m4 index 3ebad02bf5..87028debd9 100644 --- a/lgl/m4/gnulib-comp.m4 +++ b/lgl/m4/gnulib-comp.m4 @@ -74,6 +74,7 @@ AC_DEFUN([lgl_INIT], AM_GNU_GETTEXT_VERSION([0.15]) gl_MD2 gl_FUNC_MEMMEM + gl_STRING_MODULE_INDICATOR([memmem]) gl_FUNC_MEMMOVE gl_MINMAX gl_FUNC_READ_FILE diff --git a/lgl/m4/socklen.m4 b/lgl/m4/socklen.m4 index 5e3765a64b..e824a09f56 100644 --- a/lgl/m4/socklen.m4 +++ b/lgl/m4/socklen.m4 @@ -1,5 +1,5 @@ -# socklen.m4 serial 4 -dnl Copyright (C) 2005, 2006 Free Software Foundation, Inc. +# socklen.m4 serial 5 +dnl Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -19,7 +19,7 @@ AC_DEFUN([gl_TYPE_SOCKLEN_T], [AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl AC_CHECK_TYPE([socklen_t], , [AC_MSG_CHECKING([for socklen_t equivalent]) - AC_CACHE_VAL([gl_cv_gl_cv_socklen_t_equiv], + AC_CACHE_VAL([gl_cv_socklen_t_equiv], [# Systems have either "struct sockaddr *" or # "void *" as the second argument to getpeername gl_cv_socklen_t_equiv= diff --git a/lgl/m4/string_h.m4 b/lgl/m4/string_h.m4 index 84db7a59ba..8e0be44f85 100644 --- a/lgl/m4/string_h.m4 +++ b/lgl/m4/string_h.m4 @@ -18,6 +18,7 @@ AC_DEFUN([gl_HEADER_STRING_H_BODY], [ AC_REQUIRE([AC_C_RESTRICT]) AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + AC_REQUIRE([gl_STRING_MODULE_INDICATOR_DEFAULTS]) gl_ABSOLUTE_HEADER([string.h]) ABSOLUTE_STRING_H=\"$gl_cv_absolute_string_h\" AC_SUBST([ABSOLUTE_STRING_H]) @@ -44,3 +45,29 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], REPLACE_STRSTR=0; AC_SUBST([REPLACE_STRSTR]) REPLACE_STRCASESTR=0; AC_SUBST([REPLACE_STRCASESTR]) ]) + +AC_DEFUN([gl_STRING_MODULE_INDICATOR], +[ + dnl Use AC_REQUIRE here, so that the default settings are expanded once only. + AC_REQUIRE([gl_STRING_MODULE_INDICATOR_DEFAULTS]) + GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1 +]) + +AC_DEFUN([gl_STRING_MODULE_INDICATOR_DEFAULTS], +[ + GNULIB_MEMMEM=0; AC_SUBST([GNULIB_MEMMEM]) + GNULIB_MEMPCPY=0; AC_SUBST([GNULIB_MEMPCPY]) + GNULIB_MEMRCHR=0; AC_SUBST([GNULIB_MEMRCHR]) + GNULIB_STPCPY=0; AC_SUBST([GNULIB_STPCPY]) + GNULIB_STPNCPY=0; AC_SUBST([GNULIB_STPNCPY]) + GNULIB_STRCASE=0; AC_SUBST([GNULIB_STRCASE]) + GNULIB_STRCHRNUL=0; AC_SUBST([GNULIB_STRCHRNUL]) + GNULIB_STRDUP=0; AC_SUBST([GNULIB_STRDUP]) + GNULIB_STRNDUP=0; AC_SUBST([GNULIB_STRNDUP]) + GNULIB_STRNLEN=0; AC_SUBST([GNULIB_STRNLEN]) + GNULIB_STRPBRK=0; AC_SUBST([GNULIB_STRPBRK]) + GNULIB_STRSEP=0; AC_SUBST([GNULIB_STRSEP]) + GNULIB_STRSTR=0; AC_SUBST([GNULIB_STRSTR]) + GNULIB_STRCASESTR=0; AC_SUBST([GNULIB_STRCASESTR]) + GNULIB_STRTOK_R=0; AC_SUBST([GNULIB_STRTOK_R]) +]) diff --git a/lgl/string_.h b/lgl/string_.h index 617a51b9df..b99461a0b3 100644 --- a/lgl/string_.h +++ b/lgl/string_.h @@ -21,39 +21,95 @@ #include @ABSOLUTE_STRING_H@ + +/* GL_LINK_WARNING("literal string") arranges to emit the literal string as + a linker warning on most glibc systems. + We use a linker warning rather than a preprocessor warning, because + #warning cannot be used inside macros. */ +#ifndef GL_LINK_WARNING + /* This works on platforms with GNU ld and ELF object format. + Testing __GLIBC__ is sufficient for asserting that GNU ld is in use. + Testing __ELF__ guarantees the ELF object format. + Testing __GNUC__ is necessary for the compound expression syntax. */ +# if defined __GLIBC__ && defined __ELF__ && defined __GNUC__ +# define GL_LINK_WARNING(message) \ + GL_LINK_WARNING1 (__FILE__, __LINE__, message) +# define GL_LINK_WARNING1(file, line, message) \ + GL_LINK_WARNING2 (file, line, message) /* macroexpand file and line */ +# define GL_LINK_WARNING2(file, line, message) \ + GL_LINK_WARNING3 (file ":" #line ": " message) +# define GL_LINK_WARNING3(message) \ + ({ static const char warning[sizeof (message)] \ + __attribute__ ((__unused__, \ + __section__ (".gnu.warning"), \ + __aligned__ (1))) \ + = message "\n"; \ + (void)0; \ + }) +# else +# define GL_LINK_WARNING(message) ((void) 0) +# endif +#endif + + #ifdef __cplusplus 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 +#elif defined GNULIB_POSIXCHECK +# undef memmem +# 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 +#elif defined GNULIB_POSIXCHECK +# undef mempcpy +# 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 +#elif defined GNULIB_POSIXCHECK +# undef memrchr +# 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 +#elif defined GNULIB_POSIXCHECK +# undef stpcpy +# 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 +#elif defined GNULIB_POSIXCHECK +# undef stpncpy +# 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 +120,88 @@ 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 +#elif defined GNULIB_POSIXCHECK +# undef strcasecmp +# define strcasecmp(a,b) \ + (GL_LINK_WARNING ("strcasecmp is often incorrectly implemented for multibyte locales - use gnulib module 'strcase' for correct and portable internationalization"), \ + strcasecmp (a, b)) #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 +#endif +#if defined GNULIB_POSIXCHECK +# undef strncasecmp +# define strncasecmp(a,b) \ + (GL_LINK_WARNING ("strncasecmp cannot work correctly in multibyte locales - don't use it if you care about internationalization"), \ + strncasecmp (a, b)) #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 +#elif defined GNULIB_POSIXCHECK +# undef strchrnul +# 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 +#elif defined GNULIB_POSIXCHECK +# undef strdup +# 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 +#elif defined GNULIB_POSIXCHECK +# undef strndup +# 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 +#elif defined GNULIB_POSIXCHECK +# undef strnlen +# 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 +#elif defined GNULIB_POSIXCHECK +# undef strpbrk +# 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 +220,47 @@ 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 +#elif defined GNULIB_POSIXCHECK +# undef strsep +# 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 +#elif defined GNULIB_POSIXCHECK +# undef strstr +# define strstr(a,b) \ + (GL_LINK_WARNING ("strstr is often incorrectly implemented for multibyte locales - use gnulib module 'strstr' for correct and portable internationalization"), \ + strstr (a, b)) #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 +#elif defined GNULIB_POSIXCHECK +# undef strcasestr +# define strcasestr(a,b) \ + (GL_LINK_WARNING ("strcasestr is often incorrectly implemented for multibyte locales - use gnulib module 'strcasestr' for correct and portable internationalization"), \ + strcasestr (a, b)) #endif /* Parse S into tokens separated by characters in DELIM. @@ -170,9 +285,14 @@ 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 +#elif defined GNULIB_POSIXCHECK +# undef strtok_r +# define strtok_r strtok_r_is_unportable__use_gnulib_module_strtok_r_for_portability #endif #ifdef __cplusplus |