xref: /original-bsd/usr.bin/window/wwrint.c (revision e59fb703)
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.11 (Berkeley) 03/02/91";
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 void
29 wwrint()
30 {
31 	register n;
32 
33 	if (wwibp == wwibq)
34 		wwibp = wwibq = wwib;
35 	wwnread++;
36 	(void) fcntl(0, F_SETFL, FNDELAY|wwnewtty.ww_fflags);
37 	n = read(0, wwibq, wwibe - wwibq);
38 	(void) fcntl(0, F_SETFL, wwnewtty.ww_fflags);
39 	if (n > 0) {
40 		wwibq += n;
41 		wwnreadc += n;
42 		wwsetintr();
43 	} else if (n == 0)
44 		wwnreadz++;
45 	else
46 		wwnreade++;
47 }
48