xref: /original-bsd/usr.bin/window/wwrint.c (revision e9b82df0)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Edward Wang at The University of California, Berkeley.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #ifndef lint
12 static char sccsid[] = "@(#)wwrint.c	3.10 (Berkeley) 06/06/90";
13 #endif /* not lint */
14 
15 #include "ww.h"
16 #include <fcntl.h>
17 
18 /*
19  * Tty input interrupt handler.
20  * (1) Read input into buffer (wwib*).
21  * (2) Set the interrupt flag if anything is read.
22  * Currently, the last is used to get out of the blocking
23  * select() in wwiomux().
24  * To avoid race conditions, we only modify wwibq in here, except
25  * when the buffer is empty; and everywhere else, we only change wwibp.
26  * It should be completely safe.
27  */
28 wwrint()
29 {
30 	register n;
31 
32 	if (wwibp == wwibq)
33 		wwibp = wwibq = wwib;
34 	wwnread++;
35 	(void) fcntl(0, F_SETFL, FNDELAY|wwnewtty.ww_fflags);
36 	n = read(0, wwibq, wwibe - wwibq);
37 	(void) fcntl(0, F_SETFL, wwnewtty.ww_fflags);
38 	if (n > 0) {
39 		wwibq += n;
40 		wwnreadc += n;
41 		wwsetintr();
42 	} else if (n == 0)
43 		wwnreadz++;
44 	else
45 		wwnreade++;
46 }
47