1FTOK(3P) POSIX Programmer's Manual FTOK(3P)
2
3
4
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
11
13 ftok — generate an IPC key
14
16 #include <sys/ipc.h>
17
18 key_t ftok(const char *path, int id);
19
21 The ftok() function shall return a key based on path and id that is
22 usable in subsequent calls to msgget(), semget(), and shmget(). The
23 application shall ensure that the path argument is the pathname of an
24 existing file that the process is able to stat(), with the exception
25 that if stat() would fail with [EOVERFLOW] due to file size, ftok()
26 shall still succeed.
27
28 The ftok() function shall return the same key value for all paths that
29 name the same file, when called with the same id value, and should
30 return different key values when called with different id values or
31 with paths that name different files existing on the same file system
32 at the same time. It is unspecified whether ftok() shall return the
33 same key value when called again after the file named by path is
34 removed and recreated with the same name.
35
36 Only the low-order 8-bits of id are significant. The behavior of ftok()
37 is unspecified if these bits are 0.
38
40 Upon successful completion, ftok() shall return a key. Otherwise,
41 ftok() shall return (key_t)−1 and set errno to indicate the error.
42
44 The ftok() function shall fail if:
45
46 EACCES Search permission is denied for a component of the path prefix.
47
48 EIO An error occurred while reading from the file system.
49
50 ELOOP A loop exists in symbolic links encountered during resolution of
51 the path argument.
52
53 ENAMETOOLONG
54 The length of a component of a pathname is longer than
55 {NAME_MAX}.
56
57 ENOENT A component of path does not name an existing file or path is an
58 empty string.
59
60 ENOTDIR
61 A component of the path prefix names an existing file that is
62 neither a directory nor a symbolic link to a directory, or the
63 path argument contains at least one non-<slash> character and
64 ends with one or more trailing <slash> characters and the last
65 pathname component names an existing file that is neither a
66 directory nor a symbolic link to a directory.
67
68 The ftok() function may fail if:
69
70 ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during
71 resolution of the path argument.
72
73 ENAMETOOLONG
74 The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
75 tion of a symbolic link produced an intermediate result with a
76 length that exceeds {PATH_MAX}.
77
78 The following sections are informative.
79
81 Getting an IPC Key
82 The following example gets a key based on the pathname /tmp and the ID
83 value a. It also assigns the value of the resulting key to the semkey
84 variable so that it will be available to a later call to semget(),
85 msgget(), or shmget().
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
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
101 None.
102
104 Future versions of this standard may add new interfaces to provide
105 unique keys.
106
108 msgget(), semget(), shmget()
109
110 The Base Definitions volume of POSIX.1‐2008, <sys_ipc.h>
111
113 Portions of this text are reprinted and reproduced in electronic form
114 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
115 -- Portable Operating System Interface (POSIX), The Open Group Base
116 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
117 cal and Electronics Engineers, Inc and The Open Group. (This is
118 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
119 event of any discrepancy between this version and the original IEEE and
120 The Open Group Standard, the original IEEE and The Open Group Standard
121 is the referee document. The original Standard can be obtained online
122 at http://www.unix.org/online.html .
123
124 Any typographical or formatting errors that appear in this page are
125 most likely to have been introduced during the conversion of the source
126 files to man page format. To report such errors, see https://www.ker‐
127 nel.org/doc/man-pages/reporting_bugs.html .
128
129
130
131IEEE/The Open Group 2013 FTOK(3P)