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