ftok() — Generate an interprocess communication (IPC) key

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

#define _XOPEN_SOURCE_EXTENDED 1
#include <sys/ipc.h>

key_t ftok(const char *path, int id);

General description

The ftok() function returns a key based on path and id that is usable in subsequent calls to msgget(), semget(), and shmget(). The path argument must be the path name of an existing file that the process is able to stat().

The ftok() function returns the same key value for all paths that name the same file, when called with the same id value. If a different id value is given, or a different file is given, a different key is returned. Only the low-order 8-bits of id are significant, and must be nonzero.

Returned value

If successful, ftok() returns a key.

If unsuccessful, ftok() returns -1 and sets errno to one of the following values:
Error Code
Description
EACCES
Search permission is denied for a component of the path prefix.
EINVAL
The low-order 8-bits of id are zero.
ELOOP
Too many symbolic links were encountered in resolving path.
ENAMETOOLONG
One of the following error conditions exists:
  • The length of the path argument exceeds PATH_MAX or a path name component is longer than NAME_MAX.
  • The path name resolution of a symbolic link produced an intermediate result whose length exceeds PATH_MAX.
ENOENT
A component of path does not name an existing file or path is an empty string.
ENOTDIR
A component of the path prefix is not a directory.

Related information