12345678910111213141516171819202122232425262728293031323334353637 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <errno.h>
- #include <sys/stat.h>
- #define FIFO_PATH "/bin/test_fifo"
- int main() {
-
- if (mkfifo(FIFO_PATH, 0666) == -1 && errno != EEXIST) {
- perror("mkfifo failed");
- exit(EXIT_FAILURE);
- }
- printf("Opening FIFO in write mode...\n");
-
- int fd = open(FIFO_PATH, O_WRONLY|O_NONBLOCK);
- printf("fd: %d\n",fd);
- if (fd == -1) {
- if (errno == ENXIO) {
- printf("Error: No readers (ENXIO).\n");
- } else {
- perror("Failed to open FIFO");
- }
- } else {
- printf("FIFO opened successfully in write mode.\n");
- close(fd);
- }
-
- unlink(FIFO_PATH);
- return 0;
- }
|