From 3ddd4f56df3a75fc634dea7da5ecc5fc59a1b109 Mon Sep 17 00:00:00 2001 From: auronandace Date: Mon, 25 May 2026 16:57:12 +0100 Subject: [PATCH] split out winsize from sys_ioctl header --- src/header/bits_winsize/cbindgen.toml | 13 +++++++++++++ src/header/bits_winsize/mod.rs | 16 ++++++++++++++++ src/header/mod.rs | 1 + src/header/pty/mod.rs | 4 ++-- src/header/sys_ioctl/cbindgen.toml | 4 +++- src/header/sys_ioctl/mod.rs | 15 --------------- src/header/sys_ioctl/redox/mod.rs | 4 +--- src/header/termios/cbindgen.toml | 3 ++- src/header/termios/mod.rs | 5 +---- 9 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 src/header/bits_winsize/cbindgen.toml create mode 100644 src/header/bits_winsize/mod.rs diff --git a/src/header/bits_winsize/cbindgen.toml b/src/header/bits_winsize/cbindgen.toml new file mode 100644 index 0000000000..6140a3e23c --- /dev/null +++ b/src/header/bits_winsize/cbindgen.toml @@ -0,0 +1,13 @@ +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/termios.h.html +# +# This type is split out to include it in the following headers: +# - sys/ioctl.h (Non-POSIX) +# - termios.h (POSIX, where it should be defined) +include_guard = "_RELIBC_BITS_WINSIZE_H" +language = "C" +style = "Tag" +no_includes = true +cpp_compat = true + +[export] +include = ["winsize"] diff --git a/src/header/bits_winsize/mod.rs b/src/header/bits_winsize/mod.rs new file mode 100644 index 0000000000..0d75ae8e74 --- /dev/null +++ b/src/header/bits_winsize/mod.rs @@ -0,0 +1,16 @@ +use crate::platform::types::c_ushort; + +#[repr(C)] +#[derive(Default)] +pub struct winsize { + ws_row: c_ushort, + ws_col: c_ushort, + ws_xpixel: c_ushort, + ws_ypixel: c_ushort, +} + +impl winsize { + pub fn get_row_col(&self) -> (c_ushort, c_ushort) { + (self.ws_row, self.ws_col) + } +} diff --git a/src/header/mod.rs b/src/header/mod.rs index 230f60ed2e..6584bf126c 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -57,6 +57,7 @@ pub mod bits_timeval; pub mod bits_uid_t; #[path = "bits_useconds-t/mod.rs"] pub mod bits_useconds_t; +pub mod bits_winsize; // complex.h implemented in C (currently through openlibm) pub mod cpio; pub mod crypt; diff --git a/src/header/pty/mod.rs b/src/header/pty/mod.rs index 995aef8aec..3620c45581 100644 --- a/src/header/pty/mod.rs +++ b/src/header/pty/mod.rs @@ -29,7 +29,7 @@ pub unsafe extern "C" fn openpty( aslave: *mut c_int, namep: *mut c_char, termp: *const termios::termios, - winp: *const sys_ioctl::winsize, + winp: *const termios::winsize, ) -> c_int { let mut tmp_name = [0; limits::PATH_MAX]; let name = if !namep.is_null() { @@ -63,7 +63,7 @@ pub unsafe extern "C" fn forkpty( pm: *mut c_int, name: *mut c_char, tio: *const termios::termios, - ws: *const sys_ioctl::winsize, + ws: *const termios::winsize, ) -> c_int { let mut m = 0; let mut s = 0; diff --git a/src/header/sys_ioctl/cbindgen.toml b/src/header/sys_ioctl/cbindgen.toml index 66ec318eec..f0adcc9b80 100644 --- a/src/header/sys_ioctl/cbindgen.toml +++ b/src/header/sys_ioctl/cbindgen.toml @@ -1,5 +1,7 @@ include_guard = "_RELIBC_SYS_IOCTL_H" after_includes = """ +#include // for winsize from termios.h + // Shamelessly copy-pasted from musl #define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) ) @@ -21,4 +23,4 @@ cpp_compat = true prefix_with_name = true [export] -include = ["sgttyb", "winsize"] +include = ["sgttyb"] diff --git a/src/header/sys_ioctl/mod.rs b/src/header/sys_ioctl/mod.rs index 2b80f7536f..25b003be00 100644 --- a/src/header/sys_ioctl/mod.rs +++ b/src/header/sys_ioctl/mod.rs @@ -12,21 +12,6 @@ pub struct sgttyb { sg_flags: c_ushort, } -#[repr(C)] -#[derive(Default)] -pub struct winsize { - ws_row: c_ushort, - ws_col: c_ushort, - ws_xpixel: c_ushort, - ws_ypixel: c_ushort, -} - -impl winsize { - pub fn get_row_col(&self) -> (c_ushort, c_ushort) { - (self.ws_row, self.ws_col) - } -} - #[cfg(target_os = "linux")] pub use self::linux::*; diff --git a/src/header/sys_ioctl/redox/mod.rs b/src/header/sys_ioctl/redox/mod.rs index 8b3cf8fc23..aa1e2aa4c3 100644 --- a/src/header/sys_ioctl/redox/mod.rs +++ b/src/header/sys_ioctl/redox/mod.rs @@ -4,15 +4,13 @@ use syscall; use crate::{ error::{Errno, Result, ResultExt}, - header::{errno::EINVAL, fcntl, termios}, + header::{bits_winsize::winsize, errno::EINVAL, fcntl, termios}, platform::{ Pal, Sys, types::{c_int, c_ulong, c_ulonglong, c_void, pid_t}, }, }; -use super::winsize; - mod drm; pub const TCGETS: c_ulong = 0x5401; diff --git a/src/header/termios/cbindgen.toml b/src/header/termios/cbindgen.toml index 459e6e609f..21dddfa3f4 100644 --- a/src/header/termios/cbindgen.toml +++ b/src/header/termios/cbindgen.toml @@ -4,7 +4,8 @@ # - "The header shall define the pid_t type as described in ." sys_includes = [] after_includes = """ -#include // for pid_t from sys/types.h +#include // for pid_t from sys/types.h +#include // for winsize """ include_guard = "_RELIBC_TERMIOS_H" language = "C" diff --git a/src/header/termios/mod.rs b/src/header/termios/mod.rs index 8d40c09e3f..8aae871e4a 100644 --- a/src/header/termios/mod.rs +++ b/src/header/termios/mod.rs @@ -10,7 +10,7 @@ use crate::{ }, }; -pub use crate::header::sys_ioctl::winsize; +pub use crate::header::bits_winsize::winsize; pub use self::sys::*; @@ -39,9 +39,6 @@ pub const TCSANOW: c_int = 0; pub const TCSADRAIN: c_int = 1; pub const TCSAFLUSH: c_int = 2; -#[unsafe(no_mangle)] -pub unsafe extern "C" fn cbindgen_export_winsize(winsize: winsize) {} - /// See . #[cfg(target_os = "linux")] #[repr(C)]