ncurses 4.2
[ncurses.git] / ncurses / tinfo / lib_kernel.c
1 /****************************************************************************
2  * Copyright (c) 1998 Free Software Foundation, Inc.                        *
3  *                                                                          *
4  * Permission is hereby granted, free of charge, to any person obtaining a  *
5  * copy of this software and associated documentation files (the            *
6  * "Software"), to deal in the Software without restriction, including      *
7  * without limitation the rights to use, copy, modify, merge, publish,      *
8  * distribute, distribute with modifications, sublicense, and/or sell       *
9  * copies of the Software, and to permit persons to whom the Software is    *
10  * furnished to do so, subject to the following conditions:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22  *                                                                          *
23  * Except as contained in this notice, the name(s) of the above copyright   *
24  * holders shall not be used in advertising or otherwise to promote the     *
25  * sale, use or other dealings in this Software without prior written       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32  ****************************************************************************/
33
34
35 /*
36  *      lib_kernel.c
37  *
38  *      Misc. low-level routines:
39  *              erasechar()
40  *              killchar()
41  *              flushinp()
42  *
43  * The baudrate() and delay_output() functions could logically live here,
44  * but are in other modules to reduce the static-link size of programs
45  * that use only these facilities.
46  */
47
48 #include <curses.priv.h>
49 #include <term.h>       /* cur_term */
50
51 MODULE_ID("$Id: lib_kernel.c,v 1.19 1998/12/20 00:18:45 tom Exp $")
52
53 /*
54  *      erasechar()
55  *
56  *      Return erase character as given in cur_term->Ottyb.
57  *
58  */
59
60 char
61 erasechar(void)
62 {
63         T((T_CALLED("erasechar()")));
64
65         if (cur_term != 0) {
66 #ifdef TERMIOS
67                 returnCode(cur_term->Ottyb.c_cc[VERASE]);
68 #else
69                 returnCode(cur_term->Ottyb.sg_erase);
70 #endif
71         }
72         returnCode(ERR);
73 }
74
75
76
77 /*
78  *      killchar()
79  *
80  *      Return kill character as given in cur_term->Ottyb.
81  *
82  */
83
84 char
85 killchar(void)
86 {
87         T((T_CALLED("killchar()")));
88
89         if (cur_term != 0) {
90 #ifdef TERMIOS
91                 returnCode(cur_term->Ottyb.c_cc[VKILL]);
92 #else
93                 returnCode(cur_term->Ottyb.sg_kill);
94 #endif
95         }
96         returnCode(ERR);
97 }
98
99
100
101 /*
102  *      flushinp()
103  *
104  *      Flush any input on cur_term->Filedes
105  *
106  */
107
108 int flushinp(void)
109 {
110         T((T_CALLED("flushinp()")));
111
112         if (cur_term != 0) {
113 #ifdef TERMIOS
114                 tcflush(cur_term->Filedes, TCIFLUSH);
115 #else
116                 errno = 0;
117                 do {
118                     ioctl(cur_term->Filedes, TIOCFLUSH, 0);
119                 } while
120                     (errno == EINTR);
121 #endif
122                 if (SP) {
123                         SP->_fifohead = -1;
124                         SP->_fifotail = 0;
125                         SP->_fifopeek = 0;
126                 }
127                 returnCode(OK);
128         }
129         returnCode(ERR);
130 }