Skip to content

Instantly share code, notes, and snippets.

@ryo
Created February 10, 2016 19:14
Show Gist options
  • Select an option

  • Save ryo/509513ff56a75a45a05a to your computer and use it in GitHub Desktop.

Select an option

Save ryo/509513ff56a75a45a05a to your computer and use it in GitHub Desktop.
BUG: curses getch() with high frequency SIGALRM on FreeBSD
#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