Rewrite _dl_runtime_resolve to use nacljmp instead of ret
[glibc/nacl-glibc.git] / manual / examples / select.c
bloba65ed775038dd8acc1785c9bc947b2011f41a42d
1 /*@group*/
2 #include <errno.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <sys/types.h>
6 #include <sys/time.h>
7 /*@end group*/
9 /*@group*/
10 int
11 input_timeout (int filedes, unsigned int seconds)
13 fd_set set;
14 struct timeval timeout;
15 /*@end group*/
17 /* Initialize the file descriptor set. */
18 FD_ZERO (&set);
19 FD_SET (filedes, &set);
21 /* Initialize the timeout data structure. */
22 timeout.tv_sec = seconds;
23 timeout.tv_usec = 0;
25 /*@group*/
26 /* @code{select} returns 0 if timeout, 1 if input available, -1 if error. */
27 return TEMP_FAILURE_RETRY (select (FD_SETSIZE,
28 &set, NULL, NULL,
29 &timeout));
31 /*@end group*/
33 /*@group*/
34 int
35 main (void)
37 fprintf (stderr, "select returned %d.\n",
38 input_timeout (STDIN_FILENO, 5));
39 return 0;
41 /*@end group*/