AC_DEFUN([HW_HEADER_STDARG_H],
[
AC_PREREQ([2.60]) AC_CHECK_HEADERS_ONCE([stdarg.h])
])
AC_DEFUN([HW_HEADER_VARARGS_H],
[
AC_PREREQ([2.60]) AC_CHECK_HEADERS_ONCE([varargs.h])
])
AC_DEFUN([HW_FUNC_VA_COPY],
[
AC_REQUIRE([HW_HEADER_STDARG_H]) AC_REQUIRE([HW_HEADER_VARARGS_H]) AC_CACHE_CHECK([for va_copy],
[hw_cv_func_va_copy],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
[[ [[va_list ap, aq; va_copy(aq, ap);]])],
[hw_cv_func_va_copy=yes],
[hw_cv_func_va_copy=no],
[hw_cv_func_va_copy=no])])
AS_IF([test "$hw_cv_func_va_copy" = yes],
[AC_DEFINE([HAVE_VA_COPY], [1],
[Define to 1 if you have the `va_copy' function or macro.])])
])
AC_DEFUN([HW_FUNC___VA_COPY],
[
AC_REQUIRE([HW_HEADER_STDARG_H]) AC_REQUIRE([HW_HEADER_VARARGS_H]) AC_CACHE_CHECK([for __va_copy],
[hw_cv_func___va_copy],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
[[ [[va_list ap, aq; __va_copy(aq, ap);]])],
[hw_cv_func___va_copy=yes],
[hw_cv_func___va_copy=no],
[hw_cv_func___va_copy=no])])
AS_IF([test "$hw_cv_func___va_copy" = yes],
[AC_DEFINE([HAVE___VA_COPY], [1],
[Define to 1 if you have the `__va_copy' function or macro.])])
])
AC_DEFUN([HW_FUNC_VSNPRINTF],
[
AC_PREREQ([2.60]) AC_REQUIRE([HW_HEADER_STDARG_H]) AC_CHECK_FUNC([vsnprintf],
[hw_cv_func_vsnprintf=yes],
[hw_cv_func_vsnprintf=no])
AS_IF([test "$hw_cv_func_vsnprintf" = yes],
[AC_CACHE_CHECK([whether vsnprintf is C99 compliant],
[hw_cv_func_vsnprintf_c99],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM(
[[ static int testprintf(char *buf, size_t size, const char *format, ...)
{
int result;
va_list ap;
va_start(ap, format);
result = vsnprintf(buf, size, format, ap);
va_end(ap);
return result;
}]],
[[char buf[43];
if (testprintf(buf, 4, "The answer is %27.2g.", 42.0) != 42 ||
testprintf(buf, 0, "No, it's %32zu.", (size_t)42) != 42 ||
buf[0] != 'T' || buf[3] != '\0')
return 1;]])],
[hw_cv_func_vsnprintf_c99=yes],
[hw_cv_func_vsnprintf_c99=no],
[hw_cv_func_vsnprintf_c99=no])])],
[hw_cv_func_vsnprintf_c99=no])
AC_DEFINE([HAVE_VSNPRINTF], [1],
[Define if C99-compliant `vsnprintf' is available.])
AC_MSG_CHECKING([if C99-snprintf replacement vsnprintf will be used])
AS_IF([test "${hw_force_rpl_vsnprintf=no}" = yes -o "$hw_cv_func_vsnprintf_c99" = no],
[hw_use_rpl_vsnprintf=yes],
[hw_use_rpl_vsnprintf=no])
AC_MSG_RESULT([$hw_use_rpl_vsnprintf])
AS_IF([test "$hw_use_rpl_vsnprintf" = yes],
[AC_DEFINE([HW_WANT_RPL_VSNPRINTF], [1],
[Define to provide `rpl_vsnprintf' function.])
AS_IF([test ${hw_nodef_vsnprintf=no} = no],
[AC_DEFINE([vsnprintf], [rpl_vsnprintf],
[Define to rpl_vsnprintf if the replacement function should be used.])])
AC_CHECK_HEADERS([inttypes.h locale.h stddef.h stdint.h])
AC_CHECK_MEMBERS([struct lconv.decimal_point, struct lconv.thousands_sep],
[], [], [ AC_TYPE_LONG_DOUBLE
AC_TYPE_LONG_LONG_INT
AC_TYPE_UNSIGNED_LONG_LONG_INT
AC_TYPE_SIZE_T
AC_TYPE_INTMAX_T
AC_TYPE_UINTMAX_T
AC_TYPE_UINTPTR_T
AC_CHECK_TYPES([ptrdiff_t])
AC_CHECK_FUNCS([localeconv])
_HW_FUNC_XPRINTF_REPLACE])
])
AC_DEFUN([HW_FUNC_SNPRINTF],
[
AC_REQUIRE([HW_FUNC_VSNPRINTF]) AC_CHECK_FUNC([snprintf],
[hw_cv_func_snprintf=yes],
[hw_cv_func_snprintf=no])
AS_IF([test "$hw_cv_func_snprintf" = yes],
[AC_CACHE_CHECK([whether snprintf is C99 compliant],
[hw_cv_func_snprintf_c99],
[AC_RUN_IFELSE(
[AC_LANG_PROGRAM([[ [[char buf[43];
if (snprintf(buf, 4, "The answer is %27.2g.", 42.0) != 42 ||
snprintf(buf, 0, "No, it's %32zu.", (size_t)42) != 42 ||
buf[0] != 'T' || buf[3] != '\0')
return 1;]])],
[hw_cv_func_snprintf_c99=yes],
[hw_cv_func_snprintf_c99=no],
[hw_cv_func_snprintf_c99=no])])],
[hw_cv_func_snprintf_c99=no])
AC_DEFINE([HAVE_SNPRINTF], [1],
[Define if C99-compliant `snprintf' is available.])
AC_MSG_CHECKING([if C99-snprintf replacement snprintf will be used])
AS_IF([test "${hw_force_rpl_snprintf=no}" = yes -o "$hw_cv_func_snprintf_c99" = no],
[hw_use_rpl_snprintf=yes],
[hw_use_rpl_snprintf=no])
AC_MSG_RESULT([$hw_use_rpl_snprintf])
AS_IF([test "$hw_use_rpl_snprintf" = yes],
[AC_DEFINE([HW_WANT_RPL_SNPRINTF], [1],
[Define to provide `rpl_snprintf' function.])
AS_IF([test ${hw_nodef_snprintf=no} = no],
[AC_DEFINE([snprintf], [rpl_snprintf],
[Define to rpl_snprintf if the replacement function should be used.])])
_HW_FUNC_XPRINTF_REPLACE])
])
AC_DEFUN([HW_FUNC_VASPRINTF],
[
AC_REQUIRE([HW_FUNC_VSNPRINTF]) AC_CHECK_FUNCS([vasprintf],
[hw_cv_func_vasprintf=yes],
[hw_cv_func_vasprintf=no])
AC_DEFINE([HAVE_VASPRINTF], [1],
[Define if `vasprintf' is available.])
AC_MSG_CHECKING([if C99-snprintf replacement vasprintf will be used])
AS_IF([test "${hw_force_rpl_vasprintf=no}" = yes -o "$hw_cv_func_vasprintf" = no],
[hw_use_rpl_vasprintf=yes],
[hw_use_rpl_vasprintf=no])
AC_MSG_RESULT([$hw_use_rpl_vasprintf])
AS_IF([test "$hw_use_rpl_vasprintf" = yes],
[AC_DEFINE([HW_WANT_RPL_VASPRINTF], [1],
[Define to provide `rpl_vasprintf' function.])
AS_IF([test ${hw_nodef_vasprintf=no} = no],
[AC_DEFINE([vasprintf], [rpl_vasprintf],
[Define to rpl_vasprintf if the replacement function should be used.])])
AC_CHECK_HEADERS([stdlib.h])
HW_FUNC_VA_COPY
AS_IF([test "$hw_cv_func_va_copy" = no],
[HW_FUNC___VA_COPY])
_HW_FUNC_XPRINTF_REPLACE])
])
AC_DEFUN([HW_FUNC_ASPRINTF],
[
AC_REQUIRE([HW_FUNC_VASPRINTF]) AC_CHECK_FUNCS([asprintf],
[hw_cv_func_asprintf=yes],
[hw_cv_func_asprintf=no])
AC_DEFINE([HAVE_ASPRINTF], [1],
[Define if `asprintf' is available.])
AC_MSG_CHECKING([if C99-snprintf replacement asprintf will be used])
AS_IF([test "${hw_force_rpl_asprintf=no}" = yes -o "$hw_cv_func_asprintf" = no],
[hw_use_rpl_asprintf=yes],
[hw_use_rpl_asprintf=no])
AC_MSG_RESULT([$hw_use_rpl_asprintf])
AS_IF([test "$hw_use_rpl_asprintf" = yes],
[AC_DEFINE([HW_WANT_RPL_ASPRINTF], [1],
[Define to provide `rpl_asprintf' function.])
AS_IF([test ${hw_nodef_asprintf=no} = no],
[AC_DEFINE([asprintf], [rpl_asprintf],
[Define to rpl_asprintf if the replacement function should be used.])])
_HW_FUNC_XPRINTF_REPLACE])
])
AC_DEFUN([_HW_FUNC_XPRINTF_REPLACE],
[
AS_IF([test "x$_hw_cv_func_xprintf_replace_done" != xyes],
[AC_C_CONST
HW_HEADER_STDARG_H
AC_LIBOBJ([snprintf])
_hw_cv_func_xprintf_replace_done=yes])
])