1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <unistd.h> 4 #include <errno.h> 5 #include <fcntl.h> 6 #include <sys/select.h> 7 #include <sys/types.h> 8 9 main(int argc, char *argv[]) 10 { 11 int result, fd; 12 fd_set rset; 13 char tmpstr[] = "seltest.XXXX"; 14 15 if ((fd = mkstemp(tmpstr)) < 0) { 16 printf ("Error %d opening temp file\n", errno); 17 exit (-1); 18 } 19 20 lseek(fd, 0, SEEK_END); 21 22 FD_ZERO(&rset); 23 FD_SET(fd, &rset); 24 25 result = select(fd + 1, &rset, 0, 0, 0); 26 if (result == 1) 27 printf("OK\n"); 28 else 29 printf("FAIL\n"); 30 31 unlink(tmpstr); 32 33 return !result; 34 } 35