changeset 8570:4175c39ba7cc

Move vasprintf prototypes to stdio.
author Simon Josefsson <simon@josefsson.org>
date Tue, 27 Mar 2007 20:18:17 +0000
parents 378e85482afa
children 2c310f4a00e7
files ChangeLog lib/asprintf.c lib/stdio_.h lib/vasprintf.c lib/vasprintf.h lib/xvasprintf.c m4/stdio_h.m4 m4/vasprintf.m4 modules/stdio modules/vasprintf tests/test-vasprintf-posix.c tests/test-vasprintf.c
diffstat 12 files changed, 64 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2007-03-27  Simon Josefsson  <simon@josefsson.org>
+	    Bruno Haible  <bruno@clisp.org>
+
+	* 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  <bruno@clisp.org>
 
 	Make vasnprintf multithread-safe.
--- 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 <config.h>
 
 /* Specification.  */
-#include "vasprintf.h"
+#include <stdio.h>
 
 #include <stdarg.h>
 
--- a/lib/stdio_.h
+++ b/lib/stdio_.h
@@ -183,6 +183,22 @@
      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
 }
--- 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 <config.h>
 
 /* Specification.  */
-#include "vasprintf.h"
+#include <stdio.h>
 
 #include <errno.h>
 #include <limits.h>
deleted file mode 100644
--- 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 <stdio.h>
-
-#endif
-
-#if !HAVE_VASPRINTF || REPLACE_VASPRINTF
-
-/* Get va_list.  */
-#include <stdarg.h>
-
-#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 */
--- 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 <errno.h>
 #include <limits.h>
 #include <string.h>
+#include <stdio.h>
 
-#include "vasprintf.h"
 #include "xalloc.h"
 
 /* Checked size_t computations.  */
--- 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 @@
   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 @@
   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])
 ])
--- 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_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
--- a/modules/stdio
+++ b/modules/stdio
@@ -29,6 +29,7 @@
 	      -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 @@
 	      -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
--- a/modules/vasprintf
+++ b/modules/vasprintf
@@ -2,21 +2,22 @@
 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"
+<stdio.h>
 
 License:
 LGPL
--- a/tests/test-vasprintf-posix.c
+++ b/tests/test-vasprintf-posix.c
@@ -21,7 +21,7 @@
 # include <config.h>
 #endif
 
-#include "vasprintf.h"
+#include <stdio.h>
 
 #include <stdarg.h>
 #include <stddef.h>
--- a/tests/test-vasprintf.c
+++ b/tests/test-vasprintf.c
@@ -21,7 +21,7 @@
 # include <config.h>
 #endif
 
-#include "vasprintf.h"
+#include <stdio.h>
 
 #include <stdarg.h>
 #include <stdlib.h>