1
/* typemax.h -- encapsulate max values for long, long long, etc. */
3
/* Copyright (C) 2001 Free Software Foundation, Inc.
5
This file is part of GNU Bash, the Bourne Again SHell.
7
Bash is free software: you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
12
Bash is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with Bash. If not, see <http://www.gnu.org/licenses/>.
22
* NOTE: This should be included after config.h, limits.h, stdint.h, and
33
/* Nonzero if the integer type T is signed. */
35
# define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
39
# define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
40
? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) \
45
# define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
50
# define LLONG_MAX TYPE_MAXIMUM(long long int)
51
# define LLONG_MIN TYPE_MINIMUM(long long int)
54
# define ULLONG_MAX TYPE_MAXIMUM(unsigned long long int)
59
# define ULONG_MAX ((unsigned long) ~(unsigned long) 0)
63
# define LONG_MAX ((long int) (ULONG_MAX >> 1))
64
# define LONG_MIN ((long int) (-LONG_MAX - 1L))
67
#ifndef INT_MAX /* ouch */
68
# define INT_MAX TYPE_MAXIMUM(int)
69
# define INT_MIN TYPE_MINIMUM(int)
70
# define UINT_MAX ((unsigned int) ~(unsigned int)0)
73
/* workaround for gcc bug in versions < 2.7 */
74
#if defined (HAVE_LONG_LONG) && __GNUC__ == 2 && __GNUC_MINOR__ < 7
75
static const unsigned long long int maxquad = ULLONG_MAX;
77
# define ULLONG_MAX maxquad
80
#if !defined (INTMAX_MAX) || !defined (INTMAX_MIN)
82
#if SIZEOF_INTMAX_T == SIZEOF_LONG_LONG
83
# define INTMAX_MAX LLONG_MAX
84
# define INTMAX_MIN LLONG_MIN
85
#elif SIZEOF_INTMAX_T == SIZEOF_LONG
86
# define INTMAX_MAX LONG_MAX
87
# define INTMAX_MIN LONG_MIN
89
# define INTMAX_MAX INT_MAX
90
# define INTMAX_MIN INT_MIN
96
# define SSIZE_MAX 32767 /* POSIX minimum max */
100
# define SIZE_MAX 65535 /* POSIX minimum max */
103
#endif /* _SH_TYPEMAX_H */