Repository navigation
include/limits.h: decouple _POSIX_* invariant constants from Kconfig - #20765
Merged
Merged
Conversation
According to IEEE Std 1003.1 (POSIX), constants prefixed with _POSIX_*
and _POSIX2_* are invariant minimum values guaranteed by the standard,
not configurable implementation limits.
1. include/limits.h:
- Restore _POSIX_* and _POSIX2_* constants to standard-defined
invariant minimums (e.g. _POSIX_NAME_MAX = 14, _POSIX_PATH_MAX = 256,
_POSIX_ARG_MAX = 4096, _POSIX2_LINE_MAX = 2048, _POSIX_OPEN_MAX = 20).
- Direct implementation limits (NAME_MAX, PATH_MAX, ARG_MAX, LINE_MAX,
OPEN_MAX, NGROUPS_MAX, AIO_LISTIO_MAX) to their Kconfig values.
- Align STREAM_MAX with OPEN_MAX and provide fallback CONFIG_PATH_MAX
of at least 256 so implementation limits satisfy POSIX invariants.
- Define CLOCK_MAX with 64-bit fallback (int64_t clock_t).
2. include/stdio.h:
- Include <limits.h> and define FILENAME_MAX as PATH_MAX and
FOPEN_MAX as STREAM_MAX to align published stream and file limits.
3. include/sched.h:
- Guard PTHREAD_KEYS_MAX with #ifndef to avoid redefinition.
4. include/unistd.h:
- Set _POSIX_GETPW_R_SIZE_MAX to invariant 1024.
5. fs/vfs/fs_link.c:
- Check link count against LINK_MAX instead of _POSIX_LINK_MAX.
6. sched/mqueue/mqueue.h:
- Set MQ_PRIO_MAX to UCHAR_MAX instead of _POSIX_MQ_PRIO_MAX.
7. libs/libc/unistd/lib_pathconf.c & lib_sysconf.c:
- Query runtime implementation limits (NAME_MAX, PIPE_BUF, AIO_MAX,
CONFIG_LIBC_PASSWD_LINESIZE).
Resolves apache#15464.
Signed-off-by: Swatantra Yadav <[email protected]>
Swatantra-66
requested review from
Donny9,
GUIDINGLI,
davids5,
hartmannathan,
jerpelea,
pussuw,
simbit18,
xiaoxiang781216 and
yamt
as code owners
October 17, 2026 23:08
xiaoxiang781216
approved these changes
Oct 18, 2026
acassis
approved these changes
Oct 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
According to IEEE Std 1003.1 (POSIX), constants prefixed with
_POSIX_*and_POSIX2_*specify invariant minimum limits that any conforming implementation must support, not configurable implementation-specific maximums (issue #15464). Previously, NuttX defined several_POSIX_*constants using Kconfig options (e.g.,CONFIG_NAME_MAX,CONFIG_PATH_MAX,CONFIG_LIBC_OPEN_MAX), which violated POSIX guarantees and caused discrepancies when configurations used values lower than the standard minimums.This PR addresses issue #15464 and audits in-tree consumers:
include/limits.h:_POSIX_NAME_MAX = 14,_POSIX_PATH_MAX = 256,_POSIX_ARG_MAX = 4096,_POSIX2_LINE_MAX = 2048,_POSIX_OPEN_MAX = 20,_POSIX_CHILD_MAX = 25,_POSIX_NGROUPS_MAX = 8,_POSIX_STREAM_MAX = 8,_POSIX_TZNAME_MAX = 6,_POSIX_MQ_PRIO_MAX = 32,_POSIX_SEM_NSEMS_MAX = 256,_POSIX_SEM_VALUE_MAX = 32767,_POSIX_CLOCKRES_MIN = 20000000,_POSIX_AIO_LISTIO_MAX = 2).NAME_MAX,PATH_MAX,ARG_MAX,LINE_MAX,OPEN_MAX,NGROUPS_MAX,AIO_LISTIO_MAX) directly to their Kconfig values.CONFIG_PATH_MAXto256so unconfigured builds meet_POSIX_PATH_MAX.STREAM_MAXasOPEN_MAXand setCLOCK_MAXtoINT64_MAXwithLLONG_MAXfallback.PTHREAD_KEYS_MAXwith#ifndef.include/stdio.h:<limits.h>, definedFILENAME_MAX PATH_MAXandFOPEN_MAX STREAM_MAXto strictly align file and stream limits (FOPEN_MAX == STREAM_MAX == OPEN_MAX).include/sched.h:PTHREAD_KEYS_MAXwith#ifndef PTHREAD_KEYS_MAX.include/unistd.h:_POSIX_GETPW_R_SIZE_MAX 1024.fs/vfs/fs_link.c:LINK_MAX(128) instead of_POSIX_LINK_MAX(8).sched/mqueue/mqueue.h:MQ_PRIO_MAXtoUCHAR_MAXinstead of_POSIX_MQ_PRIO_MAX(32) to prevent rejecting valid priorities up to 255.libs/libc/unistd/lib_pathconf.c&lib_sysconf.c:NAME_MAX,PIPE_BUF,AIO_MAX,CONFIG_LIBC_PASSWD_LINESIZE).Impact
_POSIX_*guarantees experienced unexpected overflows or failures.NAME_MAX,PATH_MAX,OPEN_MAX, etc.) remain fully user-configurable via Kconfig for resource-constrained targets.Testing
./tools/checkpatch.sh -u HEAD(0 errors, 0 warnings)../tools/nxstyleacross all modified files (0 errors, 0 warnings).Resolves #15464.