gtpc2m4s | C/C++ Language Support User's Guide |
This function creates a FIFO special file. A FIFO special file is a file that is typically used to send data from one process to another so that the receiving process reads the data in first-in-first-out (FIFO) format. A FIFO special file is also known as a named pipe.
Format
#include <sys/types.h> #include <sys/stat.h> int mkfifo(const char *path, mode_t mode)
This function creates a new file called path. The file permission bits in mode are modified by the file creation mask of the process and then used to set the file permission bits of the pipe being created. For more information about the file creation mask, see umask-Set the File Mode Creation Mask; for information about the file permission bits, see chmod-Change the Mode of a File or Directory.
The user ID of the new file is set to the effective user ID of the process. If the S_ISGID mode bit is set to OFF in the parent directory, the group ID of the new file is set to the group ID of the process; otherwise, the group ID of the new file is set to the group ID of the parent directory.
When it has completed successfully, the mkfifo function updates the st_mtime field in the new file and also updates the st_mtime field of the directory that contains the new file.
TPF deviation from POSIX |
---|
The TPF system does not support the atime (access time) or ctime (change time) time stamp. |
Normal Return
A value of 0.
Error Return
A value of -1 and errno is set to one of the following:
Programming Considerations
Because the mkfifo function requires an update to an existing directory file, new pipes cannot be created in 1052 or UTIL state.
Examples
The following example uses the mkfifo function to create a FIFO special file called temp.fifo and then writes and reads from the file before closing it.
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <stdio.h> main() { char fn[]="temp.fifo"; char out[20]="FIFO's are fun!", in[20]; int rfd, wfd; if (mkfifo(fn, S_IRWXU) != 0) perror("mkfifo() error"); else { if ((rfd = open(fn, O_RDONLY|O_NONBLOCK)) < 0) perror("open() error for read end"); else { if ((wfd = open(fn, O_WRONLY)) < 0) perror("open() error for write end"); else { if (write(wfd, out, strlen(out)+1) == -1) perror("write() error"); else if (read(rfd, in, sizeof(in)) == -1) perror("read() error"); else printf("read '%s' from the FIFO\n", in); close(wfd); } close(rfd); } unlink(fn); } }
Related Information
See TPF Concepts and Structures for more information about special files.
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.