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