[COMMITTED,12/31] ada: Fix argument type of read() and write() on windows

Message ID 20250911091904.1505690-12-poulhies@adacore.com
State Committed
Commit bca81f45b90f2cb525f39ad3ade439eeb51c177a
Headers
Series [COMMITTED,01/31] ada: Disable new warning for composite equality ops that can raise Program_Error |

Commit Message

Marc Poulhiès Sept. 11, 2025, 9:18 a.m. UTC
  From: Tonu Naks <naks@adacore.com>

gcc/ada/ChangeLog:

	* libgnat/s-crtl.ads: define unsigned
	* libgnat/s-crtl__mingw.adb (read, write): change arg type

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/s-crtl.ads        | 3 +++
 gcc/ada/libgnat/s-crtl__mingw.adb | 8 ++++----
 2 files changed, 7 insertions(+), 4 deletions(-)
  

Patch

diff --git a/gcc/ada/libgnat/s-crtl.ads b/gcc/ada/libgnat/s-crtl.ads
index 196b0109ab55..5ca7fc468495 100644
--- a/gcc/ada/libgnat/s-crtl.ads
+++ b/gcc/ada/libgnat/s-crtl.ads
@@ -50,6 +50,9 @@  package System.CRTL is
 
    subtype int is Integer;
 
+   type unsigned is mod 2 ** 32;
+   for unsigned'Size use 32;
+
    type long is range -(2 ** (System.Parameters.long_bits - 1))
                    .. +(2 ** (System.Parameters.long_bits - 1)) - 1;
 
diff --git a/gcc/ada/libgnat/s-crtl__mingw.adb b/gcc/ada/libgnat/s-crtl__mingw.adb
index 6b1035974519..8f10cb8c13f4 100644
--- a/gcc/ada/libgnat/s-crtl__mingw.adb
+++ b/gcc/ada/libgnat/s-crtl__mingw.adb
@@ -40,10 +40,10 @@  package body System.CRTL is
    function read (fd : int; buffer : chars; count : size_t) return ssize_t
    is
       function read_raw
-        (fd : int; buffer : chars; count : size_t) return int;
+        (fd : int; buffer : chars; count : unsigned) return int;
       pragma Import (C, read_raw, "read");
    begin
-      return ssize_t (read_raw (fd, buffer, count));
+      return ssize_t (read_raw (fd, buffer, unsigned (count)));
    end read;
 
    -----------
@@ -53,10 +53,10 @@  package body System.CRTL is
    function write (fd : int; buffer : chars; count : size_t) return ssize_t
    is
       function write_raw
-        (fd : int; buffer : chars; count : size_t) return int;
+        (fd : int; buffer : chars; count : unsigned) return int;
       pragma Import (C, write_raw, "write");
    begin
-      return ssize_t (write_raw (fd, buffer, count));
+      return ssize_t (write_raw (fd, buffer, unsigned (count)));
    end write;
 
 end System.CRTL;