https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=d0d90851f1285478739e0b63a098c02eb5c7d51f

commit d0d90851f1285478739e0b63a098c02eb5c7d51f
Author:     Corinna Vinschen <cori...@vinschen.de>
AuthorDate: Fri Jul 18 10:15:30 2025 +0200
Commit:     Corinna Vinschen <cori...@vinschen.de>
CommitDate: Fri Jul 18 10:59:30 2025 +0200

    Cygwin: sys/termios.h: define struct winsize before using it
    
    Long-standing bug in the sys/termios.h file which, for some reason,
    has never been encountered before.
    
    STC:
    
      #include <sys/termios.h>
    
      int main()
      {
        struct winsize win;
        tcgetwinsize (0, &win);
      }
    
    Result with gcc 12.4.0:
    
      termios-bug.c: In function ‘main’:
      termios-bug.c:7:20: warning: passing argument 2 of ‘tcgetwinsize’ from 
incompatible pointer type [-Wincompatible-pointer-types]
          7 |   tcgetwinsize (0, &win);
            |                    ^~~~
            |                    |
            |                    struct winsize *
      In file included from termios-bug.c:1:
      /usr/include/sys/termios.h:304:42: note: expected ‘struct winsize *’ but 
argument is of type ‘struct winsize *’
        304 | int tcgetwinsize(int fd, struct winsize *winsz);
            |                          ~~~~~~~~~~~~~~~~^~~~~
    
    This warning apparently becomes an error with C23.
    
    The reason is that struct winsize is defined in sys/termios.h after
    using it as argument type in function declarations.  From the compil;er
    perspective it's now a different type , regardless of having the same
    name.
    
    Move declaration of struct winsize up so it's defined before being used.
    
    Reported-by: Zachary Santer <zsan...@gmail.com>
    Suggested-by: Zachary Santer <zsan...@gmail.com>
    Addresses: https://cygwin.com/pipermail/cygwin/2025-July/258474.html
    Fixes: 1fd5e000ace55 ("import winsup-2000-02-17 snapshot")
    Signed-off-by: Corinna Vinschen <cori...@vinschen.de>
    (cherry picked from commit 73600d68227e125af24b7de7c3fccbd4eb66ee03)

Diff:
---
 winsup/cygwin/include/sys/termios.h | 13 ++++++-------
 winsup/cygwin/release/3.6.5         |  5 ++++-
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/winsup/cygwin/include/sys/termios.h 
b/winsup/cygwin/include/sys/termios.h
index d1b4a0af5b15..75e0c53482b1 100644
--- a/winsup/cygwin/include/sys/termios.h
+++ b/winsup/cygwin/include/sys/termios.h
@@ -282,6 +282,12 @@ struct termios
   speed_t      c_ospeed;
 };
 
+struct winsize
+{
+  unsigned short ws_row, ws_col;
+  unsigned short ws_xpixel, ws_ypixel;
+};
+
 #define termio termios
 
 #ifdef __cplusplus
@@ -313,13 +319,6 @@ int tcsetwinsize(int fd, const struct winsize *winsz);
 #define cfgetospeed(tp)                ((tp)->c_ospeed)
 #endif
 
-/* Extra stuff to make porting stuff easier.  */
-struct winsize
-{
-  unsigned short ws_row, ws_col;
-  unsigned short ws_xpixel, ws_ypixel;
-};
-
 #define TIOCGWINSZ (('T' << 8) | 1)
 #define TIOCSWINSZ (('T' << 8) | 2)
 #define TIOCLINUX  (('T' << 8) | 3)
diff --git a/winsup/cygwin/release/3.6.5 b/winsup/cygwin/release/3.6.5
index 471a12a916af..402c8abaeef9 100644
--- a/winsup/cygwin/release/3.6.5
+++ b/winsup/cygwin/release/3.6.5
@@ -1,4 +1,7 @@
 Fixes:
 ------
 
-Fix two minor bugs in clock and POSIX timer handling.
+- Fix two minor bugs in clock and POSIX timer handling.
+
+- Fix an ordering problem in sys/termios.h.
+  Addresses: https://cygwin.com/pipermail/cygwin/2025-July/258474.html

Reply via email to