xref: /original-bsd/usr.bin/window/wwrint.c (revision 860e07fc)
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.13 (Berkeley) 08/16/92";
13 #endif /* not lint */
14 
15 #include "ww.h"
16 #include "tt.h"
17 #if defined(OLD_TTY) || defined(VMIN_BUG)
18 #include <fcntl.h>
19 #endif
20 
21 /*
22  * Tty input interrupt handler.
23  * (1) Read input into buffer (wwib*).
24  * (2) Set the interrupt flag if anything is read.
25  * Currently, the last is used to get out of the blocking
26  * select() in wwiomux().
27  * To avoid race conditions, we only modify wwibq in here, except
28  * when the buffer is empty; and everywhere else, we only change wwibp.
29  * It should be completely safe.
30  */
31 void
32 wwrint()
33 {
34 	register n;
35 
36 	if (wwibp == wwibq)
37 		wwibp = wwibq = wwib;
38 	wwnread++;
39 #if defined(OLD_TTY) || defined(VMIN_BUG)
40 	/* we have set c_cc[VMIN] to 0 */
41 	(void) fcntl(0, F_SETFL, O_NONBLOCK|wwnewtty.ww_fflags);
42 #endif
43 	n = read(0, wwibq, wwibe - wwibq);
44 #if defined(OLD_TTY) || defined(VMIN_BUG)
45 	(void) fcntl(0, F_SETFL, wwnewtty.ww_fflags);
46 #endif
47 	if (n > 0) {
48 		if (tt.tt_rint)
49 			n = (*tt.tt_rint)(wwibq, n);
50 		wwibq += n;
51 		wwnreadc += n;
52 		wwsetintr();
53 	} else if (n == 0)
54 		wwnreadz++;
55 	else
56 		wwnreade++;
57 }
58