1*433d6423SLionel Sambuc /*
2*433d6423SLionel Sambuc *
3*433d6423SLionel Sambuc * Rev 05-05-1988
4*433d6423SLionel Sambuc * This file contains Unix specific code for setting terminal modes,
5*433d6423SLionel Sambuc * very little is specific to ZMODEM or YMODEM per se (that code is in
6*433d6423SLionel Sambuc * sz.c and rz.c). The CRC-16 routines used by XMODEM, YMODEM, and ZMODEM
7*433d6423SLionel Sambuc * are also in this file, a fast table driven macro version
8*433d6423SLionel Sambuc *
9*433d6423SLionel Sambuc * V7/BSD HACKERS: SEE NOTES UNDER mode(2) !!!
10*433d6423SLionel Sambuc *
11*433d6423SLionel Sambuc * This file is #included so the main file can set parameters such as HOWMANY.
12*433d6423SLionel Sambuc * See the main files (rz.c/sz.c) for compile instructions.
13*433d6423SLionel Sambuc */
14*433d6423SLionel Sambuc
15*433d6423SLionel Sambuc #ifdef V7
16*433d6423SLionel Sambuc #include <sys/types.h>
17*433d6423SLionel Sambuc #include <sys/stat.h>
18*433d6423SLionel Sambuc #include <sgtty.h>
19*433d6423SLionel Sambuc #define OS "V7/BSD"
20*433d6423SLionel Sambuc #ifdef LLITOUT
21*433d6423SLionel Sambuc long Locmode; /* Saved "local mode" for 4.x BSD "new driver" */
22*433d6423SLionel Sambuc long Locbit = LLITOUT; /* Bit SUPPOSED to disable output translations */
23*433d6423SLionel Sambuc #include <strings.h>
24*433d6423SLionel Sambuc #endif
25*433d6423SLionel Sambuc #endif
26*433d6423SLionel Sambuc
27*433d6423SLionel Sambuc #ifdef POSIX
28*433d6423SLionel Sambuc #include <sys/types.h>
29*433d6423SLionel Sambuc #include <sys/stat.h>
30*433d6423SLionel Sambuc #include <termios.h>
31*433d6423SLionel Sambuc #define OS "POSIX"
32*433d6423SLionel Sambuc #endif
33*433d6423SLionel Sambuc
34*433d6423SLionel Sambuc #ifndef OS
35*433d6423SLionel Sambuc #ifndef USG
36*433d6423SLionel Sambuc #define USG
37*433d6423SLionel Sambuc #endif
38*433d6423SLionel Sambuc #endif
39*433d6423SLionel Sambuc
40*433d6423SLionel Sambuc #ifdef USG
41*433d6423SLionel Sambuc #include <sys/types.h>
42*433d6423SLionel Sambuc #include <sys/stat.h>
43*433d6423SLionel Sambuc #include <termio.h>
44*433d6423SLionel Sambuc #include <sys/ioctl.h>
45*433d6423SLionel Sambuc #define OS "SYS III/V"
46*433d6423SLionel Sambuc #define MODE2OK
47*433d6423SLionel Sambuc #include <string.h>
48*433d6423SLionel Sambuc #endif
49*433d6423SLionel Sambuc
50*433d6423SLionel Sambuc #include "zmodem.h"
51*433d6423SLionel Sambuc
52*433d6423SLionel Sambuc static unsigned getspeed(int code );
53*433d6423SLionel Sambuc
54*433d6423SLionel Sambuc #if HOWMANY > 255
55*433d6423SLionel Sambuc Howmany must be 255 or less
56*433d6423SLionel Sambuc #endif
57*433d6423SLionel Sambuc
58*433d6423SLionel Sambuc /*
59*433d6423SLionel Sambuc * return 1 iff stdout and stderr are different devices
60*433d6423SLionel Sambuc * indicating this program operating with a modem on a
61*433d6423SLionel Sambuc * different line
62*433d6423SLionel Sambuc */
63*433d6423SLionel Sambuc int Fromcu; /* Were called from cu or yam */
64*433d6423SLionel Sambuc
from_cu()65*433d6423SLionel Sambuc void from_cu()
66*433d6423SLionel Sambuc {
67*433d6423SLionel Sambuc struct stat a, b;
68*433d6423SLionel Sambuc
69*433d6423SLionel Sambuc fstat(1, &a); fstat(2, &b);
70*433d6423SLionel Sambuc Fromcu = a.st_rdev != b.st_rdev;
71*433d6423SLionel Sambuc return;
72*433d6423SLionel Sambuc }
73*433d6423SLionel Sambuc
cucheck()74*433d6423SLionel Sambuc void cucheck()
75*433d6423SLionel Sambuc {
76*433d6423SLionel Sambuc if (Fromcu)
77*433d6423SLionel Sambuc fprintf(stderr,"Please read the manual page BUGS chapter!\r\n");
78*433d6423SLionel Sambuc }
79*433d6423SLionel Sambuc
80*433d6423SLionel Sambuc
81*433d6423SLionel Sambuc struct {
82*433d6423SLionel Sambuc unsigned baudr;
83*433d6423SLionel Sambuc int speedcode;
84*433d6423SLionel Sambuc } speeds[] = {
85*433d6423SLionel Sambuc {110, B110, },
86*433d6423SLionel Sambuc {300, B300, },
87*433d6423SLionel Sambuc #ifdef B600
88*433d6423SLionel Sambuc {600, B600, },
89*433d6423SLionel Sambuc #endif
90*433d6423SLionel Sambuc {1200, B1200, },
91*433d6423SLionel Sambuc {2400, B2400, },
92*433d6423SLionel Sambuc {4800, B4800, },
93*433d6423SLionel Sambuc {9600, B9600, },
94*433d6423SLionel Sambuc #ifdef EXTA
95*433d6423SLionel Sambuc {19200, EXTA, },
96*433d6423SLionel Sambuc {38400, EXTB, },
97*433d6423SLionel Sambuc #endif
98*433d6423SLionel Sambuc {0},
99*433d6423SLionel Sambuc };
100*433d6423SLionel Sambuc
101*433d6423SLionel Sambuc int Twostop; /* Use two stop bits */
102*433d6423SLionel Sambuc
103*433d6423SLionel Sambuc
104*433d6423SLionel Sambuc #ifndef READCHECK
105*433d6423SLionel Sambuc #ifdef FIONREAD
106*433d6423SLionel Sambuc #define READCHECK
107*433d6423SLionel Sambuc /*
108*433d6423SLionel Sambuc * Return non 0 iff something to read from io descriptor f
109*433d6423SLionel Sambuc */
rdchk(int f)110*433d6423SLionel Sambuc int rdchk(int f)
111*433d6423SLionel Sambuc {
112*433d6423SLionel Sambuc static long lf;
113*433d6423SLionel Sambuc
114*433d6423SLionel Sambuc ioctl(f, FIONREAD, &lf);
115*433d6423SLionel Sambuc return ((int) lf);
116*433d6423SLionel Sambuc }
117*433d6423SLionel Sambuc #endif
118*433d6423SLionel Sambuc #ifdef SV
119*433d6423SLionel Sambuc #define READCHECK
120*433d6423SLionel Sambuc #include <fcntl.h>
121*433d6423SLionel Sambuc
122*433d6423SLionel Sambuc char checked = '\0' ;
123*433d6423SLionel Sambuc /*
124*433d6423SLionel Sambuc * Nonblocking I/O is a bit different in System V, Release 2
125*433d6423SLionel Sambuc */
rdchk(f)126*433d6423SLionel Sambuc int rdchk(f)
127*433d6423SLionel Sambuc {
128*433d6423SLionel Sambuc int lf, savestat;
129*433d6423SLionel Sambuc
130*433d6423SLionel Sambuc savestat = fcntl(f, F_GETFL) ;
131*433d6423SLionel Sambuc fcntl(f, F_SETFL, savestat | O_NDELAY) ;
132*433d6423SLionel Sambuc lf = read(f, &checked, 1) ;
133*433d6423SLionel Sambuc fcntl(f, F_SETFL, savestat) ;
134*433d6423SLionel Sambuc return(lf) ;
135*433d6423SLionel Sambuc }
136*433d6423SLionel Sambuc #endif
137*433d6423SLionel Sambuc #endif
138*433d6423SLionel Sambuc
139*433d6423SLionel Sambuc
140*433d6423SLionel Sambuc static unsigned
getspeed(int code)141*433d6423SLionel Sambuc getspeed(int code)
142*433d6423SLionel Sambuc {
143*433d6423SLionel Sambuc register int n;
144*433d6423SLionel Sambuc
145*433d6423SLionel Sambuc for (n=0; speeds[n].baudr; ++n)
146*433d6423SLionel Sambuc if (speeds[n].speedcode == code)
147*433d6423SLionel Sambuc return speeds[n].baudr;
148*433d6423SLionel Sambuc return 38400; /* Assume fifo if ioctl failed */
149*433d6423SLionel Sambuc }
150*433d6423SLionel Sambuc
151*433d6423SLionel Sambuc
152*433d6423SLionel Sambuc
153*433d6423SLionel Sambuc #ifdef POSIX
154*433d6423SLionel Sambuc struct termios oldtty, tty;
155*433d6423SLionel Sambuc #else
156*433d6423SLionel Sambuc #ifdef ICANON
157*433d6423SLionel Sambuc struct termio oldtty, tty;
158*433d6423SLionel Sambuc #else
159*433d6423SLionel Sambuc struct sgttyb oldtty, tty;
160*433d6423SLionel Sambuc struct tchars oldtch, tch;
161*433d6423SLionel Sambuc #endif
162*433d6423SLionel Sambuc #endif
163*433d6423SLionel Sambuc
164*433d6423SLionel Sambuc int iofd = 0; /* File descriptor for ioctls & reads */
165*433d6423SLionel Sambuc
166*433d6423SLionel Sambuc /*
167*433d6423SLionel Sambuc * mode(n)
168*433d6423SLionel Sambuc * 3: save old tty stat, set raw mode with flow control
169*433d6423SLionel Sambuc * 2: set XON/XOFF for sb/sz with ZMODEM or YMODEM-g
170*433d6423SLionel Sambuc * 1: save old tty stat, set raw mode
171*433d6423SLionel Sambuc * 0: restore original tty mode
172*433d6423SLionel Sambuc */
mode(n)173*433d6423SLionel Sambuc int mode(n)
174*433d6423SLionel Sambuc int n;
175*433d6423SLionel Sambuc {
176*433d6423SLionel Sambuc static int did0 = FALSE;
177*433d6423SLionel Sambuc
178*433d6423SLionel Sambuc vfile("mode:%d", n);
179*433d6423SLionel Sambuc switch(n) {
180*433d6423SLionel Sambuc #ifdef POSIX
181*433d6423SLionel Sambuc case 2: /* Un-raw mode used by sz, sb when -g detected */
182*433d6423SLionel Sambuc if(!did0)
183*433d6423SLionel Sambuc (void) tcgetattr(iofd, &oldtty);
184*433d6423SLionel Sambuc tty = oldtty;
185*433d6423SLionel Sambuc
186*433d6423SLionel Sambuc tty.c_iflag = BRKINT|IXON;
187*433d6423SLionel Sambuc
188*433d6423SLionel Sambuc tty.c_oflag = 0; /* Transparent output */
189*433d6423SLionel Sambuc
190*433d6423SLionel Sambuc tty.c_cflag &= ~PARENB; /* Disable parity */
191*433d6423SLionel Sambuc tty.c_cflag |= CS8; /* Set character size = 8 */
192*433d6423SLionel Sambuc if (Twostop)
193*433d6423SLionel Sambuc tty.c_cflag |= CSTOPB; /* Set two stop bits */
194*433d6423SLionel Sambuc
195*433d6423SLionel Sambuc
196*433d6423SLionel Sambuc tty.c_lflag = ISIG;
197*433d6423SLionel Sambuc tty.c_cc[VINTR] = Zmodem ? 03:030; /* Interrupt char */
198*433d6423SLionel Sambuc tty.c_cc[VQUIT] = -1; /* Quit char */
199*433d6423SLionel Sambuc tty.c_cc[VMIN] = 3; /* This many chars satisfies reads */
200*433d6423SLionel Sambuc tty.c_cc[VTIME] = 1; /* or in this many tenths of seconds */
201*433d6423SLionel Sambuc
202*433d6423SLionel Sambuc (void) tcsetattr(iofd, TCSANOW, &tty);
203*433d6423SLionel Sambuc did0 = TRUE;
204*433d6423SLionel Sambuc return OK;
205*433d6423SLionel Sambuc case 1:
206*433d6423SLionel Sambuc case 3:
207*433d6423SLionel Sambuc if(!did0)
208*433d6423SLionel Sambuc (void) tcgetattr(iofd, &oldtty);
209*433d6423SLionel Sambuc tty = oldtty;
210*433d6423SLionel Sambuc
211*433d6423SLionel Sambuc tty.c_iflag = n==3 ? (IGNBRK|IXOFF) : IGNBRK;
212*433d6423SLionel Sambuc
213*433d6423SLionel Sambuc /* No echo, crlf mapping, INTR, QUIT, delays, no erase/kill */
214*433d6423SLionel Sambuc tty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
215*433d6423SLionel Sambuc
216*433d6423SLionel Sambuc tty.c_oflag = 0; /* Transparent output */
217*433d6423SLionel Sambuc
218*433d6423SLionel Sambuc tty.c_cflag &= ~PARENB; /* Same baud rate, disable parity */
219*433d6423SLionel Sambuc tty.c_cflag |= CS8; /* Set character size = 8 */
220*433d6423SLionel Sambuc if (Twostop)
221*433d6423SLionel Sambuc tty.c_cflag |= CSTOPB; /* Set two stop bits */
222*433d6423SLionel Sambuc tty.c_cc[VMIN] = HOWMANY; /* This many chars satisfies reads */
223*433d6423SLionel Sambuc tty.c_cc[VTIME] = 1; /* or in this many tenths of seconds */
224*433d6423SLionel Sambuc (void) tcsetattr(iofd, TCSANOW, &tty);
225*433d6423SLionel Sambuc did0 = TRUE;
226*433d6423SLionel Sambuc Baudrate = cfgetospeed(&tty);
227*433d6423SLionel Sambuc return OK;
228*433d6423SLionel Sambuc #endif
229*433d6423SLionel Sambuc #ifdef USG
230*433d6423SLionel Sambuc case 2: /* Un-raw mode used by sz, sb when -g detected */
231*433d6423SLionel Sambuc if(!did0)
232*433d6423SLionel Sambuc (void) ioctl(iofd, TCGETA, &oldtty);
233*433d6423SLionel Sambuc tty = oldtty;
234*433d6423SLionel Sambuc
235*433d6423SLionel Sambuc tty.c_iflag = BRKINT|IXON;
236*433d6423SLionel Sambuc
237*433d6423SLionel Sambuc tty.c_oflag = 0; /* Transparent output */
238*433d6423SLionel Sambuc
239*433d6423SLionel Sambuc tty.c_cflag &= ~PARENB; /* Disable parity */
240*433d6423SLionel Sambuc tty.c_cflag |= CS8; /* Set character size = 8 */
241*433d6423SLionel Sambuc if (Twostop)
242*433d6423SLionel Sambuc tty.c_cflag |= CSTOPB; /* Set two stop bits */
243*433d6423SLionel Sambuc
244*433d6423SLionel Sambuc
245*433d6423SLionel Sambuc #ifdef READCHECK
246*433d6423SLionel Sambuc tty.c_lflag = Zmodem ? 0 : ISIG;
247*433d6423SLionel Sambuc tty.c_cc[VINTR] = Zmodem ? -1:030; /* Interrupt char */
248*433d6423SLionel Sambuc #else
249*433d6423SLionel Sambuc tty.c_lflag = ISIG;
250*433d6423SLionel Sambuc tty.c_cc[VINTR] = Zmodem ? 03:030; /* Interrupt char */
251*433d6423SLionel Sambuc #endif
252*433d6423SLionel Sambuc tty.c_cc[VQUIT] = -1; /* Quit char */
253*433d6423SLionel Sambuc #ifdef NFGVMIN
254*433d6423SLionel Sambuc tty.c_cc[VMIN] = 1;
255*433d6423SLionel Sambuc #else
256*433d6423SLionel Sambuc tty.c_cc[VMIN] = 3; /* This many chars satisfies reads */
257*433d6423SLionel Sambuc #endif
258*433d6423SLionel Sambuc tty.c_cc[VTIME] = 1; /* or in this many tenths of seconds */
259*433d6423SLionel Sambuc
260*433d6423SLionel Sambuc (void) ioctl(iofd, TCSETAW, &tty);
261*433d6423SLionel Sambuc did0 = TRUE;
262*433d6423SLionel Sambuc return OK;
263*433d6423SLionel Sambuc case 1:
264*433d6423SLionel Sambuc case 3:
265*433d6423SLionel Sambuc if(!did0)
266*433d6423SLionel Sambuc (void) ioctl(iofd, TCGETA, &oldtty);
267*433d6423SLionel Sambuc tty = oldtty;
268*433d6423SLionel Sambuc
269*433d6423SLionel Sambuc tty.c_iflag = n==3 ? (IGNBRK|IXOFF) : IGNBRK;
270*433d6423SLionel Sambuc
271*433d6423SLionel Sambuc /* No echo, crlf mapping, INTR, QUIT, delays, no erase/kill */
272*433d6423SLionel Sambuc tty.c_lflag &= ~(ECHO | ICANON | ISIG);
273*433d6423SLionel Sambuc
274*433d6423SLionel Sambuc tty.c_oflag = 0; /* Transparent output */
275*433d6423SLionel Sambuc
276*433d6423SLionel Sambuc tty.c_cflag &= ~PARENB; /* Same baud rate, disable parity */
277*433d6423SLionel Sambuc tty.c_cflag |= CS8; /* Set character size = 8 */
278*433d6423SLionel Sambuc if (Twostop)
279*433d6423SLionel Sambuc tty.c_cflag |= CSTOPB; /* Set two stop bits */
280*433d6423SLionel Sambuc #ifdef NFGVMIN
281*433d6423SLionel Sambuc tty.c_cc[VMIN] = 1; /* This many chars satisfies reads */
282*433d6423SLionel Sambuc #else
283*433d6423SLionel Sambuc tty.c_cc[VMIN] = HOWMANY; /* This many chars satisfies reads */
284*433d6423SLionel Sambuc #endif
285*433d6423SLionel Sambuc tty.c_cc[VTIME] = 1; /* or in this many tenths of seconds */
286*433d6423SLionel Sambuc (void) ioctl(iofd, TCSETAW, &tty);
287*433d6423SLionel Sambuc did0 = TRUE;
288*433d6423SLionel Sambuc Baudrate = getspeed(tty.c_cflag & CBAUD);
289*433d6423SLionel Sambuc return OK;
290*433d6423SLionel Sambuc #endif
291*433d6423SLionel Sambuc #ifdef V7
292*433d6423SLionel Sambuc /*
293*433d6423SLionel Sambuc * NOTE: this should transmit all 8 bits and at the same time
294*433d6423SLionel Sambuc * respond to XOFF/XON flow control. If no FIONREAD or other
295*433d6423SLionel Sambuc * READCHECK alternative, also must respond to INTRRUPT char
296*433d6423SLionel Sambuc * This doesn't work with V7. It should work with LLITOUT,
297*433d6423SLionel Sambuc * but LLITOUT was broken on the machine I tried it on.
298*433d6423SLionel Sambuc */
299*433d6423SLionel Sambuc case 2: /* Un-raw mode used by sz, sb when -g detected */
300*433d6423SLionel Sambuc if(!did0) {
301*433d6423SLionel Sambuc #ifdef TIOCEXCL
302*433d6423SLionel Sambuc ioctl(iofd, TIOCEXCL, 0);
303*433d6423SLionel Sambuc #endif
304*433d6423SLionel Sambuc ioctl(iofd, TIOCGETP, &oldtty);
305*433d6423SLionel Sambuc ioctl(iofd, TIOCGETC, (struct sgttyb *) &oldtch);
306*433d6423SLionel Sambuc #ifdef LLITOUT
307*433d6423SLionel Sambuc ioctl(iofd, TIOCLGET, &Locmode);
308*433d6423SLionel Sambuc #endif
309*433d6423SLionel Sambuc }
310*433d6423SLionel Sambuc tty = oldtty;
311*433d6423SLionel Sambuc tch = oldtch;
312*433d6423SLionel Sambuc #ifdef READCHECK
313*433d6423SLionel Sambuc tch.t_intrc = Zmodem ? -1:030; /* Interrupt char */
314*433d6423SLionel Sambuc #else
315*433d6423SLionel Sambuc tch.t_intrc = Zmodem ? 03:030; /* Interrupt char */
316*433d6423SLionel Sambuc #endif
317*433d6423SLionel Sambuc #ifdef ODDP
318*433d6423SLionel Sambuc tty.sg_flags |= ODDP;
319*433d6423SLionel Sambuc #endif
320*433d6423SLionel Sambuc #ifdef EVENP
321*433d6423SLionel Sambuc tty.sg_flags |= EVENP;
322*433d6423SLionel Sambuc #endif
323*433d6423SLionel Sambuc #ifdef CBREAK
324*433d6423SLionel Sambuc tty.sg_flags |= CBREAK;
325*433d6423SLionel Sambuc #endif
326*433d6423SLionel Sambuc #ifdef ALLDELAY
327*433d6423SLionel Sambuc tty.sg_flags &= ~ALLDELAY;
328*433d6423SLionel Sambuc #endif
329*433d6423SLionel Sambuc #ifdef CRMOD
330*433d6423SLionel Sambuc tty.sg_flags &= ~CRMOD;
331*433d6423SLionel Sambuc #endif
332*433d6423SLionel Sambuc #ifdef ECHO
333*433d6423SLionel Sambuc tty.sg_flags &= ~ECHO;
334*433d6423SLionel Sambuc #endif
335*433d6423SLionel Sambuc #ifdef LCASE
336*433d6423SLionel Sambuc tty.sg_flags &= ~LCASE;
337*433d6423SLionel Sambuc #endif
338*433d6423SLionel Sambuc
339*433d6423SLionel Sambuc ioctl(iofd, TIOCSETP, &tty);
340*433d6423SLionel Sambuc ioctl(iofd, TIOCSETC, (struct sgttyb *) &tch);
341*433d6423SLionel Sambuc #ifdef LLITOUT
342*433d6423SLionel Sambuc ioctl(iofd, TIOCLBIS, &Locbit);
343*433d6423SLionel Sambuc #endif
344*433d6423SLionel Sambuc bibi(99); /* un-raw doesn't work w/o lit out */
345*433d6423SLionel Sambuc did0 = TRUE;
346*433d6423SLionel Sambuc return OK;
347*433d6423SLionel Sambuc case 1:
348*433d6423SLionel Sambuc case 3:
349*433d6423SLionel Sambuc if(!did0) {
350*433d6423SLionel Sambuc #ifdef TIOCEXCL
351*433d6423SLionel Sambuc ioctl(iofd, TIOCEXCL, 0);
352*433d6423SLionel Sambuc #endif
353*433d6423SLionel Sambuc ioctl(iofd, TIOCGETP, &oldtty);
354*433d6423SLionel Sambuc ioctl(iofd, TIOCGETC, (struct sgttyb *) &oldtch);
355*433d6423SLionel Sambuc #ifdef LLITOUT
356*433d6423SLionel Sambuc ioctl(iofd, TIOCLGET, &Locmode);
357*433d6423SLionel Sambuc #endif
358*433d6423SLionel Sambuc }
359*433d6423SLionel Sambuc tty = oldtty;
360*433d6423SLionel Sambuc tty.sg_flags |= RAW;
361*433d6423SLionel Sambuc tty.sg_flags &= ~ECHO;
362*433d6423SLionel Sambuc ioctl(iofd, TIOCSETP, &tty);
363*433d6423SLionel Sambuc did0 = TRUE;
364*433d6423SLionel Sambuc Baudrate = getspeed(tty.sg_ospeed);
365*433d6423SLionel Sambuc return OK;
366*433d6423SLionel Sambuc #endif
367*433d6423SLionel Sambuc case 0:
368*433d6423SLionel Sambuc if(!did0)
369*433d6423SLionel Sambuc return ERROR;
370*433d6423SLionel Sambuc #ifdef POSIX
371*433d6423SLionel Sambuc /* Wait for output to drain, flush input queue, restore
372*433d6423SLionel Sambuc * modes and restart output.
373*433d6423SLionel Sambuc */
374*433d6423SLionel Sambuc (void) tcsetattr(iofd, TCSAFLUSH, &oldtty);
375*433d6423SLionel Sambuc (void) tcflow(iofd, TCOON);
376*433d6423SLionel Sambuc #endif
377*433d6423SLionel Sambuc #ifdef USG
378*433d6423SLionel Sambuc (void) ioctl(iofd, TCSBRK, 1); /* Wait for output to drain */
379*433d6423SLionel Sambuc (void) ioctl(iofd, TCFLSH, 1); /* Flush input queue */
380*433d6423SLionel Sambuc (void) ioctl(iofd, TCSETAW, &oldtty); /* Restore modes */
381*433d6423SLionel Sambuc (void) ioctl(iofd, TCXONC,1); /* Restart output */
382*433d6423SLionel Sambuc #endif
383*433d6423SLionel Sambuc #ifdef V7
384*433d6423SLionel Sambuc ioctl(iofd, TIOCSETP, &oldtty);
385*433d6423SLionel Sambuc ioctl(iofd, TIOCSETC, (struct sgttyb *) &oldtch);
386*433d6423SLionel Sambuc #ifdef TIOCNXCL
387*433d6423SLionel Sambuc ioctl(iofd, TIOCNXCL, 0);
388*433d6423SLionel Sambuc #endif
389*433d6423SLionel Sambuc #ifdef LLITOUT
390*433d6423SLionel Sambuc ioctl(iofd, TIOCLSET, &Locmode);
391*433d6423SLionel Sambuc #endif
392*433d6423SLionel Sambuc #endif
393*433d6423SLionel Sambuc
394*433d6423SLionel Sambuc return OK;
395*433d6423SLionel Sambuc default:
396*433d6423SLionel Sambuc return ERROR;
397*433d6423SLionel Sambuc }
398*433d6423SLionel Sambuc }
399*433d6423SLionel Sambuc
sendbrk()400*433d6423SLionel Sambuc void sendbrk()
401*433d6423SLionel Sambuc {
402*433d6423SLionel Sambuc #ifdef POSIX
403*433d6423SLionel Sambuc tcsendbreak(iofd, 1);
404*433d6423SLionel Sambuc #endif
405*433d6423SLionel Sambuc #ifdef V7
406*433d6423SLionel Sambuc #ifdef TIOCSBRK
407*433d6423SLionel Sambuc #define CANBREAK
408*433d6423SLionel Sambuc sleep(1);
409*433d6423SLionel Sambuc ioctl(iofd, TIOCSBRK, 0);
410*433d6423SLionel Sambuc sleep(1);
411*433d6423SLionel Sambuc ioctl(iofd, TIOCCBRK, 0);
412*433d6423SLionel Sambuc #endif
413*433d6423SLionel Sambuc #endif
414*433d6423SLionel Sambuc #ifdef USG
415*433d6423SLionel Sambuc #define CANBREAK
416*433d6423SLionel Sambuc ioctl(iofd, TCSBRK, 0);
417*433d6423SLionel Sambuc #endif
418*433d6423SLionel Sambuc }
419*433d6423SLionel Sambuc
420*433d6423SLionel Sambuc /* End of rbsb.c */
421