Plan 9 from Bell Labs’s /usr/web/sources/contrib/cinap_lenrek/old/linuxemu.old/systty.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <ureg.h>
#include "linuxsys.h"
#include "linux.h"

enum {
	VEOF		=0,
	VEOL		=1,
	VEOL2		=2,
	VERASE		=3,
	VWERASE		=4,
	VKILL		=5,
	VREPRINT		=6,
	VSWTC		=7,
	VINTR		=8,
	VQUIT		=9,
	VSUSP		=10,
	VSTART		=12,
	VSTOP		=13,
	VLNEXT		=14,
	VDISCARD	=15,
	VMIN		=16,
	VTIME		=17,

	/* c_iflag bits */	
	IGNBRK		=0000001,
	BRKINT		=0000002,
	IGNPAR		=0000004,
	PARMRK		=0000010,
	INPCK		=0000020,
	ISTRIP		=0000040,
	INLCR		=0000100,
	IGNCR		=0000200,
	ICRNL		=0000400,
	IXON		=0001000,
	IXOFF		=0002000,
	IXANY		=0004000,
	IUCLC		=0010000,
	IMAXBEL		=0020000,
	IUTF8		=0040000,

	/* c_oflag bits */	
	OPOST		=0000001,
	ONLCR		=0000002,
	OLCUC		=0000004,
	OCRNL		=0000010,
	ONOCR		=0000020,
	ONLRET		=0000040,

	OFILL		=00000100,
	OFDEL		=00000200,
	NLDLY		=00001400,
	NL0			=00000000,
	NL1			=00000400,
	NL2			=00001000,
	NL3			=00001400,
	TABDLY		=00006000,
	TAB0		=00000000,
	TAB1		=00002000,
	TAB2		=00004000,
	TAB3		=00006000,
	CRDLY		=00030000,
	CR0			=00000000,
	CR1			=00010000,
	CR2			=00020000,
	CR3			=00030000,
	FFDLY		=00040000,
	FF0			=00000000,
	FF1			=00040000,
	BSDLY		=00100000,
	BS0			=00000000,
	BS1			=00100000,
	VTDLY		=00200000,
	VT0			=00000000,
	VT1			=00200000,
	XTABS		=01000000,

	/* c_cflag bit meaning */
	CBAUD		=0000037,
	B0			=0000000,
	B50			=0000001,
	B75			=0000002,
	B110		=0000003,
	B134		=0000004,
	B150		=0000005,
	B200		=0000006,
	B300		=0000007,
	B600		=0000010,
	B1200		=0000011,
	B1800		=0000012,
	B2400		=0000013,
	B4800		=0000014,
	B9600		=0000015,
	B19200		=0000016,
	B38400		=0000017,
	EXTA		=0000016,
	EXTB			=0000017,
	CBAUDEX		=0000000,
	B57600		=00020,
	B115200		=00021,
	B230400		=00022,
	B460800		=00023,
	B500000		=00024,
	B576000		=00025,
	B921600		=00026,
	B1000000	=00027,
	B1152000	=00030,
	B1500000	=00031,
	B2000000	=00032,
	B2500000	=00033,
	B3000000	=00034,
	B3500000	=00035,
	B4000000	=00036,

	CSIZE		=00001400,
	CS5			=00000000,
	CS6			=00000400,
	CS7			=00001000,
	CS8			=00001400,

	CSTOPB		=00002000,
	CREAD		=00004000,
	PARENB		=00010000,
	PARODD		=00020000,
	HUPCL		=00040000,

	CLOCAL		=00100000,
	CMSPAR		=010000000000,
	CRTSCTS		=020000000000,

	/* c_lflag bits */	
	ISIG			=0x00000080,
	ICANON		=0x00000100,
	XCASE		=0x00004000,
	ECHO		=0x00000008,
	ECHOE		=0x00000002,
	ECHOK		=0x00000004,
	ECHONL		=0x00000010,
	NOFLSH		=0x80000000,
	TOSTOP		=0x00400000,
	ECHOCTL		=0x00000040,
	ECHOPRT		=0x00000020,
	ECHOKE		=0x00000001,
	FLUSHO		=0x00800000,
	PENDIN		=0x20000000,
	IEXTEN		=0x00000400,

	/* Values for the ACTION argument to `tcflow'.  */
	TCOOFF		=0,
	TCOON		=1,
	TCIOFF		=2,
	TCION		=3,

	/* Values for the QUEUE_SELECTOR argument to `tcflush'.  */
	TCIFLUSH		=0,
	TCOFLUSH	=1,
	TCIOFLUSH	=2,

	/* Values for the OPTIONAL_ACTIONS argument to `tcsetattr'.  */
	TCSANOW	=0,
	TCSADRAIN	=1,
	TCSAFLUSH	=2,

	/* number of control characters */
	NCCS		=19,
};

struct termios {
	uint		c_iflag;		/* input mode flags */
	uint		c_oflag;		/* output mode flags */
	uint		c_cflag;		/* control mode flags */
	uint		c_lflag;		/* local mode flags */
	uchar	c_cc[NCCS];	/* control characters */
	uchar	c_line;		/* line discipline (== c_cc[19]) */
	uint		c_ispeed;		/* input speed */
	uint		c_ospeed;		/* output speed */
};

static int
checktty(int fd)
{
	Dir *d;
	if((d = dirfstat(fd)) == nil)
		return -EINVAL;
	if(strcmp(d->name, "cons")){
		free(d);
		return -ENOTTY;
	}
	free(d);
	return 0;
}

IOCTL(ioctl_TCGETS)
{
	int r;
	struct termios *tios;

	if((r = checktty(fd)) < 0)
		return r;

	tios = (struct termios*)arg;
	tios->c_iflag = IGNBRK | IUTF8;
	tios->c_oflag = 0;
	tios->c_cflag = CS8 | B4000000;
	tios->c_lflag = ISIG;
	memset(tios->c_cc, 0, sizeof(uchar)*NCCS);
	tios->c_line = 0;
	tios->c_ispeed = 4000000;
	tios->c_ospeed = 4000000;

	return 0;
}

IOCTL(ioctl_TCSETS)
{
	int r;
	if((r = checktty(fd)) < 0)
		return r;
	return 0;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.