From c94f031be52031bdfaef5c4757459138d78aac0c Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Fri, 28 Jun 2024 10:46:06 +0200 Subject: [PATCH] Add tcsetwinsize(2). --- libc/Makefile | 1 + libc/include/termios.h | 8 ++++++-- libc/termios/tcsetwinsize.c | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 libc/termios/tcsetwinsize.c diff --git a/libc/Makefile b/libc/Makefile index 0f03296c..6194e004 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -661,6 +661,7 @@ termios/tcgetwinsize.o \ termios/tcsendbreak.o \ termios/tcsetattr.o \ termios/tcsetblob.o \ +termios/tcsetwinsize.o \ time/clock_getres.o \ time/clock_gettime.o \ time/clock_gettimeres.o \ diff --git a/libc/include/termios.h b/libc/include/termios.h index a801d53f..49328b27 100644 --- a/libc/include/termios.h +++ b/libc/include/termios.h @@ -27,7 +27,7 @@ #include #include -#if __USE_SORTIX +#if __USE_SORTIX || 202405L <= __USE_POSIX #include #endif @@ -67,13 +67,17 @@ pid_t tcgetsid(int); int tcsendbreak(int, int); int tcsetattr(int, int, const struct termios*); +#if __USE_SORTIX || 202405L <= __USE_POSIX +int tcgetwinsize(int, struct winsize*); +int tcsetwinsize(int, const struct winsize*); +#endif + /* Functions that are Sortix extensions. */ #if __USE_SORTIX int mkpty(int*, int*, int); ssize_t tcgetblob(int, const char*, void*, size_t); ssize_t tcsetblob(int, const char*, const void*, size_t); int tcgetwincurpos(int, struct wincurpos*); -int tcgetwinsize(int, struct winsize*); #endif #ifdef __cplusplus diff --git a/libc/termios/tcsetwinsize.c b/libc/termios/tcsetwinsize.c new file mode 100644 index 00000000..58f450b4 --- /dev/null +++ b/libc/termios/tcsetwinsize.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 Jonas 'Sortie' Termansen. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * termios/tcsetwinsize.c + * Set the terminal resolution. + */ + +#include + +#include + +int tcsetwinsize(int fd, const struct winsize* ws) +{ + return ioctl(fd, TIOCSWINSZ, ws); +}