changeset 8341:7929a12676ab

New module 'vasprintf-posix'.
author Bruno Haible <bruno@clisp.org>
date Mon, 05 Mar 2007 00:37:52 +0000
parents b7fc2d0aaa1e
children 504f056f113a
files ChangeLog lib/vasprintf.h m4/vasprintf-posix.m4 m4/vasprintf.m4 modules/vasprintf-posix
diffstat 5 files changed, 95 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Mar 05 00:37:10 2007 +0000
+++ b/ChangeLog	Mon Mar 05 00:37:52 2007 +0000
@@ -1,3 +1,16 @@
+2007-03-04  Bruno Haible  <bruno@clisp.org>
+
+	* modules/vasprintf-posix: New file.
+	* lib/vasprintf.h (asprintf, vasprintf): Rename if REPLACE_VASPRINTF is
+	defined.
+	* m4/vasprintf-posix.m4: New file.
+	* m4/vasprintf.m4 (gl_REPLACE_VASPRINTF): New macro, extracted from
+	gl_FUNC_VASPRINTF.
+	(gl_FUNC_VASPRINTF): Invoke it.
+	* m4/vasnprintf.m4 (gl_REPLACE_VASNPRINTF): Define REPLACE_VASNPRINTF
+	here.
+	* m4/vasnprintf-posix.m4 (gl_FUNC_VASNPRINTF_POSIX): Not here.
+
 2007-03-04  Bruno Haible  <bruno@clisp.org>
 
 	* lib/sys_time_.h: Rename GETTIMEOFDAY_REPLACEMENT to
--- a/lib/vasprintf.h	Mon Mar 05 00:37:10 2007 +0000
+++ b/lib/vasprintf.h	Mon Mar 05 00:37:52 2007 +0000
@@ -1,5 +1,5 @@
 /* vsprintf with automatic memory allocation.
-   Copyright (C) 2002-2003 Free Software Foundation, Inc.
+   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
@@ -49,6 +49,10 @@
    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)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m4/vasprintf-posix.m4	Mon Mar 05 00:37:52 2007 +0000
@@ -0,0 +1,31 @@
+# vasprintf-posix.m4 serial 1
+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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_VASPRINTF_POSIX],
+[
+  AC_REQUIRE([gl_EOVERFLOW])
+  AC_REQUIRE([gl_PRINTF_SIZES_C99])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
+  AC_REQUIRE([gl_PRINTF_POSITIONS])
+  AC_CHECK_FUNCS([vasprintf])
+  if expr "$gl_cv_func_printf_sizes_c99" : ".*yes" > /dev/null \
+     && expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null \
+     && expr "$gl_cv_func_printf_directive_n" : ".*yes" > /dev/null \
+     && expr "$gl_cv_func_printf_positions" : ".*yes" > /dev/null \
+     && test $ac_cv_func_vasprintf = yes; then
+    : # vasprintf exists and is already POSIX compliant.
+  else
+    AC_CHECK_FUNCS([vasnprintf])
+    if ! expr "$gl_cv_func_printf_directive_a" : ".*yes" > /dev/null; then
+      AC_DEFINE([NEED_PRINTF_DIRECTIVE_A], 1,
+        [Define if the vasnprintf implementation needs special code for
+         the 'a' and 'A' directives.])
+    fi
+    gl_REPLACE_VASNPRINTF
+    gl_REPLACE_VASPRINTF
+  fi
+])
--- a/m4/vasprintf.m4	Mon Mar 05 00:37:10 2007 +0000
+++ b/m4/vasprintf.m4	Mon Mar 05 00:37:52 2007 +0000
@@ -1,20 +1,30 @@
-# vasprintf.m4 serial 2
-dnl Copyright (C) 2002-2003, 2006 Free Software Foundation, Inc.
+# vasprintf.m4 serial 3
+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,
 dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_FUNC_VASPRINTF],
 [
-  AC_REPLACE_FUNCS(vasprintf)
+  AC_CHECK_FUNCS([vasprintf])
   if test $ac_cv_func_vasprintf = no; then
-    AC_LIBOBJ(asprintf)
-    gl_PREREQ_VASPRINTF_H
-    gl_PREREQ_VASPRINTF
-    gl_PREREQ_ASPRINTF
+    gl_REPLACE_VASPRINTF
   fi
 ])
 
+AC_DEFUN([gl_REPLACE_VASPRINTF],
+[
+  AC_LIBOBJ([vasprintf])
+  AC_LIBOBJ([asprintf])
+  if test $ac_cv_func_vasprintf = yes; then
+    AC_DEFINE([REPLACE_VASPRINTF], 1,
+      [Define if vasprintf exists but is overridden by gnulib.])
+  fi
+  gl_PREREQ_VASPRINTF_H
+  gl_PREREQ_VASPRINTF
+  gl_PREREQ_ASPRINTF
+])
+
 # Prerequisites of lib/vasprintf.h.
 AC_DEFUN([gl_PREREQ_VASPRINTF_H],
 [
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/vasprintf-posix	Mon Mar 05 00:37:52 2007 +0000
@@ -0,0 +1,29 @@
+Description:
+POSIX compatible vsprintf with automatic memory allocation.
+
+Files:
+m4/vasprintf-posix.m4
+m4/printf.m4
+
+Depends-on:
+vasprintf
+vasnprintf
+isnan-nolibm
+isnanl-nolibm
+printf-frexp
+printf-frexpl
+
+configure.ac:
+gl_FUNC_VASPRINTF_POSIX
+
+Makefile.am:
+
+Include:
+"vasprintf.h"
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+