1 /* $OpenBSD: lib_kernel.c,v 1.2 2001/01/22 18:01:52 millert Exp $ */ 2 3 /**************************************************************************** 4 * Copyright (c) 1998,2000 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 ****************************************************************************/ 35 36 /* 37 * lib_kernel.c 38 * 39 * Misc. low-level routines: 40 * erasechar() 41 * killchar() 42 * flushinp() 43 * 44 * The baudrate() and delay_output() functions could logically live here, 45 * but are in other modules to reduce the static-link size of programs 46 * that use only these facilities. 47 */ 48 49 #include <curses.priv.h> 50 #include <term.h> /* cur_term */ 51 52 MODULE_ID("$From: lib_kernel.c,v 1.21 2000/12/10 02:55:07 tom Exp $") 53 54 /* 55 * erasechar() 56 * 57 * Return erase character as given in cur_term->Ottyb. 58 * 59 */ 60 61 NCURSES_EXPORT(char) 62 erasechar(void) 63 { 64 T((T_CALLED("erasechar()"))); 65 66 if (cur_term != 0) { 67 #ifdef TERMIOS 68 returnCode(cur_term->Ottyb.c_cc[VERASE]); 69 #else 70 returnCode(cur_term->Ottyb.sg_erase); 71 #endif 72 } 73 returnCode(ERR); 74 } 75 76 /* 77 * killchar() 78 * 79 * Return kill character as given in cur_term->Ottyb. 80 * 81 */ 82 83 NCURSES_EXPORT(char) 84 killchar(void) 85 { 86 T((T_CALLED("killchar()"))); 87 88 if (cur_term != 0) { 89 #ifdef TERMIOS 90 returnCode(cur_term->Ottyb.c_cc[VKILL]); 91 #else 92 returnCode(cur_term->Ottyb.sg_kill); 93 #endif 94 } 95 returnCode(ERR); 96 } 97 98 /* 99 * flushinp() 100 * 101 * Flush any input on cur_term->Filedes 102 * 103 */ 104 105 NCURSES_EXPORT(int) 106 flushinp(void) 107 { 108 T((T_CALLED("flushinp()"))); 109 110 if (cur_term != 0) { 111 #ifdef TERMIOS 112 tcflush(cur_term->Filedes, TCIFLUSH); 113 #else 114 errno = 0; 115 do { 116 ioctl(cur_term->Filedes, TIOCFLUSH, 0); 117 } while 118 (errno == EINTR); 119 #endif 120 if (SP) { 121 SP->_fifohead = -1; 122 SP->_fifotail = 0; 123 SP->_fifopeek = 0; 124 } 125 returnCode(OK); 126 } 127 returnCode(ERR); 128 } 129