about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2019-10-17 19:19:40 -0400
committerRich Felker <dalias@aerifal.cx>2019-10-17 19:23:39 -0400
commit7cc79d10afd43811a486fd5e9fcdf8e45ac599e0 (patch)
tree740e26e12e169f5d2fb1812e65e728593f94f1fe
parent316730cdc7a330cddf288b4e5c1de5daa64e19f4 (diff)
downloadmusl-7cc79d10afd43811a486fd5e9fcdf8e45ac599e0.tar.gz
musl-7cc79d10afd43811a486fd5e9fcdf8e45ac599e0.tar.xz
musl-7cc79d10afd43811a486fd5e9fcdf8e45ac599e0.zip
define LONG_MAX via arch alltypes.h, strip down bits/limits.h
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.
-rw-r--r--arch/aarch64/bits/alltypes.h.in2
-rw-r--r--arch/aarch64/bits/limits.h7
-rw-r--r--arch/arm/bits/alltypes.h.in2
-rw-r--r--arch/arm/bits/limits.h7
-rw-r--r--arch/generic/bits/limits.h0
-rw-r--r--arch/i386/bits/alltypes.h.in1
-rw-r--r--arch/i386/bits/limits.h7
-rw-r--r--arch/m68k/bits/alltypes.h.in1
-rw-r--r--arch/m68k/bits/limits.h7
-rw-r--r--arch/microblaze/bits/alltypes.h.in2
-rw-r--r--arch/microblaze/bits/limits.h7
-rw-r--r--arch/mips/bits/alltypes.h.in2
-rw-r--r--arch/mips/bits/limits.h7
-rw-r--r--arch/mips64/bits/alltypes.h.in2
-rw-r--r--arch/mips64/bits/limits.h7
-rw-r--r--arch/mipsn32/bits/alltypes.h.in2
-rw-r--r--arch/mipsn32/bits/limits.h7
-rw-r--r--arch/or1k/bits/alltypes.h.in1
-rw-r--r--arch/or1k/bits/limits.h7
-rw-r--r--arch/powerpc/bits/alltypes.h.in1
-rw-r--r--arch/powerpc/bits/limits.h7
-rw-r--r--arch/powerpc64/bits/alltypes.h.in2
-rw-r--r--arch/powerpc64/bits/limits.h7
-rw-r--r--arch/riscv64/bits/alltypes.h.in1
-rw-r--r--arch/riscv64/bits/limits.h7
-rw-r--r--arch/s390x/bits/alltypes.h.in1
-rw-r--r--arch/s390x/bits/limits.h7
-rw-r--r--arch/sh/bits/alltypes.h.in2
-rw-r--r--arch/sh/bits/limits.h7
-rw-r--r--arch/x32/bits/alltypes.h.in1
-rw-r--r--arch/x32/bits/limits.h7
-rw-r--r--arch/x86_64/bits/alltypes.h.in1
-rw-r--r--arch/x86_64/bits/limits.h7
-rw-r--r--include/limits.h16
34 files changed, 35 insertions, 117 deletions
diff --git a/arch/aarch64/bits/alltypes.h.in b/arch/aarch64/bits/alltypes.h.in
index ab2c6a26..60973f6a 100644
--- a/arch/aarch64/bits/alltypes.h.in
+++ b/arch/aarch64/bits/alltypes.h.in
@@ -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
index 0226588c..00000000
--- a/arch/aarch64/bits/limits.h
+++ /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
diff --git a/arch/arm/bits/alltypes.h.in b/arch/arm/bits/alltypes.h.in
index 42825bff..a48915e2 100644
--- a/arch/arm/bits/alltypes.h.in
+++ b/arch/arm/bits/alltypes.h.in
@@ -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
index fbc6d238..00000000
--- a/arch/arm/bits/limits.h
+++ /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
index 00000000..e69de29b
--- /dev/null
+++ b/arch/generic/bits/limits.h
diff --git a/arch/i386/bits/alltypes.h.in b/arch/i386/bits/alltypes.h.in
index 95491e4b..6f634009 100644
--- a/arch/i386/bits/alltypes.h.in
+++ b/arch/i386/bits/alltypes.h.in
@@ -3,6 +3,7 @@
 #define _Reg int
 
 #define __BYTE_ORDER 1234
+#define __LONG_MAX 0x7fffffffL
 
 #ifndef __cplusplus
 #ifdef __WCHAR_TYPE__
diff --git a/arch/i386/bits/limits.h b/arch/i386/bits/limits.h
index c340ceb2..07743b6f 100644
--- a/arch/i386/bits/limits.h
+++ b/arch/i386/bits/limits.h
@@ -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
diff --git a/arch/m68k/bits/alltypes.h.in b/arch/m68k/bits/alltypes.h.in
index 75595f24..0aab9679 100644
--- a/arch/m68k/bits/alltypes.h.in
+++ b/arch/m68k/bits/alltypes.h.in
@@ -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
index fbc6d238..00000000
--- a/arch/m68k/bits/limits.h
+++ /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/microblaze/bits/alltypes.h.in b/arch/microblaze/bits/alltypes.h.in
index daea3fcb..171ce71d 100644
--- a/arch/microblaze/bits/alltypes.h.in
+++ b/arch/microblaze/bits/alltypes.h.in
@@ -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
index fbc6d238..00000000
--- a/arch/microblaze/bits/limits.h
+++ /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/mips/bits/alltypes.h.in b/arch/mips/bits/alltypes.h.in
index d5d51289..a01de176 100644
--- a/arch/mips/bits/alltypes.h.in
+++ b/arch/mips/bits/alltypes.h.in
@@ -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
index fbc6d238..00000000
--- a/arch/mips/bits/limits.h
+++ /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/mips64/bits/alltypes.h.in b/arch/mips64/bits/alltypes.h.in
index 34776f07..c05cc6fa 100644
--- a/arch/mips64/bits/alltypes.h.in
+++ b/arch/mips64/bits/alltypes.h.in
@@ -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
index 58698c62..00000000
--- a/arch/mips64/bits/limits.h
+++ /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
diff --git a/arch/mipsn32/bits/alltypes.h.in b/arch/mipsn32/bits/alltypes.h.in
index d5d51289..a01de176 100644
--- a/arch/mipsn32/bits/alltypes.h.in
+++ b/arch/mipsn32/bits/alltypes.h.in
@@ -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
index fbc6d238..00000000
--- a/arch/mipsn32/bits/limits.h
+++ /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/or1k/bits/alltypes.h.in b/arch/or1k/bits/alltypes.h.in
index a2cae2b6..f16a3763 100644
--- a/arch/or1k/bits/alltypes.h.in
+++ b/arch/or1k/bits/alltypes.h.in
@@ -3,6 +3,7 @@
 #define _Reg int
 
 #define __BYTE_ORDER 4321
+#define __LONG_MAX 0x7fffffffL
 
 #ifndef __cplusplus
 TYPEDEF unsigned wchar_t;
diff --git a/arch/or1k/bits/limits.h b/arch/or1k/bits/limits.h
index 3a811c99..fac47aad 100644
--- a/arch/or1k/bits/limits.h
+++ b/arch/or1k/bits/limits.h
@@ -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
diff --git a/arch/powerpc/bits/alltypes.h.in b/arch/powerpc/bits/alltypes.h.in
index 60c7f1ee..2730a24b 100644
--- a/arch/powerpc/bits/alltypes.h.in
+++ b/arch/powerpc/bits/alltypes.h.in
@@ -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
index fbc6d238..00000000
--- a/arch/powerpc/bits/limits.h
+++ /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/powerpc64/bits/alltypes.h.in b/arch/powerpc64/bits/alltypes.h.in
index 395cd7cc..0096ac9a 100644
--- a/arch/powerpc64/bits/alltypes.h.in
+++ b/arch/powerpc64/bits/alltypes.h.in
@@ -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
index 0226588c..00000000
--- a/arch/powerpc64/bits/limits.h
+++ /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
diff --git a/arch/riscv64/bits/alltypes.h.in b/arch/riscv64/bits/alltypes.h.in
index 54dfc7db..b9ab6633 100644
--- a/arch/riscv64/bits/alltypes.h.in
+++ b/arch/riscv64/bits/alltypes.h.in
@@ -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
index 0226588c..00000000
--- a/arch/riscv64/bits/limits.h
+++ /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
diff --git a/arch/s390x/bits/alltypes.h.in b/arch/s390x/bits/alltypes.h.in
index 1f392b1a..64150fcf 100644
--- a/arch/s390x/bits/alltypes.h.in
+++ b/arch/s390x/bits/alltypes.h.in
@@ -3,6 +3,7 @@
 #define _Reg long
 
 #define __BYTE_ORDER 4321
+#define __LONG_MAX 0x7fffffffffffffffL
 
 #ifndef __cplusplus
 TYPEDEF int wchar_t;
diff --git a/arch/s390x/bits/limits.h b/arch/s390x/bits/limits.h
index 86ef7663..07743b6f 100644
--- a/arch/s390x/bits/limits.h
+++ b/arch/s390x/bits/limits.h
@@ -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
diff --git a/arch/sh/bits/alltypes.h.in b/arch/sh/bits/alltypes.h.in
index 5952e9e6..9656416e 100644
--- a/arch/sh/bits/alltypes.h.in
+++ b/arch/sh/bits/alltypes.h.in
@@ -8,6 +8,8 @@
 #define __BYTE_ORDER 1234
 #endif
 
+#define __LONG_MAX 0x7fffffffL
+
 #ifndef __cplusplus
 #ifdef __WCHAR_TYPE__
 TYPEDEF __WCHAR_TYPE__ wchar_t;
diff --git a/arch/sh/bits/limits.h b/arch/sh/bits/limits.h
index c340ceb2..07743b6f 100644
--- a/arch/sh/bits/limits.h
+++ b/arch/sh/bits/limits.h
@@ -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
diff --git a/arch/x32/bits/alltypes.h.in b/arch/x32/bits/alltypes.h.in
index 5d7a1279..0c2dd106 100644
--- a/arch/x32/bits/alltypes.h.in
+++ b/arch/x32/bits/alltypes.h.in
@@ -3,6 +3,7 @@
 #define _Reg long long
 
 #define __BYTE_ORDER 1234
+#define __LONG_MAX 0x7fffffffL
 
 #ifndef __cplusplus
 #ifdef __WCHAR_TYPE__
diff --git a/arch/x32/bits/limits.h b/arch/x32/bits/limits.h
index c340ceb2..07743b6f 100644
--- a/arch/x32/bits/limits.h
+++ b/arch/x32/bits/limits.h
@@ -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
diff --git a/arch/x86_64/bits/alltypes.h.in b/arch/x86_64/bits/alltypes.h.in
index b815b438..d104cb07 100644
--- a/arch/x86_64/bits/alltypes.h.in
+++ b/arch/x86_64/bits/alltypes.h.in
@@ -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/x86_64/bits/limits.h b/arch/x86_64/bits/limits.h
index 86ef7663..07743b6f 100644
--- a/arch/x86_64/bits/limits.h
+++ b/arch/x86_64/bits/limits.h
@@ -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
diff --git a/include/limits.h b/include/limits.h
index 02c2139d..1499eaae 100644
--- a/include/limits.h
+++ b/include/limits.h
@@ -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
@@ -30,8 +26,10 @@
 #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
@@ -53,6 +53,12 @@
 #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