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()



Return Value



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.

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



Error Messages

The following messages may be sent from this function:


Usage Notes

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

    • Where multiple threads exist in the job.
    • The object on which this function is operating resides in a file system that is not threadsafe. Only the following file systems are threadsafe for this function:

      • "Root" (/)
      • QOpenSys
      • User-defined
      • QNTC
      • QSYS.LIB
      • Independent ASP QSYS.LIB
      • QOPT
      • QFileSvr.400

  2. The following file systems support mkfifo():
    • "Root" (/)
    • QOpenSys
    • User-defined

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

    • Opening a FIFO for reading or reading and writing is not allowed.
    • Any conversion between CCSIDs that are not strictly single-byte must be done by an open instance that has write-only access.

  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

The following example creates a new FIFO.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#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

[ Back to top | UNIX-Type APIs | APIs by category ]