* modules/chdir-long (Depends-on): Add memrchr.
[gnulib.git] / m4 / ullong_max.m4
1 # ullong_max.m4 - define ULLONG_MAX if necessary
2
3 dnl Copyright (C) 2005 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
8 # Written by Paul Eggert.
9
10 AC_DEFUN([gl_ULLONG_MAX],
11 [
12   dnl Avoid _AC_COMPUTE_INT-related macros, as they may not work with
13   dnl types wider than long int, due to problems with expr.
14   AC_CACHE_CHECK([for ULLONG_MAX], gl_cv_ullong_max,
15     [gl_cv_ullong_max=no
16      AC_EGREP_CPP([ULLONG_MAX is defined],
17        [
18         #include <limits.h>
19         #ifdef ULLONG_MAX
20          "ULLONG_MAX is defined"
21         #endif
22        ],
23        [gl_cv_ullong_max=yes])
24      case $gl_cv_ullong_max in
25      no)
26        for gl_expr in \
27          18446744073709551615ULL \
28          4722366482869645213695ULL \
29          340282366920938463463374607431768211455ULL
30        do
31          AC_TRY_COMPILE([],
32            [char test[$gl_expr == (unsigned long long int) -1 ? 1 : -1];
33             static unsigned long long int i = $gl_expr;
34             return i && test;],
35            [gl_cv_ullong_max=$gl_expr])
36          test $gl_cv_ullong_max != no && break
37        done
38      esac])
39   case $gl_cv_ullong_max in
40   yes | no) ;;
41   *)
42     AC_DEFINE_UNQUOTED([ULLONG_MAX], [$gl_cv_ullong_max],
43       [Define as the maximum value of the type 'unsigned long long int',
44        if the system doesn't define it, and if the system has that type.]);;
45   esac
46 ])