GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libcurses/tinfo/lib_kernel.c Lines: 0 22 0.0 %
Date: 2017-11-13 Branches: 0 14 0.0 %

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