+#ifdef USE_EMX_MOUSE
+# include <sys/select.h>
+static int
+kbd_mouse_read(unsigned char *p)
+{
+fd_set fdset;
+int nums = SP->_ifd+1;
+
+ for (;;) {
+ FD_ZERO(&fdset);
+ FD_SET(SP->_checkfd, &fdset);
+ if (SP->_mouse_fd >= 0) {
+ FD_SET(SP->_mouse_fd, &fdset);
+ if (SP->_mouse_fd > SP->_checkfd)
+ nums = SP->_mouse_fd+1;
+ }
+ if (select(nums, &fdset, NULL, NULL, NULL) >= 0) {
+ int n;
+
+ if (FD_ISSET(SP->_mouse_fd, &fdset)) /* Prefer mouse */
+ n = read(SP->_mouse_fd, p, 1);
+ else
+ n = read(SP->_ifd, p, 1);
+ return n;
+ }
+ if (errno != EINTR)
+ return -1;
+ }
+}
+#endif /* USE_EMX_MOUSE */
+