1FTOK(3P)                   POSIX Programmer's Manual                  FTOK(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       ftok — generate an IPC key
13

SYNOPSIS

15       #include <sys/ipc.h>
16
17       key_t ftok(const char *path, int id);
18

DESCRIPTION

20       The ftok() function shall return a key based on path  and  id  that  is
21       usable  in  subsequent  calls to msgget(), semget(), and shmget().  The
22       application shall ensure that the path argument is the pathname  of  an
23       existing  file  that  the process is able to stat(), with the exception
24       that if stat() would fail with [EOVERFLOW] due  to  file  size,  ftok()
25       shall still succeed.
26
27       The  ftok() function shall return the same key value for all paths that
28       name the same file, when called with the  same  id  value,  and  should
29       return  different  key  values  when called with different id values or
30       with paths that name different files existing on the same  file  system
31       at  the  same  time.  It is unspecified whether ftok() shall return the
32       same key value when called again  after  the  file  named  by  path  is
33       removed and recreated with the same name.
34
35       Only the low-order 8-bits of id are significant. The behavior of ftok()
36       is unspecified if these bits are 0.
37

RETURN VALUE

39       Upon successful completion,  ftok()  shall  return  a  key.  Otherwise,
40       ftok() shall return (key_t)-1 and set errno to indicate the error.
41

ERRORS

43       The ftok() function shall fail if:
44
45       EACCES Search permission is denied for a component of the path prefix.
46
47       EIO    An error occurred while reading from the file system.
48
49       ELOOP  A loop exists in symbolic links encountered during resolution of
50              the path argument.
51
52       ENAMETOOLONG
53              The  length  of  a  component  of  a  pathname  is  longer  than
54              {NAME_MAX}.
55
56       ENOENT A component of path does not name an existing file or path is an
57              empty string.
58
59       ENOTDIR
60              A component of the path prefix names an existing  file  that  is
61              neither  a  directory nor a symbolic link to a directory, or the
62              path argument contains at least one  non-<slash>  character  and
63              ends  with  one or more trailing <slash> characters and the last
64              pathname component names an existing  file  that  is  neither  a
65              directory nor a symbolic link to a directory.
66
67       The ftok() function may fail if:
68
69       ELOOP  More  than  {SYMLOOP_MAX} symbolic links were encountered during
70              resolution of the path argument.
71
72       ENAMETOOLONG
73              The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
74              tion  of  a symbolic link produced an intermediate result with a
75              length that exceeds {PATH_MAX}.
76
77       The following sections are informative.
78

EXAMPLES

80   Getting an IPC Key
81       The following example gets a key based on the pathname /tmp and the  ID
82       value  a.  It also assigns the value of the resulting key to the semkey
83       variable so that it will be available to  a  later  call  to  semget(),
84       msgget(), or shmget().
85
86
87           #include <sys/ipc.h>
88           ...
89           key_t semkey;
90
91           if ((semkey = ftok("/tmp", 'a')) == (key_t) -1) {
92               perror("IPC error: ftok"); exit(1);
93           }
94

APPLICATION USAGE

96       For maximum portability, id should be a single-byte character.
97
98       Applications should not assume that the resulting key value is unique.
99

RATIONALE

101       None.
102

FUTURE DIRECTIONS

104       Future  versions  of  this  standard  may add new interfaces to provide
105       unique keys.
106

SEE ALSO

108       msgget(), semget(), shmget()
109
110       The Base Definitions volume of POSIX.1‐2017, <sys_ipc.h>
111
113       Portions of this text are reprinted and reproduced in  electronic  form
114       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
115       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
116       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
117       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
118       event of any discrepancy between this version and the original IEEE and
119       The Open Group Standard, the original IEEE and The Open Group  Standard
120       is  the  referee document. The original Standard can be obtained online
121       at http://www.opengroup.org/unix/online.html .
122
123       Any typographical or formatting errors that appear  in  this  page  are
124       most likely to have been introduced during the conversion of the source
125       files to man page format. To report such errors,  see  https://www.ker
126       nel.org/doc/man-pages/reporting_bugs.html .
127
128
129
130IEEE/The Open Group                  2017                             FTOK(3P)
Impressum