1MKFIFO(3P) POSIX Programmer's Manual MKFIFO(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 mkfifo, mkfifoat — make a FIFO special file relative to directory file
14 descriptor
15
17 #include <sys/stat.h>
18
19 int mkfifo(const char *path, mode_t mode);
20 int mkfifoat(int fd, const char *path, mode_t mode);
21
23 The mkfifo() function shall create a new FIFO special file named by the
24 pathname pointed to by path. The file permission bits of the new FIFO
25 shall be initialized from mode. The file permission bits of the mode
26 argument shall be modified by the process' file creation mask.
27
28 When bits in mode other than the file permission bits are set, the
29 effect is implementation-defined.
30
31 If path names a symbolic link, mkfifo() shall fail and set errno to
32 [EEXIST].
33
34 The FIFO's user ID shall be set to the process' effective user ID. The
35 FIFO's group ID shall be set to the group ID of the parent directory or
36 to the effective group ID of the process. Implementations shall provide
37 a way to initialize the FIFO's group ID to the group ID of the parent
38 directory. Implementations may, but need not, provide an implementa‐
39 tion-defined way to initialize the FIFO's group ID to the effective
40 group ID of the calling process.
41
42 Upon successful completion, mkfifo() shall mark for update the last
43 data access, last data modification, and last file status change time‐
44 stamps of the file. Also, the last data modification and last file sta‐
45 tus change timestamps of the directory that contains the new entry
46 shall be marked for update.
47
48 The mkfifoat() function shall be equivalent to the mkfifo() function
49 except in the case where path specifies a relative path. In this case
50 the newly created FIFO is created relative to the directory associated
51 with the file descriptor fd instead of the current working directory.
52 If the file descriptor was opened without O_SEARCH, the function shall
53 check whether directory searches are permitted using the current per‐
54 missions of the directory underlying the file descriptor. If the file
55 descriptor was opened with O_SEARCH, the function shall not perform the
56 check.
57
58 If mkfifoat() is passed the special value AT_FDCWD in the fd parameter,
59 the current working directory shall be used and the behavior shall be
60 identical to a call to mkfifo().
61
63 Upon successful completion, these functions shall return 0. Otherwise,
64 these functions shall return −1 and set errno to indicate the error. If
65 −1 is returned, no FIFO shall be created.
66
68 These functions shall fail if:
69
70 EACCES A component of the path prefix denies search permission, or
71 write permission is denied on the parent directory of the FIFO
72 to be created.
73
74 EEXIST The named file already exists.
75
76 ELOOP A loop exists in symbolic links encountered during resolution of
77 the path argument.
78
79 ENAMETOOLONG
80 The length of a component of a pathname is longer than
81 {NAME_MAX}.
82
83 ENOENT A component of the path prefix of path does not name an existing
84 file or path is an empty string.
85
86 ENOENT or ENOTDIR
87 The path argument contains at least one non-<slash> character
88 and ends with one or more trailing <slash> characters. If path
89 names an existing file, an [ENOENT] error shall not occur.
90
91 ENOSPC The directory that would contain the new file cannot be extended
92 or the file system is out of file-allocation resources.
93
94 ENOTDIR
95 A component of the path prefix names an existing file that is
96 neither a directory nor a symbolic link to a directory.
97
98 EROFS The named file resides on a read-only file system.
99
100 The mkfifoat() function shall fail if:
101
102 EACCES fd was not opened with O_SEARCH and the permissions of the
103 directory underlying fd do not permit directory searches.
104
105 EBADF The path argument does not specify an absolute path and the fd
106 argument is neither AT_FDCWD nor a valid file descriptor open
107 for reading or searching.
108
109 ENOTDIR
110 The path argument is not an absolute path and fd is a file
111 descriptor associated with a non-directory file.
112
113 These functions may fail if:
114
115 ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during
116 resolution of the path argument.
117
118 ENAMETOOLONG
119 The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
120 tion of a symbolic link produced an intermediate result with a
121 length that exceeds {PATH_MAX}.
122
123 The following sections are informative.
124
126 Creating a FIFO File
127 The following example shows how to create a FIFO file named
128 /home/cnd/mod_done, with read/write permissions for owner, and with
129 read permissions for group and others.
130
131 #include <sys/types.h>
132 #include <sys/stat.h>
133
134 int status;
135 ...
136 status = mkfifo("/home/cnd/mod_done", S_IWUSR | S_IRUSR |
137 S_IRGRP | S_IROTH);
138
140 None.
141
143 The syntax of this function is intended to maintain compatibility with
144 historical implementations of mknod(). The latter function was
145 included in the 1984 /usr/group standard but only for use in creating
146 FIFO special files. The mknod() function was originally excluded from
147 the POSIX.1‐1988 standard as implementation-defined and replaced by
148 mkdir() and mkfifo(). The mknod() function is now included for align‐
149 ment with the Single UNIX Specification.
150
151 The POSIX.1‐1990 standard required that the group ID of a newly created
152 FIFO be set to the group ID of its parent directory or to the effective
153 group ID of the creating process. FIPS 151‐2 required that implementa‐
154 tions provide a way to have the group ID be set to the group ID of the
155 containing directory, but did not prohibit implementations also sup‐
156 porting a way to set the group ID to the effective group ID of the cre‐
157 ating process. Conforming applications should not assume which group
158 ID will be used. If it matters, an application can use chown() to set
159 the group ID after the FIFO is created, or determine under what condi‐
160 tions the implementation will set the desired group ID.
161
162 The purpose of the mkfifoat() function is to create a FIFO special file
163 in directories other than the current working directory without expo‐
164 sure to race conditions. Any part of the path of a file could be
165 changed in parallel to a call to mkfifo(), resulting in unspecified
166 behavior. By opening a file descriptor for the target directory and
167 using the mkfifoat() function it can be guaranteed that the newly cre‐
168 ated FIFO is located relative to the desired directory.
169
171 None.
172
174 chmod(), mknod(), umask()
175
176 The Base Definitions volume of POSIX.1‐2008, <sys_stat.h>,
177 <sys_types.h>
178
180 Portions of this text are reprinted and reproduced in electronic form
181 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
182 -- Portable Operating System Interface (POSIX), The Open Group Base
183 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
184 cal and Electronics Engineers, Inc and The Open Group. (This is
185 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
186 event of any discrepancy between this version and the original IEEE and
187 The Open Group Standard, the original IEEE and The Open Group Standard
188 is the referee document. The original Standard can be obtained online
189 at http://www.unix.org/online.html .
190
191 Any typographical or formatting errors that appear in this page are
192 most likely to have been introduced during the conversion of the source
193 files to man page format. To report such errors, see https://www.ker‐
194 nel.org/doc/man-pages/reporting_bugs.html .
195
196
197
198IEEE/The Open Group 2013 MKFIFO(3P)