Back to index

glibc  2.9
select.c
Go to the documentation of this file.
00001 /*@group*/
00002 #include <errno.h>
00003 #include <stdio.h>
00004 #include <unistd.h>
00005 #include <sys/types.h>
00006 #include <sys/time.h>
00007 /*@end group*/
00008 
00009 /*@group*/
00010 int
00011 input_timeout (int filedes, unsigned int seconds)
00012 {
00013   fd_set set;
00014   struct timeval timeout;
00015 /*@end group*/
00016 
00017   /* Initialize the file descriptor set. */
00018   FD_ZERO (&set);
00019   FD_SET (filedes, &set);
00020 
00021   /* Initialize the timeout data structure. */
00022   timeout.tv_sec = seconds;
00023   timeout.tv_usec = 0;
00024 
00025 /*@group*/
00026   /* @code{select} returns 0 if timeout, 1 if input available, -1 if error. */
00027   return TEMP_FAILURE_RETRY (select (FD_SETSIZE,
00028                                  &set, NULL, NULL,
00029                                  &timeout));
00030 }
00031 /*@end group*/
00032 
00033 /*@group*/
00034 int
00035 main (void)
00036 {
00037   fprintf (stderr, "select returned %d.\n",
00038           input_timeout (STDIN_FILENO, 5));
00039   return 0;
00040 }
00041 /*@end group*/