From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/SNIP/timegetc.c | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 reference/C/CONTRIB/SNIP/timegetc.c (limited to 'reference/C/CONTRIB/SNIP/timegetc.c') diff --git a/reference/C/CONTRIB/SNIP/timegetc.c b/reference/C/CONTRIB/SNIP/timegetc.c new file mode 100755 index 0000000..c41c45b --- /dev/null +++ b/reference/C/CONTRIB/SNIP/timegetc.c @@ -0,0 +1,44 @@ +/* +** TIMEGETC.C - waits for a given number of seconds for the user to press +** a key. Returns the key pressed, or EOF if time expires +** +** by Bob Jarvis +*/ + +#include +#include +#include + +int timed_getch(int n_seconds) +{ + time_t start, now; + + start = time(NULL); + now = start; + + while(difftime(now, start) < (double)n_seconds && !kbhit()) + { + now = time(NULL); + } + + if(kbhit()) + return getch(); + else return EOF; +} + +#ifdef TEST + +void main(void) +{ + int c; + + printf("Starting a 5 second delay...\n"); + + c = timed_getch(5); + + if(c == EOF) + printf("Timer expired\n"); + else printf("Key was pressed, c = '%c'\n", c); +} + +#endif /* TEST */ -- cgit v1.2.3-54-g00ecf n> net-next plumbingsTobias Klauser
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/devicetree')