From c68c756f05b4d51ffa5a12b391ff996990deee14 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 5 Mar 2007 00:37:52 +0000 Subject: [PATCH] New module 'vasprintf-posix'. --- ChangeLog | 13 +++++++++++++ lib/vasprintf.h | 6 +++++- m4/vasprintf-posix.m4 | 31 +++++++++++++++++++++++++++++++ m4/vasprintf.m4 | 24 +++++++++++++++++------- modules/vasprintf-posix | 29 +++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 m4/vasprintf-posix.m4 create mode 100644 modules/vasprintf-posix diff --git a/ChangeLog b/ChangeLog index 94f1a5582..f84040c6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2007-03-04 Bruno Haible + * 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 + * lib/sys_time_.h: Rename GETTIMEOFDAY_REPLACEMENT to REPLACE_GETTIMEOFDAY. * modules/sys_time (Makefile.am): Likewise. diff --git a/lib/vasprintf.h b/lib/vasprintf.h index ab5515ce7..4a342e30e 100644 --- a/lib/vasprintf.h +++ b/lib/vasprintf.h @@ -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 index 000000000..ac024f2d8 --- /dev/null +++ b/m4/vasprintf-posix.m4 @@ -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 +]) diff --git a/m4/vasprintf.m4 b/m4/vasprintf.m4 index 18ca6327b..0f4c12374 100644 --- a/m4/vasprintf.m4 +++ b/m4/vasprintf.m4 @@ -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 index 000000000..e07e3d3f3 --- /dev/null +++ b/modules/vasprintf-posix @@ -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 + -- 2.11.0