438e8528d7756d555b1f7d1fb6475dc183b4e7f1
[gnulib.git] / m4 / xstrtoimax.m4
1 #serial 2
2 dnl Cloned from xstrtoumax.m4.  Keep these files in sync.
3
4 # autoconf tests required for use of xstrtoimax.c
5
6 AC_DEFUN([jm_AC_PREREQ_XSTRTOIMAX],
7 [
8   AC_REQUIRE([jm_AC_TYPE_INTMAX_T])
9   AC_REQUIRE([jm_AC_TYPE_UINTMAX_T])
10   AC_REQUIRE([jm_AC_TYPE_LONG_LONG])
11   AC_REQUIRE([jm_AC_TYPE_UNSIGNED_LONG_LONG])
12   AC_CHECK_DECLS([strtol, strtoul, strtoll, strtoimax, strtoumax])
13   AC_CHECK_HEADERS(limits.h stdlib.h inttypes.h)
14
15   AC_CACHE_CHECK([whether <inttypes.h> defines strtoimax as a macro],
16     jm_cv_func_strtoimax_macro,
17     AC_EGREP_CPP([inttypes_h_defines_strtoimax], [#include <inttypes.h>
18 #ifdef strtoimax
19  inttypes_h_defines_strtoimax
20 #endif],
21       jm_cv_func_strtoimax_macro=yes,
22       jm_cv_func_strtoimax_macro=no))
23
24   if test "$jm_cv_func_strtoimax_macro" != yes; then
25     AC_REPLACE_FUNCS(strtoimax)
26   fi
27
28   dnl Only the replacement strtoimax invokes strtol and strtoll,
29   dnl so we need the replacements only if strtoimax does not exist.
30   case "$jm_cv_func_strtoimax_macro,$ac_cv_func_strtoimax" in
31     no,no)
32       AC_REPLACE_FUNCS(strtol)
33
34       dnl We don't need (and can't compile) the replacement strtoll
35       dnl unless the type `long long' exists.
36       if test "$ac_cv_type_long_long" = yes; then
37         AC_REPLACE_FUNCS(strtoll)
38       fi
39       ;;
40   esac
41 ])