diff options
author | 2000-10-10 15:10:29 +0000 | |
---|---|---|
committer | 2000-10-10 15:10:29 +0000 | |
commit | a63cca663781c9cd66123066d673fff22ad0dfc1 (patch) | |
tree | 487bd214579c29a5aa7ebccb96afe27a45e165cd /lib/libcurses/base/lib_getch.c | |
parent | bring in icmp rate limitation code. (diff) | |
download | wireguard-openbsd-a63cca663781c9cd66123066d673fff22ad0dfc1.tar.xz wireguard-openbsd-a63cca663781c9cd66123066d673fff22ad0dfc1.zip |
Don't ignore $TERMCAP, $TERMINFO, $TERMINFO_DIRS, $TERMPATH, and $HOME
if root but not setugid.
Fix select usage to deal with an arbitrary number of fd's. This code
is not compiled since we use poll(2).
Diffstat (limited to 'lib/libcurses/base/lib_getch.c')
-rw-r--r-- | lib/libcurses/base/lib_getch.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/lib/libcurses/base/lib_getch.c b/lib/libcurses/base/lib_getch.c index 0b37e2190c6..ca60de8dddc 100644 --- a/lib/libcurses/base/lib_getch.c +++ b/lib/libcurses/base/lib_getch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_getch.c,v 1.7 2000/10/08 22:46:58 millert Exp $ */ +/* $OpenBSD: lib_getch.c,v 1.8 2000/10/10 15:10:31 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. * @@ -53,34 +53,40 @@ int ESCDELAY = 1000; /* max interval betw. chars in funkeys, in millisecs */ static int kbd_mouse_read(unsigned char *p) { - fd_set fdset; + fd_set *fdset; + size_t fdsetsize; int nums = SP->_ifd + 1; + if (SP->_checkfd >= 0 && SP->_checkfd >= nums) + nums = SP->_checkfd + 1; + if (SP->_mouse_fd >= 0 && SP->_mouse_fd >= nums) + nums = SP->_mouse_fd + 1; + fdsetsize = howmany(nums, NFDBITS) * sizeof(fd_mask); + fdset = malloc(fdsetsize); + if (fdset == NULL) + return -1; + for (;;) { - FD_ZERO(&fdset); - FD_SET(SP->_ifd, &fdset); - if (SP->_checkfd >= 0) { - FD_SET(SP->_checkfd, &fdset); - if (SP->_checkfd >= nums) - nums = SP->_checkfd + 1; - } - if (SP->_mouse_fd >= 0) { - FD_SET(SP->_mouse_fd, &fdset); - if (SP->_mouse_fd >= nums) - nums = SP->_mouse_fd + 1; - } - if (select(nums, &fdset, NULL, NULL, NULL) >= 0) { + memset(fdset, 0, fdsetsize); + FD_SET(SP->_ifd, fdset); + if (SP->_checkfd >= 0) + FD_SET(SP->_checkfd, fdset); + if (SP->_mouse_fd >= 0) + FD_SET(SP->_mouse_fd, fdset); + if (select(nums, fdset, NULL, NULL, NULL) >= 0) { int n; if (SP->_mouse_fd >= 0 - && FD_ISSET(SP->_mouse_fd, &fdset)) { /* Prefer mouse */ + && FD_ISSET(SP->_mouse_fd, fdset)) { /* Prefer mouse */ n = read(SP->_mouse_fd, p, 1); } else { n = read(SP->_ifd, p, 1); } + free(fdset); return n; } if (errno != EINTR) { + free(fdset); return -1; } } |