Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (hide annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1074 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

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    
46     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     }