From: Collin Funk Date: Tue, 13 Aug 2024 03:09:01 +0000 (-0700) Subject: termios: Define struct winsize on all platforms. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=afbe284229fc249527b0e76827e67e5e1c7a7399;p=gnulib.git termios: Define struct winsize on all platforms. * doc/posix-headers/termios.texi (termios.h): Mention struct winsize is defined in 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. --- diff --git a/ChangeLog b/ChangeLog index 63b19e0480..b6c173ab03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2024-08-12 Collin Funk + + termios: Define struct winsize on all platforms. + * doc/posix-headers/termios.texi (termios.h): Mention struct winsize is + defined in 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 errno tests: Avoid test failure on Haiku. diff --git a/doc/posix-headers/termios.texi b/doc/posix-headers/termios.texi index cf4da4da3a..87f02db571 100644 --- a/doc/posix-headers/termios.texi +++ b/doc/posix-headers/termios.texi @@ -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 diff --git a/lib/termios.in.h b/lib/termios.in.h index a7c1f3f90a..173cb69786 100644 --- a/lib/termios.in.h +++ b/lib/termios.in.h @@ -48,6 +48,23 @@ extern "C" { /* Get pid_t. */ #include +#if ! @TERMIOS_H_DEFINES_STRUCT_WINSIZE@ +/* On glibc. */ +# if @SYS_IOCTL_H_DEFINES_STRUCT_WINSIZE@ +# include +# 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. */ diff --git a/m4/termios_h.m4 b/m4/termios_h.m4 index 788008eb82..537656d8cc 100644 --- a/m4/termios_h.m4 +++ b/m4/termios_h.m4 @@ -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 ], + [gl_cv_struct_winsize_in_termios_h], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + ]], + [[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 ], + [gl_cv_struct_winsize_in_sys_ioctl_h], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + ]], + [[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 ]], [tcgetsid]) + + AC_SUBST([TERMIOS_H_DEFINES_STRUCT_WINSIZE]) + AC_SUBST([SYS_IOCTL_H_DEFINES_STRUCT_WINSIZE]) ]) # gl_TERMIOS_MODULE_INDICATOR([modulename]) diff --git a/modules/termios b/modules/termios index abc954ceb4..3af20592b9 100644 --- a/modules/termios +++ b/modules/termios @@ -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