8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libcurses / screen / ttimeout.c
blobd56bd487d67d33b43479008bf56533e9598ef500
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
40 #pragma ident "%Z%%M% %I% %E% SMI"
42 /*LINTLIBRARY*/
44 #include <sys/types.h>
45 #include "curses_inc.h"
46 #include <fcntl.h>
49 * Set the current time-out period for getting input.
51 * delay: < 0 for infinite delay (blocking read)
52 * = 0 for no delay read
53 * > 0 to specify a period in millisecs to wait
54 * for input, then return '\0' if none comes
57 static void _setblock(int), _settimeout(int);
59 int
60 ttimeout(int delay)
62 if (cur_term->_inputfd < 0)
63 return (ERR);
65 if (delay < 0)
66 delay = -1;
68 if (cur_term->_delay == delay)
69 goto good;
71 #ifdef SYSV
72 if (delay > 0) {
73 if (cur_term->_delay < 0)
74 _setblock(-delay);
75 _settimeout(delay);
76 } else
77 if ((delay + cur_term->_delay) == -1)
78 _setblock(delay);
79 else {
80 if (delay < 0)
81 _setblock(delay);
82 _settimeout(delay);
84 #else /* SYSV */
85 cbreak();
86 #endif /* SYSV */
88 cur_term->_delay = delay;
89 good:
90 return (OK);
93 #ifdef SYSV
94 /* set the terminal to nodelay (==0) or block(<0) */
95 static void
96 _setblock(int block)
98 int flags = fcntl(cur_term->_inputfd, F_GETFL, 0);
100 if (block < 0)
101 flags &= ~O_NDELAY;
102 else
103 flags |= O_NDELAY;
105 (void) fcntl(cur_term->_inputfd, F_SETFL, flags);
109 * set the terminal to timeout in t milliseconds,
110 * rounded up to the nearest 10th of a second.
112 static void
113 _settimeout(int num)
115 PROGTTYS.c_lflag &= ~ICANON;
116 if (num > 0) {
117 PROGTTYS.c_cc[VMIN] = 0;
118 PROGTTYS.c_cc[VTIME] = (num > 25500) ? 255 : (num + 99) / 100;
119 cur_term->_fl_rawmode = 3;
120 } else {
121 PROGTTYS.c_cc[VMIN] = 1;
122 PROGTTYS.c_cc[VTIME] = 0;
123 cur_term->_fl_rawmode = 1;
125 (void) reset_prog_mode();
127 #endif /* SYSV */