Fix bad reads due to erroneous use of stdio
This commit is contained in:
parent
b79e33ad76
commit
4c103806d0
10
apps/bim.c
10
apps/bim.c
@ -138,8 +138,10 @@ int bim_getch(void) {
|
||||
#ifdef __linux__
|
||||
struct pollfd fds[] = {STDIN_FILENO,POLLIN,0};
|
||||
int ret = poll(fds,1,200);
|
||||
if (ret > 0) {
|
||||
return fgetc(stdin);
|
||||
if (ret > 0 && fds[0].revents & POLLIN) {
|
||||
char buf[1];
|
||||
read(STDIN_FILENO, buf, 1);
|
||||
return buf[0];
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
@ -147,7 +149,9 @@ int bim_getch(void) {
|
||||
int fds[] = {STDIN_FILENO};
|
||||
int index = fswait2(1,fds,200);
|
||||
if (index == 0) {
|
||||
return fgetc(stdin);
|
||||
char buf[1];
|
||||
read(STDIN_FILENO, buf, 1);
|
||||
return buf[0];
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user