2 * Acess2 POSIX Emulation
3 * - By John Hodge (thePowersGang)
11 #include <acess/sys.h>
12 #include <acess/devices/pty.h>
15 speed_t cfgetospeed(const struct termios *termios_p)
17 return termios_p->c_oflag & CBAUD;
20 int tcgetattr(int fd, struct termios *termios_p)
27 // Double-check `fd` describes a terminal
28 if( _SysIOCtl(fd, DRV_IOCTL_TYPE, NULL) != DRV_TYPE_TERMINAL ) {
34 memset(termios_p, 0, sizeof(struct termios));
36 // Query kernel for other params
38 _SysIOCtl(fd, PTY_IOCTL_GETMODE, &mode);
40 if( (mode.OutputMode & PTYOMODE_BUFFMT) != PTYBUFFMT_TEXT ) {
41 _SysDebug("Call to tcgetattr when terminal is not in text mode");
45 if(mode.InputMode & PTYIMODE_CANON)
46 termios_p->c_lflag |= ICANON|ECHOE|ECHOK;
47 if(mode.InputMode & PTYIMODE_ECHO)
48 termios_p->c_lflag |= ECHO;
49 // TODO: The more subtle flags
54 int tcsetattr(int fd, int optional_actions, const struct termios *termios_p)
56 _SysDebug("tcsetattr(%i, 0%o, %p)", fd, optional_actions, termios_p);
63 if( !termios_p || (optional_actions & ~(7)) ) {
67 _SysDebug("*termios_p = {%x,%x,%x,%x}",
68 termios_p->c_iflag, termios_p->c_oflag, termios_p->c_cflag, termios_p->c_lflag);
70 // Double-check `fd` describes a terminal
71 if( _SysIOCtl(fd, DRV_IOCTL_TYPE, NULL) != DRV_TYPE_TERMINAL ) {
76 struct ptymode mode = {0,0};
78 if(termios_p->c_lflag & ICANON)
79 mode.InputMode |= PTYIMODE_CANON;
80 if(termios_p->c_lflag & ECHO)
81 mode.InputMode |= PTYIMODE_ECHO;
83 _SysIOCtl(fd, PTY_IOCTL_SETMODE, &mode);