Created
February 10, 2016 19:14
-
-
Save ryo/509513ff56a75a45a05a to your computer and use it in GitHub Desktop.
BUG: curses getch() with high frequency SIGALRM on FreeBSD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <signal.h> | |
| #include <curses.h> | |
| #include <string.h> | |
| #include <sys/time.h> | |
| //#define USE_ALARM | |
| void | |
| sigalrm(int signo) | |
| { | |
| } | |
| int | |
| main(int argc, char *argv[]) | |
| { | |
| WINDOW *win; | |
| int c; | |
| win = initscr(); | |
| noecho(); | |
| cbreak(); | |
| keypad(win, TRUE); | |
| #ifdef USE_ALARM | |
| signal(SIGALRM, sigalrm); | |
| { | |
| struct itimerval itv; | |
| memset(&itv, 0, sizeof(itv)); | |
| itv.it_interval.tv_sec = 0; | |
| itv.it_interval.tv_usec = 100; | |
| itv.it_value = itv.it_interval; | |
| setitimer(ITIMER_REAL, &itv, NULL); | |
| } | |
| #endif | |
| for (;;) { | |
| c = getch(); | |
| printw("c = %d\n", c); | |
| refresh(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment