mirror of
git://sourceware.org/git/glibc.git
synced 2024-11-27 03:41:23 +08:00
8e96ae1a08
2002-11-04 Ulrich Drepper <drepper@redhat.com> * manual/examples/dir.c: Don't include <stddef.h>. * manual/examples/select.c: Include <errno.h> for TEMP_FAILURE_RETRY. Reported by Frédéric Delanoy <delanoy_f@yahoo.com>. 2002-11-02 H.J. Lu <hjl@gnu.org> * stdio-common/reg-printf.c: Include <stddef.h>.
42 lines
786 B
C
42 lines
786 B
C
/*@group*/
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/time.h>
|
|
/*@end group*/
|
|
|
|
/*@group*/
|
|
int
|
|
input_timeout (int filedes, unsigned int seconds)
|
|
{
|
|
fd_set set;
|
|
struct timeval timeout;
|
|
/*@end group*/
|
|
|
|
/* Initialize the file descriptor set. */
|
|
FD_ZERO (&set);
|
|
FD_SET (filedes, &set);
|
|
|
|
/* Initialize the timeout data structure. */
|
|
timeout.tv_sec = seconds;
|
|
timeout.tv_usec = 0;
|
|
|
|
/*@group*/
|
|
/* @code{select} returns 0 if timeout, 1 if input available, -1 if error. */
|
|
return TEMP_FAILURE_RETRY (select (FD_SETSIZE,
|
|
&set, NULL, NULL,
|
|
&timeout));
|
|
}
|
|
/*@end group*/
|
|
|
|
/*@group*/
|
|
int
|
|
main (void)
|
|
{
|
|
fprintf (stderr, "select returned %d.\n",
|
|
input_timeout (STDIN_FILENO, 5));
|
|
return 0;
|
|
}
|
|
/*@end group*/
|