From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12376 invoked by alias); 12 May 2005 14:59:33 -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 11681 invoked from network); 12 May 2005 14:59:24 -0000 Received: from unknown (HELO legolas.inter.net.il) (192.114.186.24) by sourceware.org with SMTP; 12 May 2005 14:59:24 -0000 Received: from zaretski (IGLD-83-130-254-105.inter.net.il [83.130.254.105]) by legolas.inter.net.il (MOS 3.5.6-GR) with ESMTP id EIZ06482 (AUTH halo1); Thu, 12 May 2005 17:59:21 +0300 (IDT) Date: Thu, 12 May 2005 15:08:00 -0000 From: "Eli Zaretskii" To: gcc-patches@gcc.gnu.org Message-ID: <01c55702$Blat.v2.4$d4764900@zahav.net.il> Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=ISO-8859-1 CC: gdb-patches@sources.redhat.com In-reply-to: <41994B9D.9080809@gnu.org> (message from Andrew Cagney on Mon, 15 Nov 2004 19:36:45 -0500) Subject: [RFA] Eliminate warnings about snprintf declaration Reply-to: Eli Zaretskii References: <01c4c990$Blat.v2.2.2$887ec720@zahav.net.il> <41994B9D.9080809@gnu.org> X-SW-Source: 2005-05/txt/msg00285.txt.bz2 > Date: Mon, 15 Nov 2004 19:36:45 -0500 > From: Andrew Cagney > Cc: gdb@sources.redhat.com > > Eli Zaretskii wrote: > > When I build GDB with DJGPP, GCC whines like so: > > > > remote.c: In function `remote_xfer_partial': > > remote.c:4920: warning: implicit declaration of function `snprintf' > > > > (I see this warning for other source files as well.) > > > > This happens because DJGPP doesn't have `snprintf' in its library, so > > the libiberty version is used. But there's no prototype for the > > libiberty `snprintf' anywhere, thus the warning. The code seems to be > > relying on getting the prototype from stdio.h, but if the library > > doesn't have the function, we cannot expect to have the prototype on a > > standard header. > > > > What would be the canonical way to fix that? > > include/libiberty.h, for instance: > > > #if !HAVE_DECL_ASPRINTF > > /* Like sprintf but provides a pointer to malloc'd storage, which must > > be freed by the caller. */ > > > > extern int asprintf PARAMS ((char **, const char *, ...)) ATTRIBUTE_PRINTF_2; > > #endif Okay, here're the patches to add snprintf and vsnprintf to the list of functions whose declarations are checked at configure time. Comments? libiberty/ChangeLog: 2005-05-12 Eli Zaretskii * configure.ac: Add snprintf and vsnprintf to AC_CHEK_DECLS. include/ChangeLog: 2005-05-12 Eli Zaretskii * libiberty.h (snprintf) [!HAVE_DECL_SNPRINTF]: Add a prototype. (vsnprintf) [!HAVE_DECL_VSNPRINTF]: Add a prototype. 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 12 May 2005 14:55:28 -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 Index: include/libiberty.h =================================================================== RCS file: /cvs/src/src/include/libiberty.h,v retrieving revision 1.43 diff -u -r1.43 libiberty.h --- include/libiberty.h 10 May 2005 10:21:08 -0000 1.43 +++ include/libiberty.h 12 May 2005 14:56:04 -0000 @@ -528,6 +528,24 @@ ATTRIBUTE_PRINTF(2,0); #endif +#if !HAVE_DECL_SNPRINTF +# ifdef HAVE_DECL_SNPRINTF + extern int snprintf (); +# else +/* Like sprintf but prints at most N characters. */ + extern int snprintf (char *, size_t, const char *, ...) ATTRIBUTE_PRINTF_3; +# endif +#endif + +#if !HAVE_DECL_VSNPRINTF +# ifdef HAVE_DECL_VSNPRINTF + extern int vsnprintf (); +# else +/* Like vsprintf but prints at most N characters. */ + extern int vsnprintf (char *, size_t, const char *, va_list); +# endif +#endif + #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) /* Drastically simplified alloca configurator. If we're using GCC,