aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2024-04-09 15:41:10 +0000
committerElliott Hughes <enh@google.com>2024-04-09 15:41:10 +0000
commitb266f6522ff75c65c1112b0bb1e5784d3fefb37f (patch)
tree272990d608b62f703f26f448d33af811934f5bb9
parent252ed5704a08a2ec017d2e0811a27b350dcf84e7 (diff)
downloadbionic-b266f6522ff75c65c1112b0bb1e5784d3fefb37f.tar.gz
Add LINE_MAX.
LINE_MAX is a bad idea from the 1970s that we've ignored until now, but there's already one hack in the AOSP tree (external/ltp) to work around its absence, and kselftests would need another. Both uses are bad code, but bad code exists, and iOS/macOS and musl/glibc all have the same 2048 value, and it is in POSIX, so at least it's consistent idiocy. Hopefully we're not encouraging more of it! Bug: https://github.com/llvm/llvm-project/issues/88119 Change-Id: Ief219c3fe20b3d95da7040c4b9411f997b1c0470
-rw-r--r--libc/include/limits.h3
-rw-r--r--tests/headers/posix/limits_h.c2
-rw-r--r--tests/limits_test.cpp1
3 files changed, 5 insertions, 1 deletions
diff --git a/libc/include/limits.h b/libc/include/limits.h
index 48e7ea9f7..80fc45d2a 100644
--- a/libc/include/limits.h
+++ b/libc/include/limits.h
@@ -136,6 +136,9 @@
#define IOV_MAX 1024
#define SEM_VALUE_MAX 0x3fffffff
+/** Do not use: prefer getline() or asprintf() rather than hard-coding an arbitrary size. */
+#define LINE_MAX _POSIX2_LINE_MAX
+
/* POSIX says these belong in <unistd.h> but BSD has some in <limits.h>. */
#include <bits/posix_limits.h>
diff --git a/tests/headers/posix/limits_h.c b/tests/headers/posix/limits_h.c
index 7e92d8139..0ca80a5ca 100644
--- a/tests/headers/posix/limits_h.c
+++ b/tests/headers/posix/limits_h.c
@@ -130,10 +130,10 @@ static void limits_h() {
MACRO(CHARCLASS_NAME_MAX);
MACRO(COLL_WEIGHTS_MAX);
MACRO(EXPR_NEST_MAX);
- MACRO(LINE_MAX);
MACRO(NGROUPS_MAX);
MACRO(RE_DUP_MAX);
#endif
+ MACRO(LINE_MAX);
MACRO_VALUE(_POSIX_CLOCKRES_MIN, 20000000);
diff --git a/tests/limits_test.cpp b/tests/limits_test.cpp
index e5902ad9c..bc13a3f7f 100644
--- a/tests/limits_test.cpp
+++ b/tests/limits_test.cpp
@@ -21,6 +21,7 @@
TEST(limits, macros) {
ASSERT_EQ(8, CHAR_BIT);
ASSERT_EQ(8 * static_cast<int>(sizeof(int)), WORD_BIT);
+ ASSERT_EQ(2048, LINE_MAX);
ASSERT_EQ(20, NZERO);
#if !defined(MB_LEN_MAX)
#error MB_LEN_MAX