New module 'vasprintf-posix'.
authorBruno Haible <bruno@clisp.org>
Mon, 5 Mar 2007 00:37:52 +0000 (00:37 +0000)
committerBruno Haible <bruno@clisp.org>
Mon, 5 Mar 2007 00:37:52 +0000 (00:37 +0000)
ChangeLog
lib/vasprintf.h
m4/vasprintf-posix.m4 [new file with mode: 0644]
m4/vasprintf.m4
modules/vasprintf-posix [new file with mode: 0644]

index 94f1a55..f84040c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 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
        REPLACE_GETTIMEOFDAY.
        * modules/sys_time (Makefile.am): Likewise.
index ab5515c..4a342e3 100644 (file)
@@ -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 @@ extern "C" {
    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)
diff --git a/m4/vasprintf-posix.m4 b/m4/vasprintf-posix.m4
new file mode 100644 (file)
index 0000000..ac024f2
--- /dev/null
@@ -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
+])
index 18ca632..0f4c123 100644 (file)
@@ -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],
 [
diff --git a/modules/vasprintf-posix b/modules/vasprintf-posix
new file mode 100644 (file)
index 0000000..e07e3d3
--- /dev/null
@@ -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
+