Update.
[glibc.git] / manual / examples / select.c
blobdef2cd6f9fe0ca51fe6c25af668b483f2e771707
1 /*@group*/
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <sys/types.h>
5 #include <sys/time.h>
6 /*@end group*/
8 /*@group*/
9 int
10 input_timeout (int filedes, unsigned int seconds)
12 fd_set set;
13 struct timeval timeout;
14 /*@end group*/
16 /* Initialize the file descriptor set. */
17 FD_ZERO (&set);
18 FD_SET (filedes, &set);
20 /* Initialize the timeout data structure. */
21 timeout.tv_sec = seconds;
22 timeout.tv_usec = 0;
24 /*@group*/
25 /* @code{select} returns 0 if timeout, 1 if input available, -1 if error. */
26 return TEMP_FAILURE_RETRY (select (FD_SETSIZE,
27 &set, NULL, NULL,
28 &timeout));
30 /*@end group*/
32 /*@group*/
33 int
34 main (void)
36 fprintf (stderr, "select returned %d.\n",
37 input_timeout (STDIN_FILENO, 5));
38 return 0;
40 /*@end group*/