This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit cf909c21038d96340d45b131b431a1b7955c551e
Author: fangxinyong <[email protected]>
AuthorDate: Mon Apr 27 20:47:08 2026 +0800

    limits: decouple _POSIX_SSIZE_MAX/_POSIX_SSIZE_MIN from CONFIG_SMALL_MEMORY
    
    Per POSIX.1-2017, _POSIX_SSIZE_MAX is the standard-mandated minimum
    that every compliant implementation must support (32767 = 2^15 - 1).
    Like every other _POSIX_* constant, it is fixed and must not vary
    with build configuration.
    
    Previously _POSIX_SSIZE_MAX was defined as LONG_MAX on normal
    platforms and 32767 only under CONFIG_SMALL_MEMORY, conflating the
    POSIX minimum with the implementation limit.
    
    Lift _POSIX_SSIZE_MAX / _POSIX_SSIZE_MIN out of the CONFIG_SMALL_MEMORY
        _POSIX_SSIZE_MAX    32767   (always)
        _POSIX_SSIZE_MIN   -32768   (always)
    
    The implementation-facing macros SSIZE_MAX / SSIZE_MIN retain their
    previous runtime values by switching on CONFIG_SMALL_MEMORY directly:
        CONFIG_SMALL_MEMORY=y:  SSIZE_MAX = _POSIX_SSIZE_MAX (32767)
        CONFIG_SMALL_MEMORY=n:  SSIZE_MAX = LONG_MAX
    
    Net effect:
        SSIZE_MAX / SSIZE_MIN values unchanged for every build config.
        _POSIX_SSIZE_MAX on non-SMALL_MEMORY builds: LONG_MAX -> 32767
        (a POSIX-correctness fix; no in-tree code references this macro
        outside of <limits.h> itself).
    
    Signed-off-by: fangxinyong <[email protected]>
---
 include/limits.h | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/include/limits.h b/include/limits.h
index 75b5d1fd217..4860b8604fb 100644
--- a/include/limits.h
+++ b/include/limits.h
@@ -110,19 +110,22 @@
 #define _POSIX_SIZE_MAX                         65535        /* See 
sys/types.h */
 #define _POSIX_SIZE_MIN                         0
 
-#define _POSIX_SSIZE_MAX                        32767        /* See 
sys/types.h */
-#define _POSIX_SSIZE_MIN                        -32768
-
 #else /* CONFIG_SMALL_MEMORY */
 
 #define _POSIX_SIZE_MAX                         ULONG_MAX
 #define _POSIX_SIZE_MIN                         0
 
-#define _POSIX_SSIZE_MAX                        LONG_MAX
-#define _POSIX_SSIZE_MIN                        LONG_MIN
-
 #endif /* CONFIG_SMALL_MEMORY */
 
+/* _POSIX_SSIZE_MAX / _POSIX_SSIZE_MIN are the POSIX-mandated minimums
+ * (SSIZE_MAX >= 32767 per POSIX.1-2017). They are fixed constants and
+ * must not vary with build configuration. See SSIZE_MAX / SSIZE_MIN
+ * below for the implementation's actual limit.
+ */
+
+#define _POSIX_SSIZE_MAX                        32767
+#define _POSIX_SSIZE_MIN                        -32768
+
 /* Numerical limits.  These values may be increased from the POSIX minimum
  * values above or made indeterminate
  */
@@ -165,8 +168,15 @@
 #define SIZE_MAX                                _POSIX_SIZE_MAX
 #define SIZE_MIN                                _POSIX_SIZE_MIN
 #define RSIZE_MAX                               _POSIX_SIZE_MAX
-#define SSIZE_MAX                               _POSIX_SSIZE_MAX
-#define SSIZE_MIN                               _POSIX_SSIZE_MIN
+
+#ifdef CONFIG_SMALL_MEMORY
+#  define SSIZE_MAX                             _POSIX_SSIZE_MAX
+#  define SSIZE_MIN                             _POSIX_SSIZE_MIN
+#else
+#  define SSIZE_MAX                             LONG_MAX
+#  define SSIZE_MIN                             LONG_MIN
+#endif
+
 #define STREAM_MAX                              OPEN_MAX
 #define TZNAME_MAX                              _POSIX_TZNAME_MAX
 #define TZ_MAX_TIMES                            CONFIG_LIBC_TZ_MAX_TIMES

Reply via email to