Commit | Line | Data |
---|---|---|
caf8a9b2 | 1 | # strtoimax.m4 serial 13 |
ab422c4d | 2 | dnl Copyright (C) 2002-2004, 2006, 2009-2013 Free Software Foundation, Inc. |
f6ce9b9a PE |
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. | |
6 | ||
7 | AC_DEFUN([gl_FUNC_STRTOIMAX], | |
8 | [ | |
9 | AC_REQUIRE([gl_INTTYPES_H_DEFAULTS]) | |
10 | ||
7f59d9c8 PE |
11 | dnl On OSF/1 5.1 with cc, this function is declared but not defined. |
12 | AC_CHECK_FUNCS_ONCE([strtoimax]) | |
f6ce9b9a PE |
13 | AC_CHECK_DECLS_ONCE([strtoimax]) |
14 | if test "$ac_cv_have_decl_strtoimax" != yes; then | |
15 | HAVE_DECL_STRTOIMAX=0 | |
f6ce9b9a | 16 | fi |
caf8a9b2 PE |
17 | |
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 () | |
29 | { | |
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; | |
59 | } | |
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 | HAVE_STRTOIMAX=0 | |
76 | fi | |
f6ce9b9a PE |
77 | ]) |
78 | ||
79 | # Prerequisites of lib/strtoimax.c. | |
80 | AC_DEFUN([gl_PREREQ_STRTOIMAX], [ | |
81 | AC_CHECK_DECLS([strtoll]) | |
82 | AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) | |
83 | ]) |