Magellan Linux

Annotation of /trunk/mkinitrd-magellan/klibc/usr/klibc/tests/select.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1297 - (hide annotations) (download)
Fri May 27 15:12:11 2011 UTC (12 years, 11 months ago) by niro
File MIME type: text/plain
File size: 1073 byte(s)
-updated to klibc-1.5.22 with mntproc definitions patch included
1 niro 532 /*
2     * Simple test of select()
3     */
4    
5     #include <sys/select.h>
6     #include <fcntl.h>
7     #include <stdio.h>
8     #include <string.h>
9     #include <errno.h>
10     #include <unistd.h>
11    
12     int main(int argc, char *argv[])
13     {
14     int fdn, fdz, pfd[2], rv;
15     fd_set readset;
16     struct timeval timeout;
17     int err = 0;
18    
19     /* We can always read from /dev/zero; open a pipe that is never
20     ready for a "never readable" file descriptor */
21     fdz = open("/dev/zero", O_RDONLY);
22     pipe(pfd);
23     fdn = pfd[0];
24    
25     FD_ZERO(&readset);
26     FD_SET(fdn, &readset);
27    
28     timeout.tv_sec = 0;
29     timeout.tv_usec = 100000;
30    
31     rv = select(FD_SETSIZE, &readset, NULL, NULL, &timeout);
32    
33     if (rv != 0) {
34     fprintf(stderr,
35     "select with timeout failed (rv = %d, errno = %s)\n",
36     rv, strerror(errno));
37     err++;
38     }
39    
40     FD_ZERO(&readset);
41     FD_SET(fdn, &readset);
42     FD_SET(fdz, &readset);
43    
44     rv = select(FD_SETSIZE, &readset, NULL, NULL, &timeout);
45 niro 1297
46 niro 532 if (rv != 1 || !FD_ISSET(fdz, &readset) ||
47     FD_ISSET(fdn, &readset)) {
48     fprintf(stderr,
49     "select with /dev/zero failed (rv = %d, errno = %s)\n",
50     rv, strerror(errno));
51     err++;
52     }
53    
54     return err;
55     }