Define IPPORT_RESERVED in netdb.h for XPG4 and UNIX98 (bug 14838).
[glibc.git] / stdlib / tst-limits.c
blob265b9dbfbbdbf5e1fa81c8b5be02ff53e399d7f9
1 /* It is important that this comes first to not hide effects introduced
2 by other headers. */
3 #include <limits.h>
5 #include <inttypes.h>
6 #include <stdio.h>
9 static long long int
10 bitval (int bits)
12 long long int val = 0;
13 while (bits-- > 0)
14 val |= 1ll << bits;
15 return val;
19 int
20 main (void)
22 int result = 0;
24 #define TEST(name, format, expected) \
25 printf ("%-12s expected = %-20" format " actual = %" format "\n", \
26 #name ":", expected, name); \
27 result |= name != expected
29 /* The limits from ISO C99. */
31 /* We cannot support anything but 8-bit chars. */
32 TEST (CHAR_BIT, "d", 8);
33 TEST (SCHAR_MIN, "d", -128);
34 TEST (SCHAR_MAX, "d", 127);
35 TEST (UCHAR_MAX, "d", 255);
37 TEST (SHRT_MIN, "d", -(1 << (sizeof (short int) * CHAR_BIT - 1)));
38 TEST (SHRT_MAX, "d", (1 << (sizeof (short int) * CHAR_BIT - 1)) - 1);
39 TEST (USHRT_MAX, "d", (1 << sizeof (short int) * CHAR_BIT) - 1);
41 TEST (INT_MIN, "d", (int) -bitval (sizeof (int) * CHAR_BIT - 1) - 1);
42 TEST (INT_MAX, "d", (int) bitval (sizeof (int) * CHAR_BIT - 1));
43 TEST (UINT_MAX, "u",
44 (unsigned int) bitval (sizeof (unsigned int) * CHAR_BIT));
46 TEST (LONG_MIN, "ld",
47 (long int) -bitval (sizeof (long int) * CHAR_BIT - 1) - 1);
48 TEST (LONG_MAX, "ld", (long int) bitval (sizeof (long int) * CHAR_BIT - 1));
49 TEST (ULONG_MAX, "lu",
50 (unsigned long int) bitval (sizeof (unsigned long int) * CHAR_BIT));
52 TEST (LLONG_MIN, "lld", -bitval (sizeof (long long int) * CHAR_BIT - 1) - 1);
53 TEST (LLONG_MAX, "lld", bitval (sizeof (long long int) * CHAR_BIT - 1));
54 TEST (ULLONG_MAX, "llu",
55 (unsigned long long int) bitval (sizeof (unsigned long long int)
56 * CHAR_BIT));
58 /* Values from POSIX and Unix. */
59 #ifdef PAGESIZE
60 TEST (PAGESIZE, "d", getpagesize ());
61 #elif PAGE_SIZE
62 TEST (PAGE_SIZE, "d", getpagesize ());
63 #endif
65 TEST (WORD_BIT, "d", (int) sizeof (int) * CHAR_BIT);
66 TEST (LONG_BIT, "d", (int) sizeof (long int) * CHAR_BIT);
68 return result;