1MKFIFO(3P)                 POSIX Programmer's Manual                MKFIFO(3P)
2
3
4

PROLOG

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

NAME

12       mkfifo, mkfifoat — make a FIFO special file
13

SYNOPSIS

15       #include <sys/stat.h>
16
17       int mkfifo(const char *path, mode_t mode);
18
19       #include <fcntl.h>
20
21       int mkfifoat(int fd, const char *path, mode_t mode);
22

DESCRIPTION

24       The mkfifo() function shall create a new FIFO special file named by the
25       pathname  pointed to by path.  The file permission bits of the new FIFO
26       shall be initialized from mode.  The file permission bits of  the  mode
27       argument shall be modified by the process' file creation mask.
28
29       When  bits  in  mode  other  than the file permission bits are set, the
30       effect is implementation-defined.
31
32       If path names a symbolic link, mkfifo() shall fail  and  set  errno  to
33       [EEXIST].
34
35       The  FIFO's user ID shall be set to the process' effective user ID. The
36       FIFO's group ID shall be set to the group ID of the parent directory or
37       to the effective group ID of the process. Implementations shall provide
38       a way to initialize the FIFO's group ID to the group ID of  the  parent
39       directory.  Implementations  may,  but need not, provide an implementa‐
40       tion-defined way to initialize the FIFO's group  ID  to  the  effective
41       group ID of the calling process.
42
43       Upon  successful  completion,  mkfifo()  shall mark for update the last
44       data access, last data modification, and last file status change  time‐
45       stamps of the file. Also, the last data modification and last file sta‐
46       tus change timestamps of the directory  that  contains  the  new  entry
47       shall be marked for update.
48
49       The  mkfifoat()  function  shall be equivalent to the mkfifo() function
50       except in the case where path specifies a relative path. In  this  case
51       the  newly created FIFO is created relative to the directory associated
52       with the file descriptor fd instead of the current  working  directory.
53       If  the  access  mode  of the open file description associated with the
54       file descriptor is not  O_SEARCH,  the  function  shall  check  whether
55       directory  searches  are permitted using the current permissions of the
56       directory underlying  the  file  descriptor.  If  the  access  mode  is
57       O_SEARCH, the function shall not perform the check.
58
59       If mkfifoat() is passed the special value AT_FDCWD in the fd parameter,
60       the current working directory shall be used and the behavior  shall  be
61       identical to a call to mkfifo().
62

RETURN VALUE

64       Upon successful completion, these functions shall return 0.  Otherwise,
65       these functions shall return -1 and set errno to indicate the error. If
66       -1 is returned, no FIFO shall be created.
67

ERRORS

69       These functions shall fail if:
70
71       EACCES A  component  of  the  path  prefix denies search permission, or
72              write permission is denied on the parent directory of  the  FIFO
73              to be created.
74
75       EEXIST The named file already exists.
76
77       ELOOP  A loop exists in symbolic links encountered during resolution of
78              the path argument.
79
80       ENAMETOOLONG
81              The  length  of  a  component  of  a  pathname  is  longer  than
82              {NAME_MAX}.
83
84       ENOENT A component of the path prefix of path does not name an existing
85              file or path is an empty string.
86
87       ENOENT or ENOTDIR
88              The path argument contains at least  one  non-<slash>  character
89              and  ends  with one or more trailing <slash> characters. If path
90              without the trailing <slash> characters would name  an  existing
91              file, an [ENOENT] error shall not occur.
92
93       ENOSPC The directory that would contain the new file cannot be extended
94              or the file system is out of file-allocation resources.
95
96       ENOTDIR
97              A component of the path prefix names an existing  file  that  is
98              neither a directory nor a symbolic link to a directory.
99
100       EROFS  The named file resides on a read-only file system.
101
102       The mkfifoat() function shall fail if:
103
104       EACCES The  access mode of the open file description associated with fd
105              is not O_SEARCH and the permissions of the directory  underlying
106              fd do not permit directory searches.
107
108       EBADF  The  path  argument does not specify an absolute path and the fd
109              argument is neither AT_FDCWD nor a valid  file  descriptor  open
110              for reading or searching.
111
112       ENOTDIR
113              The  path  argument  is  not  an  absolute path and fd is a file
114              descriptor associated with a non-directory file.
115
116       These functions may fail if:
117
118       ELOOP  More than {SYMLOOP_MAX} symbolic links were  encountered  during
119              resolution of the path argument.
120
121       ENAMETOOLONG
122              The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
123              tion of a symbolic link produced an intermediate result  with  a
124              length that exceeds {PATH_MAX}.
125
126       The following sections are informative.
127

EXAMPLES

129   Creating a FIFO File
130       The   following   example  shows  how  to  create  a  FIFO  file  named
131       /home/cnd/mod_done, with read/write permissions  for  owner,  and  with
132       read permissions for group and others.
133
134
135           #include <sys/types.h>
136           #include <sys/stat.h>
137
138           int status;
139           ...
140           status = mkfifo("/home/cnd/mod_done", S_IWUSR | S_IRUSR |
141               S_IRGRP | S_IROTH);
142

APPLICATION USAGE

144       None.
145

RATIONALE

147       The  syntax of this function is intended to maintain compatibility with
148       historical  implementations  of  mknod().   The  latter  function   was
149       included  in  the 1984 /usr/group standard but only for use in creating
150       FIFO special files. The mknod() function was originally  excluded  from
151       the  POSIX.1‐1988  standard  as  implementation-defined and replaced by
152       mkdir() and mkfifo().  The mknod() function is now included for  align‐
153       ment with the Single UNIX Specification.
154
155       The POSIX.1‐1990 standard required that the group ID of a newly created
156       FIFO be set to the group ID of its parent directory or to the effective
157       group  ID of the creating process. FIPS 151‐2 required that implementa‐
158       tions provide a way to have the group ID be set to the group ID of  the
159       containing  directory,  but  did not prohibit implementations also sup‐
160       porting a way to set the group ID to the effective group ID of the cre‐
161       ating  process.   Conforming applications should not assume which group
162       ID will be used. If it matters, an application can use chown()  to  set
163       the  group ID after the FIFO is created, or determine under what condi‐
164       tions the implementation will set the desired group ID.
165
166       The purpose of the mkfifoat() function is to create a FIFO special file
167       in  directories  other than the current working directory without expo‐
168       sure to race conditions. Any part of  the  path  of  a  file  could  be
169       changed  in  parallel  to  a call to mkfifo(), resulting in unspecified
170       behavior. By opening a file descriptor for  the  target  directory  and
171       using  the mkfifoat() function it can be guaranteed that the newly cre‐
172       ated FIFO is located relative to the desired directory.
173

FUTURE DIRECTIONS

175       None.
176

SEE ALSO

178       chmod(), mknod(), umask()
179
180       The Base Definitions volume of POSIX.1‐2017,  <fcntl.h>,  <sys_stat.h>,
181       <sys_types.h>
182
184       Portions  of  this text are reprinted and reproduced in electronic form
185       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
186       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
187       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
188       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
189       event of any discrepancy between this version and the original IEEE and
190       The  Open Group Standard, the original IEEE and The Open Group Standard
191       is the referee document. The original Standard can be  obtained  online
192       at http://www.opengroup.org/unix/online.html .
193
194       Any  typographical  or  formatting  errors that appear in this page are
195       most likely to have been introduced during the conversion of the source
196       files  to  man page format. To report such errors, see https://www.ker
197       nel.org/doc/man-pages/reporting_bugs.html .
198
199
200
201IEEE/The Open Group                  2017                           MKFIFO(3P)
Impressum