aboutsummaryrefslogtreecommitdiff
path: root/m4/size_max.m4
diff options
context:
space:
mode:
authorNils Durner <durner@gnunet.org>2009-05-29 19:20:23 +0000
committerNils Durner <durner@gnunet.org>2009-05-29 19:20:23 +0000
commit179946965cc0f171e4af1bd053b42ec36314c86e (patch)
treedf49518ea91d8a644ecbd0e6a48c26c1e7fe93b3 /m4/size_max.m4
parentc137702c332798fb68622739f61ae06bbf6286df (diff)
downloadgnunet-179946965cc0f171e4af1bd053b42ec36314c86e.tar.gz
gnunet-179946965cc0f171e4af1bd053b42ec36314c86e.zip
cp
Diffstat (limited to 'm4/size_max.m4')
-rw-r--r--m4/size_max.m462
1 files changed, 62 insertions, 0 deletions
diff --git a/m4/size_max.m4 b/m4/size_max.m4
new file mode 100644
index 000000000..bfba811eb
--- /dev/null
+++ b/m4/size_max.m4
@@ -0,0 +1,62 @@
1# size_max.m4 serial 5
2dnl Copyright (C) 2003, 2005-2006 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl From Bruno Haible.
8
9AC_DEFUN([gl_SIZE_MAX],
10[
11 AC_CHECK_HEADERS(stdint.h)
12 dnl First test whether the system already has SIZE_MAX.
13 AC_MSG_CHECKING([for SIZE_MAX])
14 AC_CACHE_VAL([gl_cv_size_max], [
15 gl_cv_size_max=
16 AC_EGREP_CPP([Found it], [
17#include <limits.h>
18#if HAVE_STDINT_H
19#include <stdint.h>
20#endif
21#ifdef SIZE_MAX
22Found it
23#endif
24], gl_cv_size_max=yes)
25 if test -z "$gl_cv_size_max"; then
26 dnl Define it ourselves. Here we assume that the type 'size_t' is not wider
27 dnl than the type 'unsigned long'. Try hard to find a definition that can
28 dnl be used in a preprocessor #if, i.e. doesn't contain a cast.
29 _AC_COMPUTE_INT([sizeof (size_t) * CHAR_BIT - 1], size_t_bits_minus_1,
30 [#include <stddef.h>
31#include <limits.h>], size_t_bits_minus_1=)
32 _AC_COMPUTE_INT([sizeof (size_t) <= sizeof (unsigned int)], fits_in_uint,
33 [#include <stddef.h>], fits_in_uint=)
34 if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then
35 if test $fits_in_uint = 1; then
36 dnl Even though SIZE_MAX fits in an unsigned int, it must be of type
37 dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'.
38 AC_TRY_COMPILE([#include <stddef.h>
39 extern size_t foo;
40 extern unsigned long foo;
41 ], [], fits_in_uint=0)
42 fi
43 dnl We cannot use 'expr' to simplify this expression, because 'expr'
44 dnl works only with 'long' integers in the host environment, while we
45 dnl might be cross-compiling from a 32-bit platform to a 64-bit platform.
46 if test $fits_in_uint = 1; then
47 gl_cv_size_max="(((1U << $size_t_bits_minus_1) - 1) * 2 + 1)"
48 else
49 gl_cv_size_max="(((1UL << $size_t_bits_minus_1) - 1) * 2 + 1)"
50 fi
51 else
52 dnl Shouldn't happen, but who knows...
53 gl_cv_size_max='((size_t)~(size_t)0)'
54 fi
55 fi
56 ])
57 AC_MSG_RESULT([$gl_cv_size_max])
58 if test "$gl_cv_size_max" != yes; then
59 AC_DEFINE_UNQUOTED([SIZE_MAX], [$gl_cv_size_max],
60 [Define as the maximum value of type 'size_t', if the system doesn't define it.])
61 fi
62])