| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: thunk.c,v 1.48 2011/12/20 15:45:37 reinoud Exp $ */ | | 1 | /* $NetBSD: thunk.c,v 1.49 2011/12/20 21:07:56 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> | | 4 | * Copyright (c) 2011 Jared D. McNeill <jmcneill@invisible.ca> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -18,27 +18,27 @@ | | | @@ -18,27 +18,27 @@ |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | #ifdef __NetBSD__ | | 30 | #ifdef __NetBSD__ |
31 | __RCSID("$NetBSD: thunk.c,v 1.48 2011/12/20 15:45:37 reinoud Exp $"); | | 31 | __RCSID("$NetBSD: thunk.c,v 1.49 2011/12/20 21:07:56 jmcneill Exp $"); |
32 | #endif | | 32 | #endif |
33 | | | 33 | |
34 | #include <sys/types.h> | | 34 | #include <sys/types.h> |
35 | #include <sys/mman.h> | | 35 | #include <sys/mman.h> |
36 | #include <sys/reboot.h> | | 36 | #include <sys/reboot.h> |
37 | #include <sys/poll.h> | | 37 | #include <sys/poll.h> |
38 | #include <machine/vmparam.h> | | 38 | #include <machine/vmparam.h> |
39 | | | 39 | |
40 | #include <aio.h> | | 40 | #include <aio.h> |
41 | #include <assert.h> | | 41 | #include <assert.h> |
42 | #include <errno.h> | | 42 | #include <errno.h> |
43 | #include <fcntl.h> | | 43 | #include <fcntl.h> |
44 | #include <sched.h> | | 44 | #include <sched.h> |
| @@ -371,34 +371,37 @@ thunk_set_stdin_sigio(int onoff) | | | @@ -371,34 +371,37 @@ thunk_set_stdin_sigio(int onoff) |
371 | | | 371 | |
372 | if (onoff) | | 372 | if (onoff) |
373 | flags |= O_ASYNC; | | 373 | flags |= O_ASYNC; |
374 | else | | 374 | else |
375 | flags &= ~O_ASYNC; | | 375 | flags &= ~O_ASYNC; |
376 | | | 376 | |
377 | return fcntl(STDIN_FILENO, F_SETFL, flags); | | 377 | return fcntl(STDIN_FILENO, F_SETFL, flags); |
378 | } | | 378 | } |
379 | | | 379 | |
380 | int | | 380 | int |
381 | thunk_pollchar(void) | | 381 | thunk_pollchar(void) |
382 | { | | 382 | { |
383 | struct pollfd fds[1]; | | 383 | struct pollfd fds[1]; |
| | | 384 | uint8_t c; |
384 | | | 385 | |
385 | fds[0].fd = STDIN_FILENO; | | 386 | fds[0].fd = STDIN_FILENO; |
386 | fds[0].events = POLLIN; | | 387 | fds[0].events = POLLIN; |
387 | fds[0].revents = 0; | | 388 | fds[0].revents = 0; |
388 | | | 389 | |
389 | if (poll(fds, __arraycount(fds), 0) > 0) { | | 390 | if (poll(fds, __arraycount(fds), 0) > 0) { |
390 | if (fds[0].revents & POLLIN) { | | 391 | if (fds[0].revents & POLLIN) { |
391 | return getchar(); | | 392 | if (read(STDIN_FILENO, &c, 1) != 1) |
| | | 393 | return EOF; |
| | | 394 | return c; |
392 | } | | 395 | } |
393 | } | | 396 | } |
394 | | | 397 | |
395 | return EOF; | | 398 | return EOF; |
396 | } | | 399 | } |
397 | | | 400 | |
398 | int | | 401 | int |
399 | thunk_getchar(void) | | 402 | thunk_getchar(void) |
400 | { | | 403 | { |
401 | return getchar(); | | 404 | return getchar(); |
402 | } | | 405 | } |
403 | | | 406 | |
404 | void | | 407 | void |