| 1 | # strtoimax.m4 serial 16
|
|---|
| 2 | dnl Copyright (C) 2002-2004, 2006, 2009-2021 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.
|
|---|
| 6 |
|
|---|
| 7 | AC_DEFUN([gl_FUNC_STRTOIMAX],
|
|---|
| 8 | [
|
|---|
| 9 | AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
|
|---|
| 10 |
|
|---|
| 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
|
|---|
| 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 on native Windows.
|
|---|
| 67 | mingw*) gl_cv_func_strtoimax="guessing yes" ;;
|
|---|
| 68 | # Guess yes otherwise.
|
|---|
| 69 | *) gl_cv_func_strtoimax="guessing yes" ;;
|
|---|
| 70 | esac
|
|---|
| 71 | ])
|
|---|
| 72 | ])
|
|---|
| 73 | case "$gl_cv_func_strtoimax" in
|
|---|
| 74 | *no) REPLACE_STRTOIMAX=1 ;;
|
|---|
| 75 | esac
|
|---|
| 76 | else
|
|---|
| 77 | if test "$ac_cv_have_decl_strtoimax" = yes; then
|
|---|
| 78 | # HP-UX 11.11 has "#define strtoimax(...) ..." but no function.
|
|---|
| 79 | REPLACE_STRTOIMAX=1
|
|---|
| 80 | fi
|
|---|
| 81 | HAVE_STRTOIMAX=0
|
|---|
| 82 | fi
|
|---|
| 83 | ])
|
|---|
| 84 |
|
|---|
| 85 | # Prerequisites of lib/strtoimax.c.
|
|---|
| 86 | AC_DEFUN([gl_PREREQ_STRTOIMAX], [
|
|---|
| 87 | AC_CHECK_DECLS([strtoll])
|
|---|
| 88 | ])
|
|---|