4 * Objetive: The purpose of this test is to make sure that select works
5 * when working with the terminal.
7 * Description: This tests wait entry from stdin using select and displays
8 * it again in stdout when it is ready to write (which is always)
13 #include <sys/types.h>
16 #include <sys/select.h>
23 fd_set fds_read
, fds_write
;
29 FD_SET(0, &fds_read
); /* stdin */
30 FD_SET(1, &fds_write
); /* stdout */
33 printf("Input some data: ");
35 retval
=select(3, &fds_read
, NULL
, NULL
, NULL
);
37 fprintf(stderr
, "Error while executing select\n");
40 printf("select retval: %d\n", retval
);
41 if (!FD_ISSET(0, &fds_read
)) {
42 fprintf(stderr
, "Error: stdin not ready (?)\n");
47 printf("gets done..\n");
48 if (!strcmp(data
, "exit"))
50 printf("Try to write it back\n");
51 retval
=select(3, NULL
, &fds_write
, NULL
, NULL
);
53 fprintf(stderr
, "Error while executing select\n");
56 if (!FD_ISSET(1, &fds_write
)) {
57 fprintf(stderr
, "Error: stdout not ready (?)\n");
60 printf("Data: %s\n", data
);