From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21979 invoked by alias); 14 May 2005 16:17:50 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 21946 invoked from network); 14 May 2005 16:17:36 -0000 Received: from unknown (HELO romy.inter.net.il) (192.114.186.66) by sourceware.org with SMTP; 14 May 2005 16:17:36 -0000 Received: from zaretski (IGLD-84-228-245-50.inter.net.il [84.228.245.50]) by romy.inter.net.il (MOS 3.5.6-GR) with ESMTP id BFK00282 (AUTH halo1); Sat, 14 May 2005 19:17:32 +0300 (IDT) Date: Sat, 14 May 2005 19:43:00 -0000 From: "Eli Zaretskii" To: gcc-patches@gcc.gnu.org Message-ID: <01c558a0$Blat.v2.4$2b06ba40@zahav.net.il> Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=ISO-8859-1 CC: gdb-patches@sourceware.org, binutils@sourceware.org In-reply-to: <20050514141204.GA10684@nevyn.them.org> (message from Daniel Jacobowitz on Sat, 14 May 2005 10:12:04 -0400) Subject: Re: [RFA] Eliminate warnings about snprintf declaration Reply-to: Eli Zaretskii References: <41994B9D.9080809@gnu.org> <01c55702$Blat.v2.4$d4764900@zahav.net.il> <20050512150804.GA1808@nevyn.them.org> <01c55708$Blat.v2.4$cfc9f040@zahav.net.il> <20050512154716.GA3513@nevyn.them.org> <01c5570e$Blat.v2.4$1c533160@zahav.net.il> <20050512162453.GA5180@nevyn.them.org> <01c55732$Blat.v2.4$e9bd3640@zahav.net.il> <20050512205103.GB13519@nevyn.them.org> <01c5586c$Blat.v2.4$a7dfc720@zahav.net.il> <20050514141204.GA10684@nevyn.them.org> X-SW-Source: 2005-05/txt/msg00350.txt.bz2 > Date: Sat, 14 May 2005 10:12:04 -0400 > From: Daniel Jacobowitz > Cc: gcc-patches@gcc.gnu.org, gdb-patches@sources.redhat.com > > > Actually, I found that a simpler patch to include/libiberty.h (below) > > is all that is needed to fix all the warnings about snprintf and > > vsnprintf. libiberty.h already does that for asprintf and vasprintf, > > so I think we can use the same method for snprintf and vsnprintf; no > > need to change any configure.ac files. > > > 2005-05-14 Eli Zaretskii > > > > * libiberty.h: (snprintf) [!HAVE_DECL_SNPRINTF]: Declare if > > needed. > > (vsnprintf) [!HAVE_DECL_VSNPRINTF]: Declare if needed. > > Note that this will only work if there are no systems which declare > snprintf with an incorrect prototype. For instance, a missing const on > the format string in a system header would now generate an error. For > asprintf this isn't an issue, because it's not a standard function; > it's only provided by glibc. Actually, what I wrote was completely bogus: without adding these functions to AC_CHECK_DECLS, the respective HAVE_DECL_* macros will never get defined, so what I suggested is equivalent to including these prototypes unconditionally, which is certainly not what I meant. Sorry. Here's a revised patch, now together with the configury stuff. include/ChangeLog: 2005-05-14 Eli Zaretskii * libiberty.h: (snprintf) [!HAVE_DECL_SNPRINTF]: Declare if needed. (vsnprintf) [!HAVE_DECL_VSNPRINTF]: Declare if needed. bfd/ChangeLog: 2005-05-14 Eli Zaretskii * configure.in: Add snprintf and vsnprintf to AC_CHECK_DECLS. gdb/ChangeLog: 2005-05-14 Eli Zaretskii * configure.ac: Add snprintf and vsnprintf to AC_CHECK_DECLS. Index: include/libiberty.h =================================================================== RCS file: /cvs/src/src/include/libiberty.h,v retrieving revision 1.44 diff -u -r1.44 libiberty.h --- include/libiberty.h 12 May 2005 20:00:35 -0000 1.44 +++ include/libiberty.h 14 May 2005 16:09:49 -0000 @@ -531,6 +531,16 @@ ATTRIBUTE_PRINTF(2,0); #endif +#if defined(HAVE_DECL_SNPRINTF) && !HAVE_DECL_SNPRINTF +/* Like sprintf but prints at most N characters. */ +extern int snprintf (char *, size_t, const char *, ...) ATTRIBUTE_PRINTF_3; +#endif + +#if defined(HAVE_DECL_VSNPRINTF) && !HAVE_DECL_VSNPRINTF +/* Like vsprintf but prints at most N characters. */ +extern int vsnprintf (char *, size_t, const char *, va_list); +#endif + #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) /* Drastically simplified alloca configurator. If we're using GCC, Index: bfd/configure.in =================================================================== RCS file: /cvs/src/src/bfd/configure.in,v retrieving revision 1.183 diff -u -r1.183 configure.in --- bfd/configure.in 10 May 2005 01:27:53 -0000 1.183 +++ bfd/configure.in 14 May 2005 16:10:11 -0000 @@ -144,6 +144,8 @@ AC_CHECK_DECLS(realloc) AC_CHECK_DECLS(stpcpy) AC_CHECK_DECLS(strstr) +AC_CHECK_DECLS(snprintf) +AC_CHECK_DECLS(vsnprintf) # If we are configured native, pick a core file support file. COREFILE= Index: gdb/configure.ac =================================================================== RCS file: /cvs/src/src/gdb/configure.ac,v retrieving revision 1.18 diff -u -r1.18 configure.ac --- gdb/configure.ac 21 Apr 2005 05:34:33 -0000 1.18 +++ gdb/configure.ac 14 May 2005 16:10:31 -0000 @@ -418,7 +418,7 @@ AC_CHECK_DECLS([free, malloc, realloc]) AC_CHECK_DECLS([strerror, strstr]) -AC_CHECK_DECLS(getopt) +AC_CHECK_DECLS([getopt, snprintf, vsnprintf]) # ----------------------- # # Checks for structures. # Index: libiberty/configure.ac =================================================================== RCS file: /cvs/src/src/libiberty/configure.ac,v retrieving revision 1.22 diff -u -r1.22 configure.ac --- libiberty/configure.ac 7 May 2005 02:00:41 -0000 1.22 +++ libiberty/configure.ac 14 May 2005 16:10:46 -0000 @@ -282,7 +282,7 @@ sysconf times sbrk gettimeofday ffs snprintf vsnprintf \ pstat_getstatic pstat_getdynamic sysmp getsysinfo table sysctl wait3 wait4 \ realpath canonicalize_file_name __fsetlocking) - AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf]) + AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf]) AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.]) AC_DEFINE(HAVE_SYS_NERR, 1, [Define if you have the sys_nerr variable.]) AC_DEFINE(HAVE_SYS_SIGLIST, 1, [Define if you have the sys_siglist variable.]) @@ -518,7 +518,7 @@ [AC_MSG_RESULT([no])]) AC_CHECK_FUNCS($checkfuncs) - AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf]) + AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf]) libiberty_NEED_DECLARATION(canonicalize_file_name) fi