1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
int
main(void)
{
fd_set rfds;
struct timeval tv;
int retval;
char buf[100];
int l;
/* Surveiller stdin (fd 0) en attente d'entrées */
/* Pendant 5 secondes maxi */
tv.tv_sec = 0;
tv.tv_usec = 0;
/* Considérer tv comme indéfini maintenant ! */
while (1)
{
FD_ZERO(&rfds);
FD_SET(0, &rfds);
retval = select(1, &rfds, NULL, NULL, &tv);
if (retval)
{
l = read(0, buf, 50);
buf[l] = 0;
printf("%s\n", buf);
}
/* FD_ISSET(0, &rfds) est vrai */
}
return (0);
} |
Partager