mkfifo()--Make FIFO Special File


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

 int mkfifo(const char *path, mode_t mode);    
  Service Program Name: QP0LLIB1

  Default Public Authority: *USE

  Threadsafe: Conditional; see Usage Notes.

The mkfifo() function creates a new FIFO special file (FIFO) whose name is defined by path. A FIFO special file is a type of file with the property that data written to the file is read on a first-in-first-out basis. See the open(), read(), write(), lseek, and close functions for more characteristics of a FIFO special file.

A FIFO may be opened for reading only or writing only for a uni-directional I/O. It also may be opened for reading and writing access to provide a bi-directional FIFO descriptor.

The file permission bits in mode are modified by the file creation mask of the job and then used to set the file permission bits of the FIFO being created.

For more information on the permission bits in mode, see chmod()--Change File Authorizations. For more information on the file creation mask, see umask()--Set Authorization Mask for Job.

The owner ID of the new FIFO is set to the effective user ID (UID) of the thread. If the object is being created in the "root" (/), QOpenSys, and user-defined file systems, the following applies. If the S_ISGID bit of the parent directory is off, the group ID (GID) is set to the effective GID of the thread creating the object. If the S_ISGID bit of the parent directory is on, the group ID (GID) of the new object is set to the GID of the parent directory. For all other file systems, the group ID (GID) of the new FIFO is set to the GID of the parent directory.

Upon successful completion, mkfifo() sets the access, change, modification, and creation times for the new FIFO. It also sets the change and modification times for the directory that contains the new FIFO (parent directory).

If path contains a symbolic link, the symbolic link is followed.

If path names a symbolic link, the symbolic link is not followed, and mkfifo() fails with the [EEXIST] error.

If bits in mode other than the file permission bits are set, mkfifo() fails with the [EINVAL] error.


Parameters

path
(Input) A pointer to the null-terminated path name of the FIFO special file to be created.

This parameter is assumed to be represented in the CCSID (coded character set identifier) currently in effect for the job. If the CCSID of the job is 65535, this parameter is assumed to be represented in the default CCSID of the job.

The name of the new FIFO is assumed to be represented in the language and country or region currently in effect for the process.

See QlgMkfifo()--Make FIFO Special File (using NLS-enabled path name) for a description and an example of supplying the path in any CCSID.

mode
(Input) Permission bits for the new FIFO.

Authorities

Adopted authority is not used.

Authorization Required for mkfifo()

Object Referred to Authority
Required
errno
Each directory in the path name preceding the FIFO to be created. *X EACCES
Parent directory of FIFO to be created *WX EACCES


Return Value

0 mkfifo() was successful. The FIFO was created.
-1 mkfifo() was not successful. The FIFO was not created. The errno global variable is set to indicate the error.


Error Conditions

If mkfifo() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.

Error condition Additional information
[EACCES]

If you are accessing a remote file through the Network File System, update operations to file permissions at the server are not reflected at the client until updates to data that is stored locally by the Network File System take place. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.) Access to a remote file also may fail due to different mappings of user IDs (UID) or group IDs (GID) on the local and remote systems.

[EAGAIN]  
[EBADFID]  
[EBADNAME]  
[EBUSY]  
[ECONVERT]  
[EDAMAGE]  
[EEXIST]  
[EFAULT]  
[EFILECVT]  
[EINTR]  
[EINVAL]  
[EIO]  
[ELOOP]  
[EMLINK]  
[ENAMETOOLONG]  
[ENOENT]  
[ENOMEM]  
[ENOSPC]  
[ENOSYS]  
[ENOTAVAIL]  
[ENOTDIR]  
[ENOTSAFE]  
[ENOTSUP]  
[EPERM]  
[EROFS]  
[EROOBJ]  
[ESTALE]

If you are accessing a remote file through the Network File System, the file may have been deleted at the server.

[EUNKNOWN]  

If interaction with a file server is required to access the object, errno could indicate one of the following errors:

Error condition Additional information
[EADDRNOTAVAIL]  
[ECONNABORTED]  
[ECONNREFUSED]  
[ECONNRESET]  
[EHOSTDOWN]  
[EHOSTUNREACH]  
[ENETDOWN]  
[ENETRESET]  
[ENETUNREACH]  
[ESTALE]

If you are accessing a remote file through the Network File System, the file may have been deleted at the server.

[ETIMEDOUT]  
[EUNATCH]  


Error Messages

The following messages may be sent from this function:

Message ID Error Message Text
CPE3418 E Possible APAR condition or hardware failure.
CPFA0D4 E File system error occurred. Error number &1.
CPF3CF2 E Error(s) occurred during running of &1 API.
CPF9872 E Program or service program &1 in library &2 ended. Reason code &3.

Usage Notes

  1. This function will fail with error code [ENOTSAFE] when all the following conditions are true:


  2. The following file systems support mkfifo():


  3. There are some restrictions when opening a FIFO for text conversion and the CCSIDs involved are not strictly single-byte:


  4. The owner, primary group, and public object authorities (*OBJEXIST, *OBJMGT, *OBJALTER, and *OBJREF) are copied from the parent directory's owner, primary group, and public object authorities. This occurs even when the new FIFO has a different owner than the parent directory. The owner, primary group, and public data authorities (*R, *W, and *X) are derived from the permissions specified in the mode (except for those permissions that are also set in the file mode creation mask). The new FIFO does not have any private authorities or authorization list. It only has authorities for the owner, primary group, and public.

Related Information


Example

See Code disclaimer information for information pertaining to code examples.

The following example creates a new FIFO:

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

void main() {
  char *mypath = "/newFIFO";

  if (mkfifo(mypath, S_IRWXU|S_IRWXO) != 0)
    perror("mkfifo() error");
  else
    puts("success!");

  return;
}

API introduced: V5R1
Top | UNIX-Type APIs | APIs by category