Skip to content

Commit

Permalink
add tcgetwinsize and tcsetwinsize functions, move struct winsize
Browse files Browse the repository at this point in the history
these have been adopted for future issue of POSIX as the outcome of
Austin Group issue 1151, and are simply functions performing the roles
of the historical ioctls. since struct winsize is being standardized
along with them, its definition is moved to the appropriate header.

there is some chance this will break source files that expect struct
winsize to be defined by sys/ioctl.h without including termios.h. if
this happens, further changes will be needed to have sys/ioctl.h
expose it too.
  • Loading branch information
richfelker committed Aug 25, 2020
1 parent 9d4b25b commit 4d57865
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
7 changes: 0 additions & 7 deletions include/sys/ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ extern "C" {

#define TIOCSER_TEMT 1

struct winsize {
unsigned short ws_row;
unsigned short ws_col;
unsigned short ws_xpixel;
unsigned short ws_ypixel;
};

#define SIOCADDRT 0x890B
#define SIOCDELRT 0x890C
#define SIOCRTMSG 0x890D
Expand Down
10 changes: 10 additions & 0 deletions include/termios.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ typedef unsigned char cc_t;
typedef unsigned int speed_t;
typedef unsigned int tcflag_t;

struct winsize {
unsigned short ws_row;
unsigned short ws_col;
unsigned short ws_xpixel;
unsigned short ws_ypixel;
};

#define NCCS 32

#include <bits/termios.h>
Expand All @@ -27,6 +34,9 @@ int cfsetispeed (struct termios *, speed_t);
int tcgetattr (int, struct termios *);
int tcsetattr (int, int, const struct termios *);

int tcgetwinsize (int, struct winsize *);
int tcsetwinsize (int, const struct winsize *);

int tcsendbreak (int, int);
int tcdrain (int);
int tcflush (int, int);
Expand Down
1 change: 1 addition & 0 deletions src/stdio/__fdopen.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stdio_impl.h"
#include <stdlib.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
Expand Down
1 change: 1 addition & 0 deletions src/stdio/__stdout_write.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "stdio_impl.h"
#include <sys/ioctl.h>
#include <termios.h>

size_t __stdout_write(FILE *f, const unsigned char *buf, size_t len)
{
Expand Down
8 changes: 8 additions & 0 deletions src/termios/tcgetwinsize.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <termios.h>
#include <sys/ioctl.h>
#include "syscall.h"

int tcgetwinsize(int fd, struct winsize *wsz)
{
return syscall(SYS_ioctl, fd, TIOCGWINSZ, wsz);
}
8 changes: 8 additions & 0 deletions src/termios/tcsetwinsize.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <termios.h>
#include <sys/ioctl.h>
#include "syscall.h"

int tcsetwinsize(int fd, const struct winsize *wsz)
{
return syscall(SYS_ioctl, fd, TIOCSWINSZ, wsz);
}
1 change: 1 addition & 0 deletions src/unistd/isatty.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <termios.h>
#include "syscall.h"

int isatty(int fd)
Expand Down

0 comments on commit 4d57865

Please sign in to comment.