* admin/make-tarball.txt: Copyedits.
[emacs.git] / m4 / strtoimax.m4
blob7662cf8b3725a08553ce4a349bb3659076da0699
1 # strtoimax.m4 serial 14
2 dnl Copyright (C) 2002-2004, 2006, 2009-2015 Free Software Foundation,
3 dnl Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_STRTOIMAX],
10   AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
12   dnl On OSF/1 5.1 with cc, this function is declared but not defined.
13   AC_CHECK_FUNCS_ONCE([strtoimax])
14   AC_CHECK_DECLS_ONCE([strtoimax])
15   if test "$ac_cv_have_decl_strtoimax" != yes; then
16     HAVE_DECL_STRTOIMAX=0
17   fi
19   if test "$ac_cv_func_strtoimax" = yes; then
20     HAVE_STRTOIMAX=1
21     dnl On AIX 5.1, strtoimax() fails for values outside the 'int' range.
22     AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
23     AC_CACHE_CHECK([whether strtoimax works], [gl_cv_func_strtoimax],
24       [AC_RUN_IFELSE(
25          [AC_LANG_SOURCE([[
26 #include <errno.h>
27 #include <string.h>
28 #include <inttypes.h>
29 int main ()
31   if (sizeof (intmax_t) > sizeof (int))
32     {
33       const char *s = "4294967295";
34       char *p;
35       intmax_t res;
36       errno = 0;
37       res = strtoimax (s, &p, 10);
38       if (p != s + strlen (s))
39         return 1;
40       if (errno != 0)
41         return 2;
42       if (res != (intmax_t) 65535 * (intmax_t) 65537)
43         return 3;
44     }
45   else
46     {
47       const char *s = "2147483647";
48       char *p;
49       intmax_t res;
50       errno = 0;
51       res = strtoimax (s, &p, 10);
52       if (p != s + strlen (s))
53         return 1;
54       if (errno != 0)
55         return 2;
56       if (res != 2147483647)
57         return 3;
58     }
59   return 0;
61 ]])],
62          [gl_cv_func_strtoimax=yes],
63          [gl_cv_func_strtoimax=no],
64          [case "$host_os" in
65                    # Guess no on AIX 5.
66             aix5*) gl_cv_func_strtoimax="guessing no" ;;
67                    # Guess yes otherwise.
68             *)     gl_cv_func_strtoimax="guessing yes" ;;
69           esac
70          ])
71       ])
72     case "$gl_cv_func_strtoimax" in
73       *no) REPLACE_STRTOIMAX=1 ;;
74     esac
75   else
76     if test "$ac_cv_have_decl_strtoimax" = yes; then
77       # HP-UX 11.11 has "#define strtoimax(...) ..." but no function.
78       REPLACE_STRTOIMAX=1
79     fi
80     HAVE_STRTOIMAX=0
81   fi
84 # Prerequisites of lib/strtoimax.c.
85 AC_DEFUN([gl_PREREQ_STRTOIMAX], [
86   AC_CHECK_DECLS([strtoll])
87   AC_REQUIRE([AC_TYPE_LONG_LONG_INT])