define LONG_MAX via arch alltypes.h, strip down bits/limits.h
authorRich Felker <dalias@aerifal.cx>
Thu, 17 Oct 2019 23:19:40 +0000 (19:19 -0400)
committerRich Felker <dalias@aerifal.cx>
Thu, 17 Oct 2019 23:23:39 +0000 (19:23 -0400)
LLONG_MAX is uniform for all archs we support and plenty of header and
code level logic assumes it is, so it does not make sense for limits.h
bits mechanism to pretend it's variable.

LONG_BIT can be defined in terms of LONG_MAX; there's no reason to put
it in bits.

by moving LONG_MAX definition to __LONG_MAX in alltypes.h and moving
LLONG_MAX out of bits, there are now no plain-C limits that are
defined in the bits header, so the bits header only needs to be
included in the POSIX or extended profiles. this allows the feature
test macro logic to be removed from the bits header, facilitating a
long-term goal of getting such logic out of bits.

having __LONG_MAX in alltypes.h will allow further generalization of
headers.

archs without a constant PAGESIZE no longer need bits/limits.h at all.

34 files changed:
arch/aarch64/bits/alltypes.h.in
arch/aarch64/bits/limits.h [deleted file]
arch/arm/bits/alltypes.h.in
arch/arm/bits/limits.h [deleted file]
arch/generic/bits/limits.h [new file with mode: 0644]
arch/i386/bits/alltypes.h.in
arch/i386/bits/limits.h
arch/m68k/bits/alltypes.h.in
arch/m68k/bits/limits.h [deleted file]
arch/microblaze/bits/alltypes.h.in
arch/microblaze/bits/limits.h [deleted file]
arch/mips/bits/alltypes.h.in
arch/mips/bits/limits.h [deleted file]
arch/mips64/bits/alltypes.h.in
arch/mips64/bits/limits.h [deleted file]
arch/mipsn32/bits/alltypes.h.in
arch/mipsn32/bits/limits.h [deleted file]
arch/or1k/bits/alltypes.h.in
arch/or1k/bits/limits.h
arch/powerpc/bits/alltypes.h.in
arch/powerpc/bits/limits.h [deleted file]
arch/powerpc64/bits/alltypes.h.in
arch/powerpc64/bits/limits.h [deleted file]
arch/riscv64/bits/alltypes.h.in
arch/riscv64/bits/limits.h [deleted file]
arch/s390x/bits/alltypes.h.in
arch/s390x/bits/limits.h
arch/sh/bits/alltypes.h.in
arch/sh/bits/limits.h
arch/x32/bits/alltypes.h.in
arch/x32/bits/limits.h
arch/x86_64/bits/alltypes.h.in
arch/x86_64/bits/limits.h
include/limits.h

index ab2c6a2..60973f6 100644 (file)
@@ -8,6 +8,8 @@
 #define __BYTE_ORDER 1234
 #endif
 
+#define __LONG_MAX 0x7fffffffffffffffL
+
 #ifndef __cplusplus
 TYPEDEF unsigned wchar_t;
 #endif
diff --git a/arch/aarch64/bits/limits.h b/arch/aarch64/bits/limits.h
deleted file mode 100644 (file)
index 0226588..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#define LONG_BIT 64
-#endif
-
-#define LONG_MAX  0x7fffffffffffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
index 42825bf..a48915e 100644 (file)
@@ -8,6 +8,8 @@
 #define __BYTE_ORDER 1234
 #endif
 
+#define __LONG_MAX 0x7fffffffL
+
 #ifndef __cplusplus
 TYPEDEF unsigned wchar_t;
 #endif
diff --git a/arch/arm/bits/limits.h b/arch/arm/bits/limits.h
deleted file mode 100644 (file)
index fbc6d23..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#define LONG_BIT 32
-#endif
-
-#define LONG_MAX  0x7fffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
diff --git a/arch/generic/bits/limits.h b/arch/generic/bits/limits.h
new file mode 100644 (file)
index 0000000..e69de29
index 95491e4..6f63400 100644 (file)
@@ -3,6 +3,7 @@
 #define _Reg int
 
 #define __BYTE_ORDER 1234
+#define __LONG_MAX 0x7fffffffL
 
 #ifndef __cplusplus
 #ifdef __WCHAR_TYPE__
index c340ceb..07743b6 100644 (file)
@@ -1,8 +1 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define PAGESIZE 4096
-#define LONG_BIT 32
-#endif
-
-#define LONG_MAX  0x7fffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
index 75595f2..0aab967 100644 (file)
@@ -3,6 +3,7 @@
 #define _Reg int
 
 #define __BYTE_ORDER 4321
+#define __LONG_MAX 0x7fffffffL
 
 #ifndef __cplusplus
 #ifdef __WCHAR_TYPE__
diff --git a/arch/m68k/bits/limits.h b/arch/m68k/bits/limits.h
deleted file mode 100644 (file)
index fbc6d23..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#define LONG_BIT 32
-#endif
-
-#define LONG_MAX  0x7fffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
index daea3fc..171ce71 100644 (file)
@@ -8,6 +8,8 @@
 #define __BYTE_ORDER 4321
 #endif
 
+#define __LONG_MAX 0x7fffffffL
+
 #ifndef __cplusplus
 TYPEDEF int wchar_t;
 #endif
diff --git a/arch/microblaze/bits/limits.h b/arch/microblaze/bits/limits.h
deleted file mode 100644 (file)
index fbc6d23..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#define LONG_BIT 32
-#endif
-
-#define LONG_MAX  0x7fffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
index d5d5128..a01de17 100644 (file)
@@ -8,6 +8,8 @@
 #define __BYTE_ORDER 4321
 #endif
 
+#define __LONG_MAX 0x7fffffffL
+
 #ifndef __cplusplus
 TYPEDEF int wchar_t;
 #endif
diff --git a/arch/mips/bits/limits.h b/arch/mips/bits/limits.h
deleted file mode 100644 (file)
index fbc6d23..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#define LONG_BIT 32
-#endif
-
-#define LONG_MAX  0x7fffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
index 34776f0..c05cc6f 100644 (file)
@@ -8,6 +8,8 @@
 #define __BYTE_ORDER 4321
 #endif
 
+#define __LONG_MAX 0x7fffffffffffffffL
+
 #ifndef __cplusplus
 TYPEDEF int wchar_t;
 #endif
diff --git a/arch/mips64/bits/limits.h b/arch/mips64/bits/limits.h
deleted file mode 100644 (file)
index 58698c6..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#define LONG_BIT 64
-#endif
-
-#define LONG_MAX 0x7fffffffffffffffL
-#define LLONG_MAX 0x7fffffffffffffffLL
index d5d5128..a01de17 100644 (file)
@@ -8,6 +8,8 @@
 #define __BYTE_ORDER 4321
 #endif
 
+#define __LONG_MAX 0x7fffffffL
+
 #ifndef __cplusplus
 TYPEDEF int wchar_t;
 #endif
diff --git a/arch/mipsn32/bits/limits.h b/arch/mipsn32/bits/limits.h
deleted file mode 100644 (file)
index fbc6d23..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#define LONG_BIT 32
-#endif
-
-#define LONG_MAX  0x7fffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
index a2cae2b..f16a376 100644 (file)
@@ -3,6 +3,7 @@
 #define _Reg int
 
 #define __BYTE_ORDER 4321
+#define __LONG_MAX 0x7fffffffL
 
 #ifndef __cplusplus
 TYPEDEF unsigned wchar_t;
index 3a811c9..fac47aa 100644 (file)
@@ -1,8 +1 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define PAGESIZE 8192
-#define LONG_BIT 32
-#endif
-
-#define LONG_MAX  0x7fffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
index 60c7f1e..2730a24 100644 (file)
@@ -3,6 +3,7 @@
 #define _Reg int
 
 #define __BYTE_ORDER 4321
+#define __LONG_MAX 0x7fffffffL
 
 #ifndef __cplusplus
 #ifdef __WCHAR_TYPE__
diff --git a/arch/powerpc/bits/limits.h b/arch/powerpc/bits/limits.h
deleted file mode 100644 (file)
index fbc6d23..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#define LONG_BIT 32
-#endif
-
-#define LONG_MAX  0x7fffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
index 395cd7c..0096ac9 100644 (file)
@@ -8,6 +8,8 @@
 #define __BYTE_ORDER 1234
 #endif
 
+#define __LONG_MAX 0x7fffffffffffffffL
+
 #ifndef __cplusplus
 TYPEDEF int wchar_t;
 #endif
diff --git a/arch/powerpc64/bits/limits.h b/arch/powerpc64/bits/limits.h
deleted file mode 100644 (file)
index 0226588..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#define LONG_BIT 64
-#endif
-
-#define LONG_MAX  0x7fffffffffffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
index 54dfc7d..b9ab663 100644 (file)
@@ -3,6 +3,7 @@
 #define _Reg long
 
 #define __BYTE_ORDER 1234
+#define __LONG_MAX 0x7fffffffffffffffL
 
 #ifndef __cplusplus
 TYPEDEF int wchar_t;
diff --git a/arch/riscv64/bits/limits.h b/arch/riscv64/bits/limits.h
deleted file mode 100644 (file)
index 0226588..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#define LONG_BIT 64
-#endif
-
-#define LONG_MAX  0x7fffffffffffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
index 1f392b1..64150fc 100644 (file)
@@ -3,6 +3,7 @@
 #define _Reg long
 
 #define __BYTE_ORDER 4321
+#define __LONG_MAX 0x7fffffffffffffffL
 
 #ifndef __cplusplus
 TYPEDEF int wchar_t;
index 86ef766..07743b6 100644 (file)
@@ -1,8 +1 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define PAGESIZE 4096
-#define LONG_BIT 64
-#endif
-
-#define LONG_MAX  0x7fffffffffffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
index 5952e9e..9656416 100644 (file)
@@ -8,6 +8,8 @@
 #define __BYTE_ORDER 1234
 #endif
 
+#define __LONG_MAX 0x7fffffffL
+
 #ifndef __cplusplus
 #ifdef __WCHAR_TYPE__
 TYPEDEF __WCHAR_TYPE__ wchar_t;
index c340ceb..07743b6 100644 (file)
@@ -1,8 +1 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define PAGESIZE 4096
-#define LONG_BIT 32
-#endif
-
-#define LONG_MAX  0x7fffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
index 5d7a127..0c2dd10 100644 (file)
@@ -3,6 +3,7 @@
 #define _Reg long long
 
 #define __BYTE_ORDER 1234
+#define __LONG_MAX 0x7fffffffL
 
 #ifndef __cplusplus
 #ifdef __WCHAR_TYPE__
index c340ceb..07743b6 100644 (file)
@@ -1,8 +1 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define PAGESIZE 4096
-#define LONG_BIT 32
-#endif
-
-#define LONG_MAX  0x7fffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
index b815b43..d104cb0 100644 (file)
@@ -3,6 +3,7 @@
 #define _Reg long
 
 #define __BYTE_ORDER 1234
+#define __LONG_MAX 0x7fffffffffffffffL
 
 #ifndef __cplusplus
 TYPEDEF int wchar_t;
index 86ef766..07743b6 100644 (file)
@@ -1,8 +1 @@
-#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define PAGESIZE 4096
-#define LONG_BIT 64
-#endif
-
-#define LONG_MAX  0x7fffffffffffffffL
-#define LLONG_MAX  0x7fffffffffffffffLL
index 02c2139..1499eaa 100644 (file)
@@ -3,9 +3,7 @@
 
 #include <features.h>
 
-/* Most limits are system-specific */
-
-#include <bits/limits.h>
+#include <bits/alltypes.h> /* __LONG_MAX */
 
 /* Support signed or unsigned plain-char */
 
@@ -17,8 +15,6 @@
 #define CHAR_MAX 127
 #endif
 
-/* Some universal constants... */
-
 #define CHAR_BIT 8
 #define SCHAR_MIN (-128)
 #define SCHAR_MAX 127
 #define INT_MAX  0x7fffffff
 #define UINT_MAX 0xffffffffU
 #define LONG_MIN (-LONG_MAX-1)
+#define LONG_MAX __LONG_MAX
 #define ULONG_MAX (2UL*LONG_MAX+1)
 #define LLONG_MIN (-LLONG_MAX-1)
+#define LLONG_MAX  0x7fffffffffffffffLL
 #define ULLONG_MAX (2ULL*LLONG_MAX+1)
 
 #define MB_LEN_MAX 4
@@ -39,6 +37,8 @@
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 
+#include <bits/limits.h>
+
 #define PIPE_BUF 4096
 #define FILESIZEBITS 64
 #define NAME_MAX 255
 #define TTY_NAME_MAX 32
 #define HOST_NAME_MAX 255
 
+#if LONG_MAX == 0x7fffffffL
+#define LONG_BIT 32
+#else
+#define LONG_BIT 64
+#endif
+
 /* Implementation choices... */
 
 #define PTHREAD_KEYS_MAX 128