gtpc2m3g | C/C++ Language Support User's Guide |
This function returns a key (token) based on the specified path name and
integer. The key can be used in subsequent calls to the
shmget function.
Format
#include <sys/ipc.h>
key_t ftok(const char *path,
int id);
- path
- The path name of an existing file.
- id
- A nonzero integer that is used to generate the key that is returned by
this function. Only the low-order 8 bits are used to generate the
key.
Normal Return
If successful, the ftok function returns a key that is specified
as the key parameter in subsequent calls to the shmget
function.
Error Return
If unsuccessful, the ftok function returns a value of -1
and sets errno to one of the following:
- EACCES
- Search permission is denied for a path name component.
- EINVAL
- The low-order 8 bits of the id parameter are zero.
- ELOOP
- Too many symbolic links were found when resolving the path
parameter.
- ENAMETOOLONG
- The length of the path parameter exceeds PATH_MAX, a path name
component is longer than NAME_MAX, or when resolving the path name of a
symbolic link, the length of an intermediate result exceeds PATH_MAX.
PATH_MAX and NAME_MAX are defined in the limits.h header
file.
- ENOENT
- A path name component does not name an existing file or the
path parameter is an empty string.
- ENOTDIR
- A path name component is not a directory.
Programming Considerations
- The ftok function returns the same key value for all paths that
name the same file when called with the same value specified for the
id parameter. If a different value is specified for the
id parameter or a different file is specified, a different key
value is returned.
- Only the low-order 8 bits of the id parameter are
significant.
Examples
The following example generates a key.
#include <sys/ipc.h>
int main()
{
key_t key;
key = ftok("/usr/testfile",3);
}
Related Information