]> Savannah Git Hosting - gnulib.git/commitdiff
limits-h: define SSIZE_MAX
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 20 May 2023 20:46:19 +0000 (13:46 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 21 May 2023 03:33:22 +0000 (20:33 -0700)
* doc/posix-headers/limits.texi (limits.h): Document this.
* lib/limits.in.h (SSIZE_MAX): Define if not already defined.
* m4/limits-h.m4 (gl_LIMITS_H): Also generate limits.h
if <limits.h> does not define SSIZE_MAX.

ChangeLog
doc/posix-headers/limits.texi
lib/limits.in.h
m4/limits-h.m4

index 51a88b03f1e51632c6432fb9f8c555dd400a09db..bdf456941cf6934fa4206fd53d0f7b5f2fcbc810 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2023-05-20  Paul Eggert  <eggert@cs.ucla.edu>
 
+       limits-h: define SSIZE_MAX
+       * doc/posix-headers/limits.texi (limits.h): Document this.
+       * lib/limits.in.h (SSIZE_MAX): Define if not already defined.
+       * m4/limits-h.m4 (gl_LIMITS_H): Also generate limits.h
+       if <limits.h> does not define SSIZE_MAX.
+
        diffseq: backward compatibility for OFFSET_MAX
        * lib/diffseq.h (OFFSET_MAX): Define only if not already defined.
 
index 5fdcd14546422989cfc9722d5d43f083179c1670..1ba789022c0ef25bb2f4ad6a06c7382b79a871bf 100644 (file)
@@ -27,6 +27,9 @@ glibc 2.32, many others.
 @item
 The macro @code{BOOL_MAX} is not defined with some compilers:
 clang 15.0.6.
+@item
+The macro @code{SSIZE_MAX} is not defined on some platforms:
+MSVC 14.
 @end itemize
 
 Portability problems fixed by Gnulib module @code{gethostname}:
@@ -43,9 +46,6 @@ Portability problems not fixed by Gnulib:
 The macro @code{SSIZE_MAX} has the wrong type,
 albeit with the correct value:
 32-bit glibc 2.24 (on some architectures), Cygwin 2.5.2.
-@item
-The macro @code{SSIZE_MAX} is not defined on some platforms:
-MSVC 14.
 @end itemize
 
 For @code{PATH_MAX}, Gnulib provides a module @code{pathmax} with a header
index 45d46fd6897011dae4d61ffcb4dd7671a9f1e4b0..1d479c3d1922f689c5fd12fbdcbc8e32a67efb42 100644 (file)
 # endif
 #endif
 
+/* Macro specified by POSIX.  */
+
+/* The maximal size_t value.  Although it might not be of ssize_t type
+   as it should be, it's too much trouble to fix this minor detail.  */
+#ifndef SSIZE_MAX
+# ifdef _WIN64
+#  define SSIZE_MAX LLONG_MAX
+# else
+#  define SSIZE_MAX LONG_MAX
+# endif
+#endif
+
 #endif /* _@GUARD_PREFIX@_LIMITS_H */
 #endif /* _@GUARD_PREFIX@_LIMITS_H */
 #endif
index ca0294e5500ec2c8ddab1fd910b0396cb52a6227..6a5983ebc25914b5dece0fd708dc6c7ec0fb5249 100644 (file)
@@ -28,11 +28,22 @@ AC_DEFUN_ONCE([gl_LIMITS_H],
           ]])],
        [gl_cv_header_limits_width=yes],
        [gl_cv_header_limits_width=no])])
-  if test "$gl_cv_header_limits_width" = yes; then
-    GL_GENERATE_LIMITS_H=false
-  else
-    GL_GENERATE_LIMITS_H=true
-  fi
+  GL_GENERATE_LIMITS_H=true
+  AS_IF([test "$gl_cv_header_limits_width" = yes],
+    [AC_CACHE_CHECK([whether limits.h has SSIZE_MAX],
+       [gl_cv_header_limits_ssize_max],
+       [AC_COMPILE_IFELSE(
+          [AC_LANG_SOURCE(
+             [[#include <limits.h>
+               #ifndef SSIZE_MAX
+                 #error "SSIZE_MAX is not defined"
+               #endif
+             ]])],
+          [gl_cv_header_limits_ssize_max=yes],
+          [gl_cv_header_limits_ssize_max=no])])
+     if test "$gl_cv_header_limits_ssize_max" = yes; then
+       GL_GENERATE_LIMITS_H=false
+     fi])
 ])
 
 dnl Unconditionally enables the replacement of <limits.h>.