diff --git a/abis/linux/termios.h b/abis/linux/termios.h index cccac0e515..3ee43d03cd 100644 --- a/abis/linux/termios.h +++ b/abis/linux/termios.h @@ -26,27 +26,33 @@ typedef unsigned int tcflag_t; #define VEOL2 16 // bitwise flags for c_iflag in struct termios -#define BRKINT 0000002 -#define ICRNL 0000400 #define IGNBRK 0000001 -#define IGNCR 0000200 +#define BRKINT 0000002 #define IGNPAR 0000004 -#define INLCR 0000100 +#define PARMRK 0000010 #define INPCK 0000020 #define ISTRIP 0000040 +#define INLCR 0000100 +#define IGNCR 0000200 +#define ICRNL 0000400 +#define IUCLC 0001000 +#define IXON 0002000 #define IXANY 0004000 #define IXOFF 0010000 -#define IXON 0002000 -#define PARMRK 0000010 +#define IMAXBEL 0020000 +#define IUTF8 0040000 // bitwise flags for c_oflag in struct termios #define OPOST 0000001 +#define OLCUC 0000002 #define ONLCR 0000004 #define OCRNL 0000010 #define ONOCR 0000020 #define ONLRET 0000040 -#define OFDEL 0000200 #define OFILL 0000100 +#define OFDEL 0000200 + +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) #define NLDLY 0000400 #define NL0 0000000 @@ -64,19 +70,20 @@ typedef unsigned int tcflag_t; #define TAB2 0010000 #define TAB3 0014000 -#define XTABS 0014000 #define BSDLY 0020000 #define BS0 0000000 #define BS1 0020000 -#define VTDLY 0040000 -#define VT0 0000000 -#define VT1 0040000 - #define FFDLY 0100000 #define FF0 0000000 #define FF1 0100000 +#endif + +#define VTDLY 0040000 +#define VT0 0000000 +#define VT1 0040000 + // bitwise constants for c_cflag in struct termios #define CSIZE 0000060 #define CS5 0000000 @@ -92,16 +99,37 @@ typedef unsigned int tcflag_t; #define CLOCAL 0004000 // bitwise constants for c_lflag in struct termios +#define ISIG 0000001 +#define ICANON 0000002 #define ECHO 0000010 #define ECHOE 0000020 #define ECHOK 0000040 #define ECHONL 0000100 -#define ICANON 0000002 -#define IEXTEN 0100000 -#define ISIG 0000001 #define NOFLSH 0000200 #define TOSTOP 0000400 +#define IEXTEN 0100000 + +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) + +#define EXTA 0000016 +#define EXTB 0000017 +#define CBAUD 0010017 +#define CBAUDEX 0010000 +#define CIBAUD 002003600000 +#define CMSPAR 010000000000 +#define CRTSCTS 020000000000 + +#define XCASE 0000004 +#define ECHOCTL 0001000 #define ECHOPRT 0002000 +#define ECHOKE 0004000 +#define FLUSHO 0010000 +#define PENDIN 0040000 +#define EXTPROC 0200000 + +#define XTABS 0014000 + +#endif struct termios { tcflag_t c_iflag; diff --git a/abis/mlibc/termios.h b/abis/mlibc/termios.h index 798045590b..49af908483 100644 --- a/abis/mlibc/termios.h +++ b/abis/mlibc/termios.h @@ -89,6 +89,10 @@ typedef unsigned int tcflag_t; #define HUPCL 0x0040 #define CLOCAL 0x0080 +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +#define CBAUD 0x100F +#endif + // bitwise constants for c_lflag in struct termios #define ECHO 0x0001 #define ECHOE 0x0002 diff --git a/options/glibc/include/sys/ioctl.h b/options/glibc/include/sys/ioctl.h index a9a1f1deb3..6121446760 100644 --- a/options/glibc/include/sys/ioctl.h +++ b/options/glibc/include/sys/ioctl.h @@ -8,6 +8,7 @@ #if __MLIBC_LINUX_OPTION # include # include +# include #endif #ifdef __cplusplus diff --git a/options/posix/generic/termios-stubs.cpp b/options/posix/generic/termios-stubs.cpp index 4c4ff04d37..633f1a9a3a 100644 --- a/options/posix/generic/termios-stubs.cpp +++ b/options/posix/generic/termios-stubs.cpp @@ -7,18 +7,27 @@ #include speed_t cfgetispeed(const struct termios *tios) { - return tios->ibaud; + return tios->c_cflag & CBAUD; } + speed_t cfgetospeed(const struct termios *tios) { - return tios->obaud; + return tios->c_cflag & CBAUD; } -int cfsetispeed(struct termios *, speed_t) { - __ensure(!"Not implemented"); - __builtin_unreachable(); + +int cfsetispeed(struct termios *termios, speed_t speed) { + return speed ? cfsetospeed(termios, speed) : 0; } -int cfsetospeed(struct termios *, speed_t) { - __ensure(!"Not implemented"); - __builtin_unreachable(); + +int cfsetospeed(struct termios *termios, speed_t speed) { + if(speed & ~CBAUD) { + errno = EINVAL; + return -1; + } + + termios->c_cflag &= ~CBAUD; + termios->c_cflag |= speed; + + return 0; } void cfmakeraw(struct termios *t) { diff --git a/options/posix/include/sys/ttydefaults.h b/options/posix/include/sys/ttydefaults.h index 7738cfdfe6..c6d04f6f10 100644 --- a/options/posix/include/sys/ttydefaults.h +++ b/options/posix/include/sys/ttydefaults.h @@ -3,20 +3,37 @@ #define _SYS_TTYDEFAULTS_H // Values taken from musl + +#define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY) +#define TTYDEF_OFLAG (OPOST | ONLCR | XTABS) +#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL) +#define TTYDEF_CFLAG (CREAD | CS7 | PARENB | HUPCL) #define TTYDEF_SPEED (B9600) + #define CTRL(x) ((x) & 037) #define CEOF CTRL('d') +#define CEOL '\0' +#define CEOL2 '\0' +#define CSTATUS '\0' + #define CERASE 0177 #define CINTR CTRL('c') #define CKILL CTRL('u') +#define CMIN 1 #define CQUIT 034 #define CSUSP CTRL('z') +#define CTIME 0 +#define CDSUSP CTRL('y') #define CSTART CTRL('q') #define CSTOP CTRL('s') #define CLNEXT CTRL('v') +#define CDISCARD CTRL('o') #define CWERASE CTRL('w') #define CREPRINT CTRL('r') -#define CDISCARD CTRL('o') +#define CEOT CEOF +#define CBRK CEOL +#define CRPRNT CREPRINT +#define CFLUSH CDISCARD #endif // _SYS_TTYDEFAULTS_H diff --git a/options/posix/include/termios.h b/options/posix/include/termios.h index d39d9fe2fb..a5a6a2feeb 100644 --- a/options/posix/include/termios.h +++ b/options/posix/include/termios.h @@ -11,6 +11,10 @@ extern "C" { #include +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +#include +#endif + // baud rate constants for speed_t #define B0 0 #define B50 1 @@ -22,31 +26,43 @@ extern "C" { #define B300 7 #define B600 8 #define B1200 9 -#define B1800 10 -#define B2400 11 -#define B4800 12 -#define B9600 13 -#define B19200 14 -#define B38400 15 -#define B57600 16 -#define B115200 17 -#define B230400 18 +#define B1800 10 +#define B2400 11 +#define B4800 12 +#define B9600 13 +#define B19200 14 +#define B38400 15 +#define B57600 0010001 +#define B115200 0010002 +#define B230400 0010003 +#define B460800 0010004 +#define B500000 0010005 +#define B576000 0010006 +#define B921600 0010007 +#define B1000000 0010010 +#define B1152000 0010011 +#define B1500000 0010012 +#define B2000000 0010013 +#define B2500000 0010014 +#define B3000000 0010015 +#define B3500000 0010016 +#define B4000000 0010017 // constants for tcsetattr() -#define TCSANOW 1 -#define TCSADRAIN 2 -#define TCSAFLUSH 3 +#define TCSANOW 0 +#define TCSADRAIN 1 +#define TCSAFLUSH 2 // constants for tcflush() -#define TCIFLUSH 1 +#define TCIFLUSH 0 +#define TCOFLUSH 1 #define TCIOFLUSH 2 -#define TCOFLUSH 3 // constants for tcflow() -#define TCIOFF 1 -#define TCION 2 -#define TCOOFF 3 -#define TCOON 4 +#define TCOOFF 0 +#define TCOON 1 +#define TCIOFF 2 +#define TCION 3 #define TIOCM_DTR 0x002 #define TIOCM_RTS 0x004 @@ -76,14 +92,6 @@ int tcsetattr(int, int, const struct termios *); #define TIOCSWINSZ 0x5414 #define TIOCGSID 0x5429 -#define ECHOCTL 0001000 -#define FLUSHO 0010000 -#define IMAXBEL 0020000 -#define ECHOKE 0040000 - -#define IUCLC 0001000 -#define IUTF8 0040000 - #ifdef __cplusplus } #endif diff --git a/options/posix/include/unistd.h b/options/posix/include/unistd.h index 6d1115496c..f9d7de8e24 100644 --- a/options/posix/include/unistd.h +++ b/options/posix/include/unistd.h @@ -196,7 +196,7 @@ extern "C" { #define STDIN_FILENO 0 #define STDOUT_FILENO 1 -#define _POSIX_VDISABLE (-1) +#define _POSIX_VDISABLE '\0' #define L_ctermid 20 diff --git a/sysdeps/managarm/generic/file.cpp b/sysdeps/managarm/generic/file.cpp index f4868a006f..35c9ef295c 100644 --- a/sysdeps/managarm/generic/file.cpp +++ b/sysdeps/managarm/generic/file.cpp @@ -729,11 +729,10 @@ int sys_tcgetattr(int fd, struct termios *attr) { } int sys_tcsetattr(int fd, int when, const struct termios *attr) { - if(when != TCSANOW) - mlibc::infoLogger() << "\e[35mmlibc: tcsetattr() when argument ignored\e[39m" - << frg::endlog; - int result; - if(int e = sys_ioctl(fd, TCSETS, const_cast(attr), &result); e) + if(when < TCSANOW || when > TCSAFLUSH) + return EINVAL; + + if(int e = sys_ioctl(fd, TCSETS, const_cast(attr), nullptr); e) return e; return 0; } diff --git a/sysdeps/managarm/generic/ioctl.cpp b/sysdeps/managarm/generic/ioctl.cpp index d95d1c50ad..384c09ef5e 100644 --- a/sysdeps/managarm/generic/ioctl.cpp +++ b/sysdeps/managarm/generic/ioctl.cpp @@ -170,7 +170,8 @@ int sys_ioctl(int fd, unsigned long request, void *arg, int *result) { managarm::fs::GenericIoctlReply resp(getSysdepsAllocator()); resp.ParseFromArray(recv_resp.data(), recv_resp.length()); __ensure(resp.error() == managarm::fs::Errors::SUCCESS); - *result = resp.result(); + if(result) + *result = resp.result(); return 0; } case TIOCSCTTY: {