OSDN Git Service

2e2e9d4c4b91895429fe81230f62fe4b7d0c93f7
[linuxjm/LDP_man-pages.git] / original / man3 / ftok.3
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 .\"
23 .\" Modified 2001-11-28, by Michael Kerrisk, <mtk.manpages@gmail.com>
24 .\"     Changed data type of proj_id; minor fixes
25 .\"     aeb: further fixes; added notes.
26 .\"
27 .TH FTOK 3 2001-11-28 "GNU" "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 #include <sys/types.h>
33 .B #include <sys/ipc.h>
34 .fi
35 .sp
36 .BI "key_t ftok(const char *" pathname ", int " proj_id );
37 .SH DESCRIPTION
38 The
39 .BR ftok ()
40 function uses the identity of the file named by the given
41 .I pathname
42 (which must refer to an existing, accessible file)
43 and the least significant 8 bits of
44 .I proj_id
45 (which must be nonzero) to generate a
46 .I key_t
47 type System V IPC key, suitable for use with
48 .BR msgget (2),
49 .BR semget (2),
50 or
51 .BR shmget (2).
52 .LP
53 The resulting value is the same for all pathnames that
54 name the same file, when the same value of
55 .I proj_id
56 is used.
57 The value returned should be different when the
58 (simultaneously existing) files or the project IDs differ.
59 .SH "RETURN VALUE"
60 On success, the generated
61 .I key_t
62 value is returned.
63 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 POSIX.1-2001.
70 .SH NOTES
71 Under libc4 and libc5 (and under SunOS 4.x) the prototype was:
72 .sp
73 .RS
74 .BI "key_t ftok(char *" pathname ", char " proj_id );
75 .RE
76 .PP
77 Today
78 .I proj_id
79 is an
80 .IR int ,
81 but still only 8 bits are used.
82 Typical usage has an ASCII character
83 .IR proj_id ,
84 that is why the behavior is said to be undefined when
85 .I proj_id
86 is zero.
87 .LP
88 Of course no guarantee can be given that the resulting
89 .I key_t
90 is unique.
91 Typically, a best effort attempt combines the given
92 .I proj_id
93 byte, the lower 16 bits of the inode number, and the
94 lower 8 bits of the device number into a 32-bit result.
95 Collisions may easily happen, for example between files on
96 .I /dev/hda1
97 and files on
98 .IR /dev/sda1 .
99 .SH "SEE ALSO"
100 .BR msgget (2),
101 .BR semget (2),
102 .BR shmget (2),
103 .BR stat (2),
104 .BR svipc (7)