]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it) |
2 | .\" | |
3 | .\" Permission is granted to make and distribute verbatim copies of this | |
4 | .\" manual provided the copyright notice and this permission notice are | |
5 | .\" preserved on all copies. | |
6 | .\" | |
7 | .\" Permission is granted to copy and distribute modified versions of this | |
8 | .\" manual under the conditions for verbatim copying, provided that the | |
9 | .\" entire resulting derived work is distributed under the terms of a | |
10 | .\" permission notice identical to this one. | |
11 | .\" | |
12 | .\" Since the Linux kernel and libraries are constantly changing, this | |
13 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
14 | .\" responsibility for errors or omissions, or for damages resulting from | |
15 | .\" the use of the information contained herein. The author(s) may not | |
16 | .\" have taken the same level of care in the production of this manual, | |
17 | .\" which is licensed free of charge, as they might when working | |
18 | .\" professionally. | |
19 | .\" | |
20 | .\" Formatted or processed versions of this manual, if unaccompanied by | |
21 | .\" the source, must acknowledge the copyright and authors of this work. | |
22 | .\" | |
305a0578 | 23 | .\" Modified 2001-11-28, by Michael Kerrisk, <mtk-manpages@gmx.net> |
fea681da MK |
24 | .\" Changed data type of proj_id; minor fixes |
25 | .\" aeb: further fixes; added notes. | |
26 | .\" | |
27 | .TH FTOK 3 2001-11-28 "Linux 2.4" "Linux Programmer's Manual" | |
28 | .SH NAME | |
29 | ftok \- convert a pathname and a project identifier to a System V IPC key | |
30 | .SH SYNOPSIS | |
31 | .nf | |
32 | .B | |
33 | # include <sys/types.h> | |
34 | .B | |
35 | # include <sys/ipc.h> | |
36 | .fi | |
37 | .sp | |
38 | .BI "key_t ftok(const char *" pathname ", int " proj_id ); | |
39 | .SH DESCRIPTION | |
40 | The | |
41 | .B ftok | |
42 | function uses the identity of the file named by the given | |
43 | .I pathname | |
44 | (which must refer to an existing, accessible file) | |
45 | and the least significant 8 bits of | |
46 | .I proj_id | |
f59a3f19 | 47 | (which must be non-zero) to generate a |
fea681da MK |
48 | .B key_t |
49 | type System V IPC key, suitable for use with | |
50 | .BR msgget (2), | |
51 | .BR semget (2), | |
52 | or | |
53 | .BR shmget (2). | |
54 | .LP | |
55 | The resulting value is the same for all pathnames that | |
56 | name the same file, when the same value of | |
57 | .I proj_id | |
58 | is used. The value returned should be different when the | |
59 | (simultaneously existing) files or the project IDs differ. | |
60 | .SH "RETURN VALUE" | |
61 | On success the generated | |
62 | .B key_t | |
63 | value is returned. On failure \-1 is returned, with | |
64 | .I errno | |
65 | indicating the error as for the | |
66 | .BR stat (2) | |
67 | system call. | |
68 | .SH "CONFORMING TO" | |
69 | XPG4 | |
70 | .SH NOTES | |
71 | Under libc4 and libc5 (and under SunOS 4.x) the prototype was | |
72 | .RS | |
73 | .BI "key_t ftok(char *" pathname ", char " proj_id ); | |
74 | .RE | |
75 | Today | |
76 | .I proj_id | |
77 | is an | |
78 | .BR int , | |
79 | but still only 8 bits are used. Typical usage has an ASCII character | |
80 | .IR proj_id , | |
81 | that is why the behaviour is said to be undefined when | |
82 | .I proj_id | |
83 | is zero. | |
84 | .LP | |
85 | Of course no guarantee can be given that the resulting | |
86 | .B key_t | |
87 | is unique. Typically, a best effort attempt combines the given | |
88 | .I proj_id | |
89 | byte, the lower 16 bits of the i\-node number, and the | |
90 | lower 8 bits of the device number into a 32\-bit result. | |
91 | Collisions may easily happen, for example between files on | |
92 | .I /dev/hda1 | |
93 | and files on | |
94 | .IR /dev/sda1 . | |
95 | .SH "SEE ALSO" | |
96 | .BR msgget (2), | |
97 | .BR semget (2), | |
98 | .BR shmget (2), | |
99 | .BR stat (2), | |
100 | .BR ipc (5) |