ANSI
[unix-history] / usr / src / usr.bin / window / wwrint.c
CommitLineData
60de5df9 1/*
46e9ea25
KB
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.
4 *
3dd3a9e5
KB
5 * This code is derived from software contributed to Berkeley by
6 * Edward Wang at The University of California, Berkeley.
7 *
87f529ec 8 * %sccs.include.redist.c%
60de5df9
EW
9 */
10
46e9ea25 11#ifndef lint
419d8eab 12static char sccsid[] = "@(#)wwrint.c 3.11 (Berkeley) %G%";
46e9ea25
KB
13#endif /* not lint */
14
78b88f48
EW
15#include "ww.h"
16#include <fcntl.h>
78b88f48
EW
17
18/*
19 * Tty input interrupt handler.
20 * (1) Read input into buffer (wwib*).
16078900 21 * (2) Set the interrupt flag if anything is read.
78b88f48
EW
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 */
419d8eab 28void
78b88f48
EW
29wwrint()
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;
16078900 42 wwsetintr();
78b88f48
EW
43 } else if (n == 0)
44 wwnreadz++;
45 else
46 wwnreade++;
78b88f48 47}