4 * Objetive: The purpose of this test is to make sure that select works
5 * when working with files.
7 * Description: This tests first creates six dummy files with different
8 * modes and performs select calls on them evaluating the input and resulting
14 #include <sys/types.h>
17 #include <sys/select.h>
22 void dump_fdset(fd_set
*set
) {
24 for (i
= 0; i
< OPEN_MAX
; i
++)
32 int main(int argc
, char *argv
[])
34 int fd1
, fd2
, fd3
, fd4
, fd5
, fd6
; /* file descriptors of files */
35 fd_set fds_read
, fds_write
;
38 /* Creates the dummy files with different modes */
39 fd1
= open("dummy1.txt", O_CREAT
| O_RDONLY
);
41 perror("Error opening file");
45 fd2
= open("dummy2.txt", O_CREAT
| O_RDONLY
);
47 perror("Error opening file");
51 fd3
= open("dummy3.txt", O_CREAT
| O_WRONLY
);
53 perror("Error opening file");
57 fd4
= open("dummy4.txt", O_CREAT
| O_WRONLY
);
59 perror("Error opening file");
63 fd5
= open("dummy5.txt", O_CREAT
| O_RDWR
);
65 perror("Error opening file");
69 fd6
= open("dummy6.txt", O_CREAT
| O_RDWR
);
71 perror("Error opening file");
75 /* Create the fd_set structures */
78 FD_SET(fd1
, &fds_read
); /* fd1 => O_RDONLY */
79 FD_SET(fd2
, &fds_read
); /* fd2 => O_RDONLY */
80 FD_SET(fd3
, &fds_write
); /* fd3 => O_WRONLY */
81 FD_SET(fd4
, &fds_write
); /* fd4 => O_WRONLY */
82 FD_SET(fd5
, &fds_read
); /* fd5 => O_RDWR */
83 FD_SET(fd5
, &fds_write
); /* fd5 => O_RDWR */
84 FD_SET(fd6
, &fds_read
); /* fd6 => O_RDWR */
85 FD_SET(fd6
, &fds_write
); /* fd6 => O_RDWR */
87 printf("* Dump INPUT fds_read:\n");
88 dump_fdset(&fds_read
);
89 printf("* Dump INPUT fds_write:\n");
90 dump_fdset(&fds_write
);
92 retval
=select(9, &fds_read
, &fds_write
, NULL
, NULL
);
93 printf("\n***********************\n");
94 printf("After select: \n");
95 printf("Return value: %d\n", retval
);
96 printf("* Dump RESULTING fds_read:\n");
97 dump_fdset(&fds_read
);
98 printf("* Dump RESULTING fds_write:\n");
99 dump_fdset(&fds_write
);
100 /* close and delete dummy files */
107 unlink("dummy1.txt");
108 unlink("dummy2.txt");
109 unlink("dummy3.txt");
110 unlink("dummy4.txt");
111 unlink("dummy5.txt");
112 unlink("dummy6.txt");