xref: /csrg-svn/sys/hp/hpux/hpux_tty.c (revision 57307)
141486Smckusick /*
241486Smckusick  * Copyright (c) 1988 University of Utah.
341486Smckusick  * Copyright (c) 1990 The Regents of the University of California.
441486Smckusick  * All rights reserved.
541486Smckusick  *
641486Smckusick  * This code is derived from software contributed to Berkeley by
741486Smckusick  * the Systems Programming Group of the University of Utah Computer
841486Smckusick  * Science Department.
941486Smckusick  *
1041486Smckusick  * %sccs.include.redist.c%
1141486Smckusick  *
12*57307Shibler  * from: Utah $Hdr: hpux_tty.c 1.12 92/04/15$
1341486Smckusick  *
14*57307Shibler  *	@(#)hpux_tty.c	7.14 (Berkeley) 12/27/92
1541486Smckusick  */
1641486Smckusick 
1741486Smckusick /*
1841486Smckusick  * stty/gtty/termio emulation stuff
1941486Smckusick  */
2041486Smckusick #ifdef HPUXCOMPAT
2141486Smckusick 
2256506Sbostic #include <sys/param.h>
2356506Sbostic #include <sys/systm.h>
2456506Sbostic #include <sys/filedesc.h>
2556506Sbostic #include <sys/ioctl.h>
2656506Sbostic #include <sys/proc.h>
2756506Sbostic #include <sys/tty.h>
2856506Sbostic #include <sys/file.h>
2956506Sbostic #include <sys/conf.h>
3056506Sbostic #include <sys/buf.h>
3156506Sbostic #include <sys/kernel.h>
3241486Smckusick 
3356506Sbostic #include <hp/hpux/hpux.h>
3456506Sbostic #include <hp/hpux/hpux_termio.h>
3541486Smckusick 
3641486Smckusick /*
3744341Shibler  * Map BSD/POSIX style termios info to and from SYS5 style termio stuff.
3841486Smckusick  */
3948477Skarels hpuxtermio(fp, com, data, p)
4041486Smckusick 	struct file *fp;
4141486Smckusick 	caddr_t data;
4248477Skarels 	struct proc *p;
4341486Smckusick {
4444341Shibler 	struct termios tios;
4555830Shibler 	struct hpuxtermios htios;
4644341Shibler 	int line, error, (*ioctlrout)();
4755830Shibler 	int newi = 0;
4841486Smckusick 
4941486Smckusick 	ioctlrout = fp->f_ops->fo_ioctl;
5041486Smckusick 	switch (com) {
5155830Shibler 	case HPUXTCGETATTR:
5255830Shibler 		newi = 1;
5355830Shibler 		/* fall into ... */
5441486Smckusick 	case HPUXTCGETA:
5544341Shibler 		/*
5644341Shibler 		 * Get BSD terminal state
5744341Shibler 		 */
5848477Skarels 		if (error = (*ioctlrout)(fp, TIOCGETA, (caddr_t)&tios, p))
5941486Smckusick 			break;
6055830Shibler 		bzero((char *)&htios, sizeof htios);
6144341Shibler 		/*
6244341Shibler 		 * Set iflag.
6344341Shibler 		 * Same through ICRNL, no BSD equivs for IUCLC, IENQAK
6444341Shibler 		 */
6555830Shibler 		htios.c_iflag = tios.c_iflag & 0x1ff;
6644341Shibler 		if (tios.c_iflag & IXON)
6755830Shibler 			htios.c_iflag |= TIO_IXON;
6844341Shibler 		if (tios.c_iflag & IXOFF)
6955830Shibler 			htios.c_iflag |= TIO_IXOFF;
7044341Shibler 		if (tios.c_iflag & IXANY)
7155830Shibler 			htios.c_iflag |= TIO_IXANY;
7244341Shibler 		/*
7344341Shibler 		 * Set oflag.
7444341Shibler 		 * No BSD equivs for OLCUC/OCRNL/ONOCR/ONLRET/OFILL/OFDEL
7544341Shibler 		 * or any of the delays.
7644341Shibler 		 */
7744341Shibler 		if (tios.c_oflag & OPOST)
7855830Shibler 			htios.c_oflag |= TIO_OPOST;
7944341Shibler 		if (tios.c_oflag & ONLCR)
8055830Shibler 			htios.c_oflag |= TIO_ONLCR;
8144341Shibler 		if (tios.c_oflag & OXTABS)
8255830Shibler 			htios.c_oflag |= TIO_TAB3;
8344341Shibler 		/*
8444341Shibler 		 * Set cflag.
8544341Shibler 		 * Baud from ospeed, rest from cflag.
8644341Shibler 		 */
8755830Shibler 		htios.c_cflag = bsdtohpuxbaud(tios.c_ospeed);
8844341Shibler 		switch (tios.c_cflag & CSIZE) {
8944341Shibler 		case CS5:
9055830Shibler 			htios.c_cflag |= TIO_CS5; break;
9144341Shibler 		case CS6:
9255830Shibler 			htios.c_cflag |= TIO_CS6; break;
9344341Shibler 		case CS7:
9455830Shibler 			htios.c_cflag |= TIO_CS7; break;
9544341Shibler 		case CS8:
9655830Shibler 			htios.c_cflag |= TIO_CS8; break;
9741486Smckusick 		}
9844341Shibler 		if (tios.c_cflag & CSTOPB)
9955830Shibler 			htios.c_cflag |= TIO_CSTOPB;
10044341Shibler 		if (tios.c_cflag & CREAD)
10155830Shibler 			htios.c_cflag |= TIO_CREAD;
10244341Shibler 		if (tios.c_cflag & PARENB)
10355830Shibler 			htios.c_cflag |= TIO_PARENB;
10444341Shibler 		if (tios.c_cflag & PARODD)
10555830Shibler 			htios.c_cflag |= TIO_PARODD;
10644341Shibler 		if (tios.c_cflag & HUPCL)
10755830Shibler 			htios.c_cflag |= TIO_HUPCL;
10844341Shibler 		if (tios.c_cflag & CLOCAL)
10955830Shibler 			htios.c_cflag |= TIO_CLOCAL;
11044341Shibler 		/*
11144341Shibler 		 * Set lflag.
11244341Shibler 		 * No BSD equiv for XCASE.
11344341Shibler 		 */
11444341Shibler 		if (tios.c_lflag & ECHOE)
11555830Shibler 			htios.c_lflag |= TIO_ECHOE;
11644341Shibler 		if (tios.c_lflag & ECHOK)
11755830Shibler 			htios.c_lflag |= TIO_ECHOK;
11844341Shibler 		if (tios.c_lflag & ECHO)
11955830Shibler 			htios.c_lflag |= TIO_ECHO;
12044341Shibler 		if (tios.c_lflag & ECHONL)
12155830Shibler 			htios.c_lflag |= TIO_ECHONL;
12244341Shibler 		if (tios.c_lflag & ISIG)
12355830Shibler 			htios.c_lflag |= TIO_ISIG;
12444341Shibler 		if (tios.c_lflag & ICANON)
12555830Shibler 			htios.c_lflag |= TIO_ICANON;
12644341Shibler 		if (tios.c_lflag & NOFLSH)
12755830Shibler 			htios.c_lflag |= TIO_NOFLSH;
12844341Shibler 		/*
12944341Shibler 		 * Line discipline
13044341Shibler 		 */
13155830Shibler 		if (!newi) {
13255830Shibler 			line = 0;
13355830Shibler 			(void) (*ioctlrout)(fp, TIOCGETD, (caddr_t)&line, p);
13455830Shibler 			htios.c_reserved = line;
13555830Shibler 		}
13644341Shibler 		/*
13755830Shibler 		 * Set editing chars.
13855830Shibler 		 * No BSD equiv for VSWTCH.
13944341Shibler 		 */
14055830Shibler 		htios.c_cc[HPUXVINTR] = tios.c_cc[VINTR];
14155830Shibler 		htios.c_cc[HPUXVQUIT] = tios.c_cc[VQUIT];
14255830Shibler 		htios.c_cc[HPUXVERASE] = tios.c_cc[VERASE];
14355830Shibler 		htios.c_cc[HPUXVKILL] = tios.c_cc[VKILL];
14455830Shibler 		htios.c_cc[HPUXVEOF] = tios.c_cc[VEOF];
14555830Shibler 		htios.c_cc[HPUXVEOL] = tios.c_cc[VEOL];
14655830Shibler 		htios.c_cc[HPUXVEOL2] = tios.c_cc[VEOL2];
14755830Shibler 		htios.c_cc[HPUXVSWTCH] = 0;
14855830Shibler 		htios.c_cc[HPUXVMINS] = tios.c_cc[VMIN];
14955830Shibler 		htios.c_cc[HPUXVTIMES] = tios.c_cc[VTIME];
15055830Shibler 		htios.c_cc[HPUXVSUSP] = tios.c_cc[VSUSP];
15155830Shibler 		htios.c_cc[HPUXVSTART] = tios.c_cc[VSTART];
15255830Shibler 		htios.c_cc[HPUXVSTOP] = tios.c_cc[VSTOP];
15355830Shibler 		if (newi)
15455830Shibler 			bcopy((char *)&htios, data, sizeof htios);
15555830Shibler 		else
15655830Shibler 			termiostotermio(&htios, (struct hpuxtermio *)data);
15741486Smckusick 		break;
15841486Smckusick 
15955830Shibler 	case HPUXTCSETATTR:
16055830Shibler 	case HPUXTCSETATTRD:
16155830Shibler 	case HPUXTCSETATTRF:
16255830Shibler 		newi = 1;
16355830Shibler 		/* fall into ... */
16441486Smckusick 	case HPUXTCSETA:
16541486Smckusick 	case HPUXTCSETAW:
16641486Smckusick 	case HPUXTCSETAF:
16744341Shibler 		/*
16844341Shibler 		 * Get old characteristics and determine if we are a tty.
16944341Shibler 		 */
17048477Skarels 		if (error = (*ioctlrout)(fp, TIOCGETA, (caddr_t)&tios, p))
17141486Smckusick 			break;
17256314Shibler 		if (newi)
17356314Shibler 			bcopy(data, (char *)&htios, sizeof htios);
17456314Shibler 		else
17556314Shibler 			termiototermios((struct termio *)data, &htios, &tios);
17644341Shibler 		/*
17744341Shibler 		 * Set iflag.
17844341Shibler 		 * Same through ICRNL, no HP-UX equiv for IMAXBEL
17944341Shibler 		 */
18044341Shibler 		tios.c_iflag &= ~(IXON|IXOFF|IXANY|0x1ff);
18155830Shibler 		tios.c_iflag |= htios.c_iflag & 0x1ff;
18255830Shibler 		if (htios.c_iflag & TIO_IXON)
18344341Shibler 			tios.c_iflag |= IXON;
18455830Shibler 		if (htios.c_iflag & TIO_IXOFF)
18544341Shibler 			tios.c_iflag |= IXOFF;
18655830Shibler 		if (htios.c_iflag & TIO_IXANY)
18744341Shibler 			tios.c_iflag |= IXANY;
18844341Shibler 		/*
18944341Shibler 		 * Set oflag.
19044341Shibler 		 * No HP-UX equiv for ONOEOT
19144341Shibler 		 */
19244341Shibler 		tios.c_oflag &= ~(OPOST|ONLCR|OXTABS);
19355830Shibler 		if (htios.c_oflag & TIO_OPOST)
19444341Shibler 			tios.c_oflag |= OPOST;
19555830Shibler 		if (htios.c_oflag & TIO_ONLCR)
19644341Shibler 			tios.c_oflag |= ONLCR;
19755830Shibler 		if (htios.c_oflag & TIO_TAB3)
19844341Shibler 			tios.c_oflag |= OXTABS;
19944341Shibler 		/*
20044341Shibler 		 * Set cflag.
20144341Shibler 		 * No HP-UX equiv for CCTS_OFLOW/CCTS_IFLOW/MDMBUF
20244341Shibler 		 */
20344341Shibler 		tios.c_cflag &=
20444341Shibler 			~(CSIZE|CSTOPB|CREAD|PARENB|PARODD|HUPCL|CLOCAL);
20555830Shibler 		switch (htios.c_cflag & TIO_CSIZE) {
20644341Shibler 		case TIO_CS5:
20744341Shibler 			tios.c_cflag |= CS5; break;
20844341Shibler 		case TIO_CS6:
20944341Shibler 			tios.c_cflag |= CS6; break;
21044341Shibler 		case TIO_CS7:
21144341Shibler 			tios.c_cflag |= CS7; break;
21244341Shibler 		case TIO_CS8:
21344341Shibler 			tios.c_cflag |= CS8; break;
21441486Smckusick 		}
21555830Shibler 		if (htios.c_cflag & TIO_CSTOPB)
21644341Shibler 			tios.c_cflag |= CSTOPB;
21755830Shibler 		if (htios.c_cflag & TIO_CREAD)
21844341Shibler 			tios.c_cflag |= CREAD;
21955830Shibler 		if (htios.c_cflag & TIO_PARENB)
22044341Shibler 			tios.c_cflag |= PARENB;
22155830Shibler 		if (htios.c_cflag & TIO_PARODD)
22244341Shibler 			tios.c_cflag |= PARODD;
22355830Shibler 		if (htios.c_cflag & TIO_HUPCL)
22444341Shibler 			tios.c_cflag |= HUPCL;
22555830Shibler 		if (htios.c_cflag & TIO_CLOCAL)
22644341Shibler 			tios.c_cflag |= CLOCAL;
22744341Shibler 		/*
22844341Shibler 		 * Set lflag.
22944341Shibler 		 * No HP-UX equiv for ECHOKE/ECHOPRT/ECHOCTL
23044341Shibler 		 * IEXTEN treated as part of ICANON
23144341Shibler 		 */
23244341Shibler 		tios.c_lflag &= ~(ECHOE|ECHOK|ECHO|ISIG|ICANON|IEXTEN|NOFLSH);
23355830Shibler 		if (htios.c_lflag & TIO_ECHOE)
23444341Shibler 			tios.c_lflag |= ECHOE;
23555830Shibler 		if (htios.c_lflag & TIO_ECHOK)
23644341Shibler 			tios.c_lflag |= ECHOK;
23755830Shibler 		if (htios.c_lflag & TIO_ECHO)
23844341Shibler 			tios.c_lflag |= ECHO;
23955830Shibler 		if (htios.c_lflag & TIO_ECHONL)
24044341Shibler 			tios.c_lflag |= ECHONL;
24155830Shibler 		if (htios.c_lflag & TIO_ISIG)
24244341Shibler 			tios.c_lflag |= ISIG;
24355830Shibler 		if (htios.c_lflag & TIO_ICANON)
24444341Shibler 			tios.c_lflag |= (ICANON|IEXTEN);
24555830Shibler 		if (htios.c_lflag & TIO_NOFLSH)
24644341Shibler 			tios.c_lflag |= NOFLSH;
24744341Shibler 		/*
24844341Shibler 		 * Set editing chars.
24955830Shibler 		 * No HP-UX equivs of VWERASE/VREPRINT/VDSUSP/VLNEXT
25055830Shibler 		 * /VDISCARD/VSTATUS/VERASE2
25144341Shibler 		 */
25255830Shibler 		tios.c_cc[VINTR] = htios.c_cc[HPUXVINTR];
25355830Shibler 		tios.c_cc[VQUIT] = htios.c_cc[HPUXVQUIT];
25455830Shibler 		tios.c_cc[VERASE] = htios.c_cc[HPUXVERASE];
25555830Shibler 		tios.c_cc[VKILL] = htios.c_cc[HPUXVKILL];
25655830Shibler 		tios.c_cc[VEOF] = htios.c_cc[HPUXVEOF];
25755830Shibler 		tios.c_cc[VEOL] = htios.c_cc[HPUXVEOL];
25855830Shibler 		tios.c_cc[VEOL2] = htios.c_cc[HPUXVEOL2];
25955830Shibler 		tios.c_cc[VMIN] = htios.c_cc[HPUXVMINS];
26055830Shibler 		tios.c_cc[VTIME] = htios.c_cc[HPUXVTIMES];
26155830Shibler 		tios.c_cc[VSUSP] = htios.c_cc[HPUXVSUSP];
26255830Shibler 		tios.c_cc[VSTART] = htios.c_cc[HPUXVSTART];
26355830Shibler 		tios.c_cc[VSTOP] = htios.c_cc[HPUXVSTOP];
26455830Shibler 
26544341Shibler 		/*
26644341Shibler 		 * Set the new stuff
26744341Shibler 		 */
26855830Shibler 		if (com == HPUXTCSETA || com == HPUXTCSETATTR)
26944341Shibler 			com = TIOCSETA;
27055830Shibler 		else if (com == HPUXTCSETAW || com == HPUXTCSETATTRD)
27144341Shibler 			com = TIOCSETAW;
27241486Smckusick 		else
27344341Shibler 			com = TIOCSETAF;
27448477Skarels 		error = (*ioctlrout)(fp, com, (caddr_t)&tios, p);
27544341Shibler 		if (error == 0) {
27644341Shibler 			/*
27744341Shibler 			 * Set line discipline
27844341Shibler 			 */
27955830Shibler 			if (!newi) {
28055830Shibler 				line = htios.c_reserved;
28155830Shibler 				(void) (*ioctlrout)(fp, TIOCSETD,
28255830Shibler 						    (caddr_t)&line, p);
28355830Shibler 			}
28444341Shibler 			/*
28544341Shibler 			 * Set non-blocking IO if VMIN == VTIME == 0.
28644341Shibler 			 * Should handle the other cases as well.  It also
28744341Shibler 			 * isn't correct to just turn it off as it could be
28844341Shibler 			 * on as the result of a fcntl operation.
28944341Shibler 			 * XXX - wouldn't need to do this at all if VMIN/VTIME
29044341Shibler 			 * were implemented.
29144341Shibler 			 */
29255830Shibler 			line = (htios.c_cc[HPUXVMIN] == 0 &&
29355830Shibler 				htios.c_cc[HPUXVTIME] == 0);
29448477Skarels 			if (line)
29549942Smckusick 				fp->f_flag |= FNONBLOCK;
29648477Skarels 			else
29749942Smckusick 				fp->f_flag &= ~FNONBLOCK;
29848477Skarels 			(void) (*ioctlrout)(fp, FIONBIO, (caddr_t)&line, p);
29944341Shibler 		}
30041486Smckusick 		break;
30141486Smckusick 
30241486Smckusick 	default:
30343453Shibler 		error = EINVAL;
30441486Smckusick 		break;
30541486Smckusick 	}
30643453Shibler 	return(error);
30741486Smckusick }
30841486Smckusick 
30956314Shibler termiototermios(tio, tios, bsdtios)
31055830Shibler 	struct hpuxtermio *tio;
31155830Shibler 	struct hpuxtermios *tios;
31256314Shibler 	struct termios *bsdtios;
31355830Shibler {
31455830Shibler 	int i;
31555830Shibler 
31655830Shibler 	bzero((char *)tios, sizeof *tios);
31755830Shibler 	tios->c_iflag = tio->c_iflag;
31855830Shibler 	tios->c_oflag = tio->c_oflag;
31955830Shibler 	tios->c_cflag = tio->c_cflag;
32055830Shibler 	tios->c_lflag = tio->c_lflag;
32155830Shibler 	tios->c_reserved = tio->c_line;
32255830Shibler 	for (i = 0; i <= HPUXVSWTCH; i++)
32355830Shibler 		tios->c_cc[i] = tio->c_cc[i];
32455830Shibler 	if (tios->c_lflag & TIO_ICANON) {
32555830Shibler 		tios->c_cc[HPUXVEOF] = tio->c_cc[HPUXVEOF];
32655830Shibler 		tios->c_cc[HPUXVEOL] = tio->c_cc[HPUXVEOL];
32755830Shibler 		tios->c_cc[HPUXVMINS] = tios->c_cc[HPUXVTIMES] = 0;
32855830Shibler 	} else {
32955830Shibler 		tios->c_cc[HPUXVEOF] = tios->c_cc[HPUXVEOL] = 0;
33055830Shibler 		tios->c_cc[HPUXVMINS] = tio->c_cc[HPUXVMIN];
33155830Shibler 		tios->c_cc[HPUXVTIMES] = tio->c_cc[HPUXVTIME];
33255830Shibler 	}
33356314Shibler 	tios->c_cc[HPUXVMINS] = bsdtios->c_cc[VMIN];
33456314Shibler 	tios->c_cc[HPUXVTIMES] = bsdtios->c_cc[VTIME];
33556314Shibler 	tios->c_cc[HPUXVSUSP] = bsdtios->c_cc[VSUSP];
33656314Shibler 	tios->c_cc[HPUXVSTART] = bsdtios->c_cc[VSTART];
33756314Shibler 	tios->c_cc[HPUXVSTOP] = bsdtios->c_cc[VSTOP];
33855830Shibler }
33955830Shibler 
34055830Shibler termiostotermio(tios, tio)
34155830Shibler 	struct hpuxtermios *tios;
34255830Shibler 	struct hpuxtermio *tio;
34355830Shibler {
34455830Shibler 	int i;
34555830Shibler 
34655830Shibler 	tio->c_iflag = tios->c_iflag;
34755830Shibler 	tio->c_oflag = tios->c_oflag;
34855830Shibler 	tio->c_cflag = tios->c_cflag;
34955830Shibler 	tio->c_lflag = tios->c_lflag;
35055830Shibler 	tio->c_line = tios->c_reserved;
35155830Shibler 	for (i = 0; i <= HPUXVSWTCH; i++)
35255830Shibler 		tio->c_cc[i] = tios->c_cc[i];
35356314Shibler 	if (tios->c_lflag & TIO_ICANON) {
35455830Shibler 		tio->c_cc[HPUXVEOF] = tios->c_cc[HPUXVEOF];
35555830Shibler 		tio->c_cc[HPUXVEOL] = tios->c_cc[HPUXVEOL];
35655830Shibler 	} else {
35755830Shibler 		tio->c_cc[HPUXVMIN] = tios->c_cc[HPUXVMINS];
35855830Shibler 		tio->c_cc[HPUXVTIME] = tios->c_cc[HPUXVTIMES];
35955830Shibler 	}
36055830Shibler }
36155830Shibler 
36244341Shibler bsdtohpuxbaud(bsdspeed)
36344341Shibler 	long bsdspeed;
36444341Shibler {
36544341Shibler 	switch (bsdspeed) {
36644341Shibler 	case B0:     return(TIO_B0);
36744341Shibler 	case B50:    return(TIO_B50);
36844341Shibler 	case B75:    return(TIO_B75);
36944341Shibler 	case B110:   return(TIO_B110);
37044341Shibler 	case B134:   return(TIO_B134);
37144341Shibler 	case B150:   return(TIO_B150);
37244341Shibler 	case B200:   return(TIO_B200);
37344341Shibler 	case B300:   return(TIO_B300);
37444341Shibler 	case B600:   return(TIO_B600);
37544341Shibler 	case B1200:  return(TIO_B1200);
37644341Shibler 	case B1800:  return(TIO_B1800);
37744341Shibler 	case B2400:  return(TIO_B2400);
37844341Shibler 	case B4800:  return(TIO_B4800);
37944341Shibler 	case B9600:  return(TIO_B9600);
38044341Shibler 	case B19200: return(TIO_B19200);
38144341Shibler 	case B38400: return(TIO_B38400);
38244341Shibler 	default:     return(TIO_B0);
38344341Shibler 	}
38444341Shibler }
38544341Shibler 
38644341Shibler hpuxtobsdbaud(hpuxspeed)
38744341Shibler 	int hpuxspeed;
38844341Shibler {
38944341Shibler 	static char hpuxtobsdbaudtab[32] = {
39044341Shibler 		B0,	B50,	B75,	B110,	B134,	B150,	B200,	B300,
39144341Shibler 		B600,	B0,	B1200,	B1800,	B2400,	B0,	B4800,	B0,
39244341Shibler 		B9600,	B19200,	B38400,	B0,	B0,	B0,	B0,	B0,
39344341Shibler 		B0,	B0,	B0,	B0,	B0,	B0,	EXTA,	EXTB
39444341Shibler 	};
39544341Shibler 
39644341Shibler 	return(hpuxtobsdbaudtab[hpuxspeed & TIO_CBAUD]);
39744341Shibler }
39844341Shibler 
39955830Shibler #ifdef COMPAT_OHPUX
400*57307Shibler struct ohpuxsgtty_args {
401*57307Shibler 	int	fdes;
402*57307Shibler 	caddr_t	cmarg;
403*57307Shibler };
40443453Shibler ohpuxgtty(p, uap, retval)
40543453Shibler 	struct proc *p;
406*57307Shibler 	struct ohpuxsgtty_args *uap;
40743453Shibler 	int *retval;
40843453Shibler {
40941486Smckusick 
41045923Smckusick 	return (getsettty(p, uap->fdes, HPUXTIOCGETP, uap->cmarg));
41141486Smckusick }
41241486Smckusick 
41343453Shibler ohpuxstty(p, uap, retval)
41443453Shibler 	struct proc *p;
415*57307Shibler 	struct ohpuxsgtty_args *uap;
41643453Shibler 	int *retval;
41743453Shibler {
41841486Smckusick 
41945923Smckusick 	return (getsettty(p, uap->fdes, HPUXTIOCSETP, uap->cmarg));
42041486Smckusick }
42141486Smckusick 
42241486Smckusick /*
42341486Smckusick  * Simplified version of ioctl() for use by
42441486Smckusick  * gtty/stty and TIOCGETP/TIOCSETP.
42541486Smckusick  */
42645923Smckusick getsettty(p, fdes, com, cmarg)
42745923Smckusick 	struct proc *p;
42841486Smckusick 	int fdes, com;
42941486Smckusick 	caddr_t cmarg;
43041486Smckusick {
43145923Smckusick 	register struct filedesc *fdp = p->p_fd;
43241486Smckusick 	register struct file *fp;
43341486Smckusick 	struct hpuxsgttyb hsb;
43441486Smckusick 	struct sgttyb sb;
43543453Shibler 	int error;
43641486Smckusick 
43748477Skarels 	if (((unsigned)fdes) >= fdp->fd_nfiles ||
43848477Skarels 	    (fp = fdp->fd_ofiles[fdes]) == NULL)
43943453Shibler 		return (EBADF);
44043453Shibler 	if ((fp->f_flag & (FREAD|FWRITE)) == 0)
44143453Shibler 		return (EBADF);
44241486Smckusick 	if (com == HPUXTIOCSETP) {
44343453Shibler 		if (error = copyin(cmarg, (caddr_t)&hsb, sizeof hsb))
44443453Shibler 			return (error);
44541486Smckusick 		sb.sg_ispeed = hsb.sg_ispeed;
44641486Smckusick 		sb.sg_ospeed = hsb.sg_ospeed;
44741486Smckusick 		sb.sg_erase = hsb.sg_erase;
44841486Smckusick 		sb.sg_kill = hsb.sg_kill;
44943453Shibler 		sb.sg_flags = hsb.sg_flags & ~(V7_HUPCL|V7_XTABS|V7_NOAL);
45043453Shibler 		if (hsb.sg_flags & V7_XTABS)
45143453Shibler 			sb.sg_flags |= XTABS;
45243453Shibler 		if (hsb.sg_flags & V7_HUPCL)
45348477Skarels 			(void)(*fp->f_ops->fo_ioctl)
45448477Skarels 				(fp, TIOCHPCL, (caddr_t)0, p);
45541486Smckusick 		com = TIOCSETP;
45641486Smckusick 	} else {
45741486Smckusick 		bzero((caddr_t)&hsb, sizeof hsb);
45841486Smckusick 		com = TIOCGETP;
45941486Smckusick 	}
46048477Skarels 	error = (*fp->f_ops->fo_ioctl)(fp, com, (caddr_t)&sb, p);
46143453Shibler 	if (error == 0 && com == TIOCGETP) {
46241486Smckusick 		hsb.sg_ispeed = sb.sg_ispeed;
46341486Smckusick 		hsb.sg_ospeed = sb.sg_ospeed;
46441486Smckusick 		hsb.sg_erase = sb.sg_erase;
46541486Smckusick 		hsb.sg_kill = sb.sg_kill;
46643453Shibler 		hsb.sg_flags = sb.sg_flags & ~(V7_HUPCL|V7_XTABS|V7_NOAL);
46743453Shibler 		if (sb.sg_flags & XTABS)
46843453Shibler 			hsb.sg_flags |= V7_XTABS;
46943453Shibler 		error = copyout((caddr_t)&hsb, cmarg, sizeof hsb);
47041486Smckusick 	}
47143453Shibler 	return (error);
47241486Smckusick }
47341486Smckusick #endif
47455830Shibler #endif
475