ftok() — Generate an interprocess communication (IPC) key
|Standards / Extensions||C or C++||Dependencies|
Single UNIX Specification, Version 3
#define _XOPEN_SOURCE_EXTENDED 1 #include <sys/ipc.h> key_t ftok(const char *path, int id);
ftok() function returns a key based on path and
id that is usable in subsequent calls to
shmget(). The path
argument must be the path name of an existing file that the process is able to
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
ftok()function does not guarantee unique key generation. The key is created by combining the given id byte, the lower 16 bits of the inode number, and the lower 8 bits of the device number into a 32-bit result. The occurrence of key duplication is very rare.
ftok() returns a key.
ftok()returns -1 and sets
errnoto one of the following values:
- Error Code
- Search permission is denied for a component of the path prefix.
- The low-order 8-bits of id are zero.
- Too many symbolic links were encountered in resolving path.
- 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.
- A component of path does not name an existing file or path is an empty string.
- A component of the path prefix is not a directory.