Index | Thread | Search

From:
finxx <me@finxx.xyz>
Subject:
Re: Implement tcgetwinsize and tcsetwinsize
To:
enh@google.com, guenther@gmail.com
Cc:
me@finxx.xyz, tech@openbsd.org
Date:
Sun, 23 Feb 2025 20:46:56 -0600

Download raw body.

Thread
  • finxx:

    Implement tcgetwinsize and tcsetwinsize

Apologies for overlooking the visibility macros. The patch below
addresses visibility, and moves struct winsize to <termios.h>.

diff c077581a317e8f39c250c631d6d29b01a97e7f8a HEAD
commit - c077581a317e8f39c250c631d6d29b01a97e7f8a
commit + 2cc73d4a67b9ac3bc796f69e9de4024f25472ff3
blob - 62a2d7a676481ae3fd947c15e237d4a5b018c1ca
blob + 77a082d7a35e751473ea281fe95996fd73066a50
--- sys/sys/termios.h
+++ sys/sys/termios.h
@@ -261,6 +261,19 @@ typedef __pid_t		pid_t;
 #endif
 #endif
 
+/*
+ * Window/terminal size structure.  This information is stored by the kernel
+ * in order to provide a consistent interface, but is not used by the kernel.
+ */
+#if __BSD_VISIBLE || __POSIX_VISIBLE >= 202405
+struct winsize {
+        unsigned short  ws_row;         /* rows, in characters */
+        unsigned short  ws_col;         /* columns, in characters */
+        unsigned short  ws_xpixel;      /* horizontal size, pixels */
+        unsigned short  ws_ypixel;      /* vertical size, pixels */
+};
+#endif
+
 __BEGIN_DECLS
 speed_t	cfgetispeed(const struct termios *);
 speed_t	cfgetospeed(const struct termios *);
@@ -272,11 +285,14 @@ int	tcdrain(int);
 int	tcflow(int, int);
 int	tcflush(int, int);
 int	tcsendbreak(int, int);
+
+#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809
+pid_t	tcgetsid(int);
+#endif
+
+#if __POSIX_VISIBLE >= 202405
 int	tcgetwinsize(int, struct winsize *);
 int	tcsetwinsize(int, const struct winsize *);
-
-#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809
-pid_t	tcgetsid(int);
 #endif
 
 #if __BSD_VISIBLE
blob - 82af7e8fba72d678f9fbdb15a6e575531daac44e
blob + 55e6482b6dab56eb51fba86cf274231c45fd4e16
--- sys/sys/ttycom.h
+++ sys/sys/ttycom.h
@@ -44,16 +44,8 @@
 
 /* Tty ioctl's. */
 
-/*
- * Window/terminal size structure.  This information is stored by the kernel
- * in order to provide a consistent interface, but is not used by the kernel.
- */
-struct winsize {
-	unsigned short	ws_row;		/* rows, in characters */
-	unsigned short	ws_col;		/* columns, in characters */
-	unsigned short	ws_xpixel;	/* horizontal size, pixels */
-	unsigned short	ws_ypixel;	/* vertical size, pixels */
-};
+/* struct winsize used to be declared here, but was moved to <termios.h>. */
+#include <termios.h>
 
 struct tstamps {
 	int	ts_set;		/* TIOCM_CAR and/or TIOCM_CTS */