mkfifoat()

Updated: April 19, 2023

Create a FIFO special file at a given location

Synopsis:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int mkfifoat( int fd,
              const char* path, 
              mode_t mode );

Arguments:

fd
A file descriptor that indicates the base directory for relative file paths. The pathname given in path is resolved by appending it to the directory associated with fd. You can set this argument to AT_FDCWD to use the current working directory as the base directory.
Note: You must use a file descriptor obtained from an open() call with the O_DIRECTORY flag set. Otherwise, the function fails and sets errno to ENOTDIR.

If path specifies an absolute path, fd has no effect.

path
The pathname that you want to use for the FIFO special file.
mode
The file permission bits for the new FIFO. For more information, see the entry for struct stat.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The mkfifoat() function creates a new FIFO special file named by the pathname pointed to by path. The path argument can contain an absolute or relative path. In the latter case, the fd argument is used to resolve the pathname, as explained in this argument's description (above).

If the access mode of the open file description associated with the fd file descriptor is not O_SEARCH, the function checks if directory searches are permitted using the current permissions of the directory underlying the file descriptor. If the access mode is O_SEARCH, the function doesn't perform the check.

QNX Neutrino has no concept of a path operation (open(), readlink(), etc.) that references a path relative to an already open file descriptor (for a directory), as far as the filesystem resource manager is concerned. Therefore, it's not possible to eliminate the race inherent in looking up a pathname with multiple intervening directories or symbolic links. However, mkfifoat() can still be used for maintaining a per-thread current working directory, using file descriptors maintained by the application.

The file permission bits of the new FIFO are initialized from mode, modified by the process's creation mask (see umask()). Bits that are set in mode other than the file permission bits are ignored.

The FIFO owner ID is set to the process's effective user ID and the FIFO's group ID is set to the process's effective group ID.

If mkfifoat() succeeds, several fields of the file and the directory that contains the new entry are marked for update. For information about which fields are affected, see the mkfifo() reference.

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

EACCES
Search permission is denied on a component of the path prefix of path, write permission is denied on the parent directory of path, or the access mode of the fd file descriptor is not O_SEARCH and the underlying directory doesn't permit directory searches.
EBADF
The path argument does not specify an absolute path and the fd argument is neither AT_FDCWD nor a valid file descriptor open for reading or searching.
EEXIST
The named file already exists.
ELOOP
During resolution of the path argument, a loop was found in the symbolic links or more than SYMLOOP_MAX symbolic links were encountered.
ENAMETOOLONG
The length of the path string exceeds PATH_MAX, the resolution of a symbolic link within path produced a result longer than PATH_MAX, or a pathname component is longer than NAME_MAX.
ENOENT
A component of the path prefix doesn't exist, or the path argument points to an empty string.
ENOSPC
The directory that would contain the new file cannot be extended, or the filesystem is out of file allocation resources (i.e., the disk is full).
ENOTDIR
One of the following is true:
  • A component of the path prefix names an existing file that is neither a directory nor a symbolic link to one.
  • The path argument contains at least one non-slash character and ends with at least one slash character (/).
  • The path argument isn't an absolute path and the fd file descriptor is associated with a non-directory file.
  • The file descriptor in fd was created without O_DIRECTORY set.
EROFS
The named file resides on a read-only filesystem.

Classification:

POSIX 2008

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes