36 #define FIFO_PATH "test-fifo"
37 #define TRIGGER_DELAY 5
39 #define perrorexit(s) { perror(s); exit(1); }
41 static void cleanup(
void)
43 printf(
"Removing fifo %s...\n",
FIFO_PATH);
49 static void perrorcleanup(
char *str)
56 static void readable_event(
int fd)
61 if (read(fd, &ch, 1) < 0) {
66 printf(
"FIFO remains readable after multiple reads.\n");
72 int main(
int unused_argc,
char **unused_argv)
86 printf(
"Open fifo %s, read-only mode...\n",
FIFO_PATH);
87 if ((fd = open(
FIFO_PATH, O_RDONLY | O_NONBLOCK, 0)) < 0)
88 perrorcleanup(
"open");
90 printf(
"Write one byte to the fifo, then close it...\n");
91 if ((fd2 = open(
FIFO_PATH, O_WRONLY, 0)) < 0)
92 perrorcleanup(
"open fifo O_WRONLY");
93 if (write(fd2,
"", 1) < 1)
94 perrorcleanup(
"write one byte to fifo");
96 perrorcleanup(
"close fifo");
98 printf(
"Selecting the fifo for readability...\n");
102 FD_SET(fd, &read_fds);
103 FD_ZERO(&except_fds);
104 FD_SET(fd, &except_fds);
108 switch (select(fd + 1, &read_fds, (fd_set *) 0, &except_fds, &tv)) {
112 if (FD_ISSET(fd, &except_fds)) {
113 printf(
"Exceptional fifo condition! You are not normal!\n");
115 }
else if (FD_ISSET(fd, &read_fds)) {
116 printf(
"Readable fifo condition\n");
121 printf(
"The fifo is not readable. You're normal.\n");
int main(int unused_argc, char **unused_argv)