~ubuntu-branches/ubuntu/hardy/prelude-manager/hardy

« back to all changes in this revision

Viewing changes to libmissing/m4/size_max.m4

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Chifflier
  • Date: 2007-03-22 18:09:27 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070322180927-tzvkkuk7yc5m0s9d
Tags: 0.9.7.2-2
* Fix permissions on configuration file (make sure it is not world-readable)
* Update my email address

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# size_max.m4 serial 4
 
1
# size_max.m4 serial 6
2
2
dnl Copyright (C) 2003, 2005-2006 Free Software Foundation, Inc.
3
3
dnl This file is free software; the Free Software Foundation
4
4
dnl gives unlimited permission to copy and/or distribute it,
11
11
  AC_CHECK_HEADERS(stdint.h)
12
12
  dnl First test whether the system already has SIZE_MAX.
13
13
  AC_MSG_CHECKING([for SIZE_MAX])
14
 
  result=
15
 
  AC_EGREP_CPP([Found it], [
 
14
  AC_CACHE_VAL([gl_cv_size_max], [
 
15
    gl_cv_size_max=
 
16
    AC_EGREP_CPP([Found it], [
16
17
#include <limits.h>
17
18
#if HAVE_STDINT_H
18
19
#include <stdint.h>
20
21
#ifdef SIZE_MAX
21
22
Found it
22
23
#endif
23
 
], result=yes)
24
 
  if test -z "$result"; then
25
 
    dnl Define it ourselves. Here we assume that the type 'size_t' is not wider
26
 
    dnl than the type 'unsigned long'. Try hard to find a definition that can
27
 
    dnl be used in a preprocessor #if, i.e. doesn't contain a cast.
28
 
    _AC_COMPUTE_INT([sizeof (size_t) * CHAR_BIT - 1], size_t_bits_minus_1,
29
 
      [#include <stddef.h>
 
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([size_t_bits_minus_1], [sizeof (size_t) * CHAR_BIT - 1],
 
30
        [#include <stddef.h>
30
31
#include <limits.h>], size_t_bits_minus_1=)
31
 
    _AC_COMPUTE_INT([sizeof (size_t) <= sizeof (unsigned int)], fits_in_uint,
32
 
      [#include <stddef.h>], fits_in_uint=)
33
 
    if test -n "$size_t_bits_minus_1" && test -n "$fits_in_uint"; then
34
 
      if test $fits_in_uint = 1; then
35
 
        dnl Even though SIZE_MAX fits in an unsigned int, it must be of type
36
 
        dnl 'unsigned long' if the type 'size_t' is the same as 'unsigned long'.
37
 
        AC_TRY_COMPILE([#include <stddef.h>
38
 
          extern size_t foo;
39
 
          extern unsigned long foo;
40
 
          ], [], fits_in_uint=0)
41
 
      fi
42
 
      dnl We cannot use 'expr' to simplify this expression, because 'expr'
43
 
      dnl works only with 'long' integers in the host environment, while we
44
 
      dnl might be cross-compiling from a 32-bit platform to a 64-bit platform.
45
 
      if test $fits_in_uint = 1; then
46
 
        result="(((1U << $size_t_bits_minus_1) - 1) * 2 + 1)"
 
32
      AC_COMPUTE_INT([fits_in_uint], [sizeof (size_t) <= sizeof (unsigned int)],
 
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
47
51
      else
48
 
        result="(((1UL << $size_t_bits_minus_1) - 1) * 2 + 1)"
 
52
        dnl Shouldn't happen, but who knows...
 
53
        gl_cv_size_max='((size_t)~(size_t)0)'
49
54
      fi
50
 
    else
51
 
      dnl Shouldn't happen, but who knows...
52
 
      result='((size_t)~(size_t)0)'
53
55
    fi
54
 
  fi
55
 
  AC_MSG_RESULT([$result])
56
 
  if test "$result" != yes; then
57
 
    AC_DEFINE_UNQUOTED([SIZE_MAX], [$result],
 
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],
58
60
      [Define as the maximum value of type 'size_t', if the system doesn't define it.])
59
61
  fi
60
62
])
 
63
 
 
64
dnl Autoconf >= 2.61 has AC_COMPUTE_INT built-in.
 
65
dnl Remove this when we can assume autoconf >= 2.61.
 
66
m4_ifdef([AC_COMPUTE_INT], [], [
 
67
  AC_DEFUN([AC_COMPUTE_INT], [_AC_COMPUTE_INT([$2],[$1],[$3],[$4])])
 
68
])