* 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 | 6 ++++++ doc/posix-headers/limits.texi | 6 +++--- lib/limits.in.h | 12 ++++++++++++ m4/limits-h.m4 | 21 ++++++++++++++++----- 4 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 51a88b03f1..bdf456941c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2023-05-20 Paul Eggert <egg...@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. diff --git a/doc/posix-headers/limits.texi b/doc/posix-headers/limits.texi index 5fdcd14546..1ba789022c 100644 --- a/doc/posix-headers/limits.texi +++ b/doc/posix-headers/limits.texi @@ -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 diff --git a/lib/limits.in.h b/lib/limits.in.h index 45d46fd689..1d479c3d19 100644 --- a/lib/limits.in.h +++ b/lib/limits.in.h @@ -134,6 +134,18 @@ # 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 diff --git a/m4/limits-h.m4 b/m4/limits-h.m4 index ca0294e550..6a5983ebc2 100644 --- a/m4/limits-h.m4 +++ b/m4/limits-h.m4 @@ -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>. -- 2.39.2