[newlib-cygwin] Fix 32-bit SSIZE_MAX

Eric Blake ericb@sourceware.org
Thu Jul 14 18:39:00 GMT 2016


commit 6795ef7d3793ca3e8528a56e41d5322c57d58a3c
Author: Eric Blake <eblake@redhat.com>
Date:   Wed Jul 13 14:35:43 2016 -0600

    Fix 32-bit SSIZE_MAX
    POSIX requires that SSIZE_MAX have the same type as ssize_t, but
    on 32-bit, we were defining it as a long even though ssize_t
    resolves to an int.  It also requires that SSIZE_MAX be usable
    via preprocessor #if, so we can't cheat and use a cast.
    If this were newlib, I'd have had to hack _intsup.h to probe the
    qualities of size_t (via gcc's __SIZE_TYPE__), similar to how we
    already probe the qualities of int8_t and friends, then cross our
    fingers that ssize_t happens to have the same rank (most systems
    do, but POSIX permits a system where they differ such as size_t
    being long while ssize_t is int).  Unfortunately gcc gives us
    neither __SSIZE_TYPE__ nor __SSIZE_MAX__.  On the other hand, our
    limits.h is specific to cygwin, so we can just shortcut to the
    correct results rather than being generic to all possible ABI.
    Signed-off-by: Eric Blake <eblake@redhat.com>

 winsup/cygwin/include/limits.h | 10 +++++++++-
 winsup/cygwin/release/2.5.3    |  3 +++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/include/limits.h b/winsup/cygwin/include/limits.h
index 2083e3e..cf3c8d0 100644
--- a/winsup/cygwin/include/limits.h
+++ b/winsup/cygwin/include/limits.h
@@ -128,9 +128,17 @@ details. */
 #undef ULLONG_MAX
 #define ULLONG_MAX (LLONG_MAX * 2ULL + 1)
-/* Maximum size of ssize_t */
+/* Maximum size of ssize_t. Sadly, gcc doesn't give us __SSIZE_MAX__
+   the way it does for __SIZE_MAX__.  On the other hand, we happen to
+   know that for Cygwin, ssize_t is 'int' on 32-bit and 'long' on
+   64-bit, and this particular header is specific to Cygwin, so we
+   don't have to jump through hoops. */
 #undef SSIZE_MAX
+#if __WORDSIZE == 64
 #define SSIZE_MAX (__LONG_MAX__)
+#define SSIZE_MAX (__INT_MAX__)
 /* Runtime Invariant Values */
diff --git a/winsup/cygwin/release/2.5.3 b/winsup/cygwin/release/2.5.3
index a27106b..0a27396 100644
--- a/winsup/cygwin/release/2.5.3
+++ b/winsup/cygwin/release/2.5.3
@@ -10,6 +10,9 @@ What changed:
 - Raise number of supported partitions per disk (for raw access) to 63.
   Addresses: https://cygwin.com/ml/cygwin/2016-06/msg00136.html
+- Fix definition of SSIZE_MAX on 32-bit systems.
+  Addresses: https://cygwin.com/ml/cygwin/2016-07/msg00179.html
 Bug Fixes

More information about the Cygwin-cvs mailing list