]> Savannah Git Hosting - gnulib.git/commitdiff
termios: Define struct winsize on all platforms.
authorCollin Funk <collin.funk1@gmail.com>
Tue, 13 Aug 2024 03:09:01 +0000 (20:09 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Tue, 13 Aug 2024 03:09:01 +0000 (20:09 -0700)
* doc/posix-headers/termios.texi (termios.h): Mention struct winsize is
defined in <sys/ioctl.h> on glibc.
* lib/termios.in.h (struct winsize): Define or include.
* m4/termios_h.m4 (gl_TERMIOS_H): Check for a definition of struct
winsize.
* modules/termios (Makefile.am): Replace AC_SUBST variables.

ChangeLog
doc/posix-headers/termios.texi
lib/termios.in.h
m4/termios_h.m4
modules/termios

index 63b19e0480b03871afbd829a7b29863de2a6f296..b6c173ab03eed149398f8634eb20cb4c3b09ae66 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-08-12  Collin Funk  <collin.funk1@gmail.com>
+
+       termios: Define struct winsize on all platforms.
+       * doc/posix-headers/termios.texi (termios.h): Mention struct winsize is
+       defined in <sys/ioctl.h> on glibc.
+       * lib/termios.in.h (struct winsize): Define or include.
+       * m4/termios_h.m4 (gl_TERMIOS_H): Check for a definition of struct
+       winsize.
+       * modules/termios (Makefile.am): Replace AC_SUBST variables.
+
 2024-08-12  Bruno Haible  <bruno@clisp.org>
 
        errno tests: Avoid test failure on Haiku.
index cf4da4da3a31db44daaf21d4e1a77954f7b7935c..87f02db57162d016017a0a20bb44eec6ef2771f9 100644 (file)
@@ -18,7 +18,13 @@ glibc on some architectures, FreeBSD 6.4, OpenBSD 4.9, Cygwin 1.7.11.
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-The types @code{struct termios}, @code{cc_t}, @code{speed_t}, @code{tcflag_t}
-are not defined on some platforms:
+The types @code{struct termios}, @code{struct winsize}, @code{cc_t},
+@code{speed_t}, @code{tcflag_t} are not defined on some platforms:
 mingw, MSVC 14.
+
+@item
+@code{struct winsize} is defined in @code{sys/ioctl.h} on some
+platforms:
+glibc
+
 @end itemize
index a7c1f3f90a2c78495c6794a7024aaf06a2098f2a..173cb69786b20730d88a452c591fc1252da346f6 100644 (file)
@@ -48,6 +48,23 @@ extern "C" {
 /* Get pid_t.  */
 #include <sys/types.h>
 
+#if ! @TERMIOS_H_DEFINES_STRUCT_WINSIZE@
+/* On glibc.  */
+# if @SYS_IOCTL_H_DEFINES_STRUCT_WINSIZE@
+#  include <sys/ioctl.h>
+# else
+/* On Windows.  */
+#  if !GNULIB_defined_struct_winsize
+struct winsize
+{
+  unsigned short ws_row;
+  unsigned short ws_col;
+};
+#   define GNULIB_defined_struct_winsize 1
+#  endif
+# endif
+#endif
+
 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
 
 /* The definition of _GL_WARN_ON_USE is copied here.  */
index 788008eb82ca0b21ec7c27e179560823acd2b4a5..537656d8cc58aeaee1168e5f53c5647a0de0f334 100644 (file)
@@ -1,5 +1,5 @@
 # termios_h.m4
-# serial 7
+# serial 8
 dnl Copyright (C) 2010-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -16,6 +16,45 @@ AC_DEFUN_ONCE([gl_TERMIOS_H],
     HAVE_TERMIOS_H=0
   fi
 
+  if test $ac_cv_header_termios_h = yes; then
+    AC_CACHE_CHECK([for struct winsize in <termios.h>],
+      [gl_cv_struct_winsize_in_termios_h],
+      [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <termios.h>
+            ]],
+            [[static struct winsize x; x.ws_row = x.ws_col;]])],
+         [gl_cv_struct_winsize_in_termios_h=yes],
+         [gl_cv_struct_winsize_in_termios_h=no])
+    ])
+    if test $gl_cv_struct_winsize_in_termios_h = no; then
+      AC_CHECK_HEADERS_ONCE([sys/ioctl.h])
+      if test $ac_cv_header_sys_ioctl_h = yes; then
+        AC_CACHE_CHECK([for struct winsize in <sys/ioctl.h>],
+          [gl_cv_struct_winsize_in_sys_ioctl_h],
+          [AC_COMPILE_IFELSE(
+             [AC_LANG_PROGRAM(
+                [[#include <sys/ioctl.h>
+                ]],
+                [[static struct winsize x; x.ws_row = x.ws_col;]])],
+             [gl_cv_struct_winsize_in_sys_ioctl_h=yes],
+             [gl_cv_struct_winsize_in_sys_ioctl_h=no])
+        ])
+      fi
+    fi
+  fi
+
+  TERMIOS_H_DEFINES_STRUCT_WINSIZE=0
+  SYS_IOCTL_H_DEFINES_STRUCT_WINSIZE=0
+  if test "$gl_cv_struct_winsize_in_termios_h" != yes \
+     || test "$gl_cv_struct_winsize_in_sys_ioctl_h" != yes; then
+    if test "$gl_cv_struct_winsize_in_termios_h" = yes; then
+      TERMIOS_H_DEFINES_STRUCT_WINSIZE=1
+    elif test "$gl_cv_struct_winsize_in_sys_ioctl_h" = yes; then
+      SYS_IOCTL_H_DEFINES_STRUCT_WINSIZE=1
+    fi
+  fi
+
   dnl Ensure the type pid_t gets defined.
   AC_REQUIRE([AC_TYPE_PID_T])
 
@@ -24,6 +63,9 @@ AC_DEFUN_ONCE([gl_TERMIOS_H],
   dnl guaranteed by C89.
   gl_WARN_ON_USE_PREPARE([[#include <termios.h>]],
     [tcgetsid])
+
+  AC_SUBST([TERMIOS_H_DEFINES_STRUCT_WINSIZE])
+  AC_SUBST([SYS_IOCTL_H_DEFINES_STRUCT_WINSIZE])
 ])
 
 # gl_TERMIOS_MODULE_INDICATOR([modulename])
index abc954ceb4296bb8c18d9d13bc4a8ccfefc795f0..3af20592b92e15b8736e0c7f5af062526e9bd7cb 100644 (file)
@@ -33,6 +33,8 @@ termios.h: termios.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE
              -e 's/@''GNULIB_TCGETSID''@/$(GNULIB_TCGETSID)/g' \
              -e 's|@''HAVE_DECL_TCGETSID''@|$(HAVE_DECL_TCGETSID)|g' \
              -e 's|@''HAVE_TERMIOS_H''@|$(HAVE_TERMIOS_H)|g' \
+             -e 's|@''TERMIOS_H_DEFINES_STRUCT_WINSIZE''@|$(TERMIOS_H_DEFINES_STRUCT_WINSIZE)|g' \
+             -e 's|@''SYS_IOCTL_H_DEFINES_STRUCT_WINSIZE''@|$(SYS_IOCTL_H_DEFINES_STRUCT_WINSIZE)|g' \
              -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
              $(srcdir)/termios.in.h > $@-t