From: Bruno Haible Date: Sat, 10 Apr 2010 09:29:14 +0000 (+0200) Subject: strnlen: Fix warning in C++ mode on MacOS X. X-Git-Tag: v0.1~4293 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=ccf404b1021c4d59c32878e9c4d81e3a551c5ffb;p=gnulib.git strnlen: Fix warning in C++ mode on MacOS X. --- diff --git a/ChangeLog b/ChangeLog index e89c1083c..c1810bab6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2010-04-10 Bruno Haible + + strnlen: Fix warning in C++ mode on MacOS X. + * lib/string.in.h (strnlen): Use the modern idiom. + * m4/strnlen.m4 (gl_FUNC_STRNLEN): Set REPLACE_STRNLEN to 1, instead of + defining strnlen as a macro already in . + * m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Initialize + REPLACE_STRNLEN. + * modules/string (Makefile.am): Substitute REPLACE_STRNLEN. + Reported by Jarno Rajahalme . + 2010-04-08 James Youngman * doc/manywarnings.texi (manywarnings): Add missing parenthesis in diff --git a/lib/string.in.h b/lib/string.in.h index 6712256f2..de446b47a 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -372,12 +372,23 @@ _GL_WARN_ON_USE (strndup, "strndup is unportable - " MAXLEN bytes. If no '\0' terminator is found in that many bytes, return MAXLEN. */ #if @GNULIB_STRNLEN@ -# if ! @HAVE_DECL_STRNLEN@ +# if @REPLACE_STRNLEN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strnlen +# define strnlen rpl_strnlen +# endif +_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen) + __attribute__ ((__pure__)) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)); +# else +# if ! @HAVE_DECL_STRNLEN@ _GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen) __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1))); -# endif +# endif _GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)); +# endif _GL_CXXALIASWARN (strnlen); #elif defined GNULIB_POSIXCHECK # undef strnlen diff --git a/m4/string_h.m4 b/m4/string_h.m4 index cf26123e2..1977aecf9 100644 --- a/m4/string_h.m4 +++ b/m4/string_h.m4 @@ -5,7 +5,7 @@ # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. -# serial 16 +# serial 17 # Written by Paul Eggert. @@ -105,6 +105,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], REPLACE_STRERROR=0; AC_SUBST([REPLACE_STRERROR]) REPLACE_STRNCAT=0; AC_SUBST([REPLACE_STRNCAT]) REPLACE_STRNDUP=0; AC_SUBST([REPLACE_STRNDUP]) + REPLACE_STRNLEN=0; AC_SUBST([REPLACE_STRNLEN]) REPLACE_STRSIGNAL=0; AC_SUBST([REPLACE_STRSIGNAL]) REPLACE_STRTOK_R=0; AC_SUBST([REPLACE_STRTOK_R]) UNDEFINE_STRTOK_R=0; AC_SUBST([UNDEFINE_STRTOK_R]) diff --git a/m4/strnlen.m4 b/m4/strnlen.m4 index cd48948f6..fabce50ba 100644 --- a/m4/strnlen.m4 +++ b/m4/strnlen.m4 @@ -1,4 +1,4 @@ -# strnlen.m4 serial 10 +# strnlen.m4 serial 11 dnl Copyright (C) 2002-2003, 2005-2007, 2009-2010 Free Software Foundation, dnl Inc. dnl This file is free software; the Free Software Foundation @@ -7,10 +7,11 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_FUNC_STRNLEN], [ + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + dnl Persuade glibc to declare strnlen(). AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) - AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) AC_CHECK_DECLS_ONCE([strnlen]) if test $ac_cv_have_decl_strnlen = no; then HAVE_DECL_STRNLEN=0 @@ -18,12 +19,11 @@ AC_DEFUN([gl_FUNC_STRNLEN], AC_FUNC_STRNLEN if test $ac_cv_func_strnlen_working = no; then + REPLACE_STRNLEN=1 # This is necessary because automake-1.6.1 doesn't understand # that the above use of AC_FUNC_STRNLEN means we may have to use # lib/strnlen.c. #AC_LIBOBJ([strnlen]) - AC_DEFINE([strnlen], [rpl_strnlen], - [Define to rpl_strnlen if the replacement function should be used.]) gl_PREREQ_STRNLEN fi ]) diff --git a/modules/string b/modules/string index 959670af4..c02cef67e 100644 --- a/modules/string +++ b/modules/string @@ -89,6 +89,7 @@ string.h: string.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \ -e 's|@''REPLACE_STRNCAT''@|$(REPLACE_STRNCAT)|g' \ -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|g' \ + -e 's|@''REPLACE_STRNLEN''@|$(REPLACE_STRNLEN)|g' \ -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \ -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \ -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \