From 6e2afe5ad7c90ae9422ae2657dd842deed21731e Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Tue, 27 Mar 2007 20:18:17 +0000 Subject: [PATCH] Move vasprintf prototypes to stdio. --- ChangeLog | 25 ++++++++++++++++ lib/asprintf.c | 4 +-- lib/stdio_.h | 16 ++++++++++ lib/vasprintf.c | 4 +-- lib/vasprintf.h | 69 -------------------------------------------- lib/xvasprintf.c | 4 +-- m4/stdio_h.m4 | 5 +++- m4/vasprintf.m4 | 8 +++-- modules/stdio | 3 ++ modules/vasprintf | 5 ++-- tests/test-vasprintf-posix.c | 2 +- tests/test-vasprintf.c | 2 +- 12 files changed, 64 insertions(+), 83 deletions(-) delete mode 100644 lib/vasprintf.h diff --git a/ChangeLog b/ChangeLog index 79fc2df32..a7710c4b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2007-03-27 Simon Josefsson + Bruno Haible + + * m4/vasprintf.m4: Convert AC_SUBST into shell variable for + REPLACE_VASPRINTF. Set HAVE_VASPRINTF. Add + AC_REQUIRE([gl_STDIO_H_DEFAULTS]). + + * m4/stdio_h.m4: Add stubs for vasprintf too. + + * modules/stdio: Support vasprintf in sed command. + + * modules/vasprintf: Depend on stdio for prototypes. Remove + vasprintf.h. Add stdio module indicator. + + * lib/stdio_.h: Declare asprintf and vasprintf, based on + vasprintf.h. + + * lib/vasprintf.h: File removed. + + * lib/asprintf.c: Use stdio.h instead of vasprintf.h. + * lib/vasprintf.c: Ditto. + * lib/xvasprintf.c: Ditto. + * tests/test-vasprintf-posix.c: Ditto. + * tests/test-vasprintf.c: Ditto. + 2007-03-27 Bruno Haible Make vasnprintf multithread-safe. diff --git a/lib/asprintf.c b/lib/asprintf.c index 29ac6cf2d..78849549d 100644 --- a/lib/asprintf.c +++ b/lib/asprintf.c @@ -1,5 +1,5 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ #include /* Specification. */ -#include "vasprintf.h" +#include #include diff --git a/lib/stdio_.h b/lib/stdio_.h index 441c0d5cd..183cf7fe0 100644 --- a/lib/stdio_.h +++ b/lib/stdio_.h @@ -183,6 +183,22 @@ extern int vsprintf (char *str, const char *format, va_list args) vsprintf (b, f, a)) #endif +#if @GNULIB_VASPRINTF@ +# if @REPLACE_VASPRINTF@ +# define asprintf rpl_asprintf +# define vasprintf rpl_vasprintf +# endif +# if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@ + /* Write formatted output to a string dynamically allocated with malloc(). + If the memory allocation succeeds, store the address of the string in + *RESULT and return the number of resulting bytes, excluding the trailing + NUL. Upon memory allocation error, or some other error, return -1. */ + extern int asprintf (char **result, const char *format, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); + extern int vasprintf (char **result, const char *format, va_list args) + __attribute__ ((__format__ (__printf__, 2, 0))); +# endif +#endif #ifdef __cplusplus } diff --git a/lib/vasprintf.c b/lib/vasprintf.c index 824707345..885d1e563 100644 --- a/lib/vasprintf.c +++ b/lib/vasprintf.c @@ -1,5 +1,5 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,7 +18,7 @@ #include /* Specification. */ -#include "vasprintf.h" +#include #include #include diff --git a/lib/vasprintf.h b/lib/vasprintf.h deleted file mode 100644 index 65f05315f..000000000 --- a/lib/vasprintf.h +++ /dev/null @@ -1,69 +0,0 @@ -/* vsprintf with automatic memory allocation. - Copyright (C) 2002-2003, 2007 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _VASPRINTF_H -#define _VASPRINTF_H - -#if HAVE_VASPRINTF - -/* Get asprintf(), vasprintf() declarations. */ -#include - -#endif - -#if !HAVE_VASPRINTF || REPLACE_VASPRINTF - -/* Get va_list. */ -#include - -#ifndef __attribute__ -/* This feature is available in gcc versions 2.5 and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ -# define __attribute__(Spec) /* empty */ -# endif -/* The __-protected variants of `format' and `printf' attributes - are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ -# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) -# define __format__ format -# define __printf__ printf -# endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* Write formatted output to a string dynamically allocated with malloc(). - If the memory allocation succeeds, store the address of the string in - *RESULT and return the number of resulting bytes, excluding the trailing - NUL. Upon memory allocation error, or some other error, return -1. */ -#if REPLACE_VASPRINTF -# define asprintf rpl_asprintf -# define vasprintf rpl_vasprintf -#endif -extern int asprintf (char **result, const char *format, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); -extern int vasprintf (char **result, const char *format, va_list args) - __attribute__ ((__format__ (__printf__, 2, 0))); - -#ifdef __cplusplus -} -#endif - -#endif - -#endif /* _VASPRINTF_H */ diff --git a/lib/xvasprintf.c b/lib/xvasprintf.c index b68442764..bd683627e 100644 --- a/lib/xvasprintf.c +++ b/lib/xvasprintf.c @@ -1,5 +1,5 @@ /* vasprintf and asprintf with out-of-memory checking. - Copyright (C) 1999, 2002-2004, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002-2004, 2006, 2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,8 +23,8 @@ #include #include #include +#include -#include "vasprintf.h" #include "xalloc.h" /* Checked size_t computations. */ diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4 index 6b4170b1b..5561626df 100644 --- a/m4/stdio_h.m4 +++ b/m4/stdio_h.m4 @@ -1,4 +1,4 @@ -# stdio_h.m4 serial 2 +# stdio_h.m4 serial 3 dnl Copyright (C) 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, @@ -29,6 +29,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS], GNULIB_VPRINTF_POSIX=0; AC_SUBST([GNULIB_VPRINTF_POSIX]) GNULIB_VSNPRINTF=0; AC_SUBST([GNULIB_VSNPRINTF]) GNULIB_VSPRINTF_POSIX=0; AC_SUBST([GNULIB_VSPRINTF_POSIX]) + GNULIB_VASPRINTF=0; AC_SUBST([GNULIB_VASPRINTF]) dnl Assume proper GNU behavior unless another module says otherwise. REPLACE_FPRINTF=0; AC_SUBST([REPLACE_FPRINTF]) REPLACE_VFPRINTF=0; AC_SUBST([REPLACE_VFPRINTF]) @@ -40,4 +41,6 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS], HAVE_DECL_VSNPRINTF=1; AC_SUBST([HAVE_DECL_VSNPRINTF]) REPLACE_SPRINTF=0; AC_SUBST([REPLACE_SPRINTF]) REPLACE_VSPRINTF=0; AC_SUBST([REPLACE_VSPRINTF]) + HAVE_VASPRINTF=1; AC_SUBST([HAVE_VASPRINTF]) + REPLACE_VASPRINTF=0; AC_SUBST([REPLACE_VASPRINTF]) ]) diff --git a/m4/vasprintf.m4 b/m4/vasprintf.m4 index 0f4c12374..d38c8ede5 100644 --- a/m4/vasprintf.m4 +++ b/m4/vasprintf.m4 @@ -1,4 +1,4 @@ -# vasprintf.m4 serial 3 +# vasprintf.m4 serial 4 dnl Copyright (C) 2002-2003, 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, @@ -16,9 +16,11 @@ AC_DEFUN([gl_REPLACE_VASPRINTF], [ AC_LIBOBJ([vasprintf]) AC_LIBOBJ([asprintf]) + AC_REQUIRE([gl_STDIO_H_DEFAULTS]) if test $ac_cv_func_vasprintf = yes; then - AC_DEFINE([REPLACE_VASPRINTF], 1, - [Define if vasprintf exists but is overridden by gnulib.]) + REPLACE_VASPRINTF=1 + else + HAVE_VASPRINTF=0 fi gl_PREREQ_VASPRINTF_H gl_PREREQ_VASPRINTF diff --git a/modules/stdio b/modules/stdio index 2499d096a..456e323f4 100644 --- a/modules/stdio +++ b/modules/stdio @@ -29,6 +29,7 @@ stdio.h: stdio_.h -e 's|@''GNULIB_VPRINTF_POSIX''@|$(GNULIB_VPRINTF_POSIX)|g' \ -e 's|@''GNULIB_VSNPRINTF''@|$(GNULIB_VSNPRINTF)|g' \ -e 's|@''GNULIB_VSPRINTF_POSIX''@|$(GNULIB_VSPRINTF_POSIX)|g' \ + -e 's|@''GNULIB_VASPRINTF''@|$(GNULIB_VASPRINTF)|g' \ -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \ -e 's|@''REPLACE_VFPRINTF''@|$(REPLACE_VFPRINTF)|g' \ -e 's|@''REPLACE_PRINTF''@|$(REPLACE_PRINTF)|g' \ @@ -39,6 +40,8 @@ stdio.h: stdio_.h -e 's|@''HAVE_DECL_VSNPRINTF''@|$(HAVE_DECL_VSNPRINTF)|g' \ -e 's|@''REPLACE_SPRINTF''@|$(REPLACE_SPRINTF)|g' \ -e 's|@''REPLACE_VSPRINTF''@|$(REPLACE_VSPRINTF)|g' \ + -e 's|@''HAVE_VASPRINTF''@|$(HAVE_VASPRINTF)|g' \ + -e 's|@''REPLACE_VASPRINTF''@|$(REPLACE_VASPRINTF)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ < $(srcdir)/stdio_.h; \ } > $@-t diff --git a/modules/vasprintf b/modules/vasprintf index e78d89a11..1cade8a01 100644 --- a/modules/vasprintf +++ b/modules/vasprintf @@ -2,21 +2,22 @@ Description: vsprintf with automatic memory allocation. Files: -lib/vasprintf.h lib/vasprintf.c lib/asprintf.c m4/vasprintf.m4 Depends-on: vasnprintf +stdio configure.ac: gl_FUNC_VASPRINTF +gl_STDIO_MODULE_INDICATOR([vasprintf]) Makefile.am: Include: -"vasprintf.h" + License: LGPL diff --git a/tests/test-vasprintf-posix.c b/tests/test-vasprintf-posix.c index f903efb15..8a175b3f9 100644 --- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -21,7 +21,7 @@ # include #endif -#include "vasprintf.h" +#include #include #include diff --git a/tests/test-vasprintf.c b/tests/test-vasprintf.c index 3de72d3f2..cae32d6ec 100644 --- a/tests/test-vasprintf.c +++ b/tests/test-vasprintf.c @@ -21,7 +21,7 @@ # include #endif -#include "vasprintf.h" +#include #include #include -- 2.11.0