2 * Acess2 POSIX Emulation
3 * - By John Hodge (thePowersGang)
11 #include <acess/sys.h>
12 #include <acess/devices/pty.h>
15 int tcgetattr(int fd, struct termios *termios_p)
22 // Double-check `fd` describes a terminal
23 if( _SysIOCtl(fd, DRV_IOCTL_TYPE, NULL) != DRV_TYPE_TERMINAL ) {
29 memset(termios_p, 0, sizeof(struct termios));
31 // Query kernel for other params
33 _SysIOCtl(fd, PTY_IOCTL_GETMODE, &mode);
35 if( (mode.OutputMode & PTYOMODE_BUFFMT) != PTYBUFFMT_TEXT ) {
36 _SysDebug("Call to tcgetattr when terminal is not in text mode");
40 if(mode.InputMode & PTYIMODE_CANON)
41 termios_p->c_lflag |= ICANON|ECHOE|ECHOK;
42 if(mode.InputMode & PTYIMODE_ECHO)
43 termios_p->c_lflag |= ECHO;
44 // TODO: The more subtle flags
49 int tcsetattr(int fd, int optional_actions, const struct termios *termios_p)
51 _SysDebug("tcsetattr(%i, 0%o, %p)", fd, optional_actions, termios_p);
58 if( !termios_p || (optional_actions & ~(7)) ) {
63 // Double-check `fd` describes a terminal
64 if( _SysIOCtl(fd, DRV_IOCTL_TYPE, NULL) != DRV_TYPE_TERMINAL ) {
69 struct ptymode mode = {0};
71 if(termios_p->c_lflag & ICANON)
72 mode.InputMode |= PTYIMODE_CANON;
73 if(termios_p->c_lflag & ECHO)
74 mode.InputMode |= PTYIMODE_ECHO;
76 _SysDebug("*termios_p = {%x,%x,%x,%x}",
77 termios_p->c_iflag, termios_p->c_oflag, termios_p->c_cflag, termios_p->c_lflag);