ftokのヘルプ・マニュアル
日本語 英語
ftok --help
man ftok
FTOK(3) Linux Programmer’s Manual FTOK(3)
名前
ftok - パス名とプロジェクト識別子を System V IPC キーに変換する
書式
#include
#include
key_t ftok(const char *pathname, int proj_id);
説明
ftok() 関数は pathname で与えられたファイル (存在し、アクセス可能でなけ
ればならない) のファイル名の識別情報 (identity) と、 proj_id (0 であ っ
て はならない) の低位 8 ビットとを用いて、 key_t 型の System V IPC キー
を生成する。このキーは msgget(2), semget(2), shmget(2) などでの利用に適
している。
同じファイルを示すあらゆるパス名と、同じ proj_id に対しては、結果の値は
等しくなる。ファイルが違ったり (この場合両者は同時に存在しているはず)、
proj_id が異なると、返り値も異なる。
返り値
成功した場合は生成された key_t の値が返される。失敗すると -1 が返され、
エラーの内容が errno に書き込まれる。この内容はシステムコー ル stat(2)
のものと同じである。
準拠
POSIX.1-2001.
注意
libc4 と libc5 (および SunOS 4.x) では、プロトタイプは以下のようになっ
ている。
key_t ftok(char *pathname, char proj_id);
現在では proj_id は int だが、依然として 8 ビットしか用いられない。通常
は ASCII キャラクタが proj_id に用いられる。 proj_id が 0 のときの振る
舞いが未定義になっているのは、これが理由である。
もちろん key_t が他と重ならないものであるかどうかは保証されない。最善の
場合の組み合わせを考えても、 proj_id の 1 バイト、i ノード番号の低位 16
ビット、およびデバイス番号の低位 8 ビットなので、結果は 32 ビットに過ぎ
な い。例えば /dev/hda1 と /dev/sda1 それぞれにあるファイルに対して、衝
突は容易に起こりうる。
関連項目
msgget(2), semget(2), shmget(2), stat(2), svipc(7)
Linux 2001-11-28 FTOK(3)
FTOK(3) Linux Programmer’s Manual FTOK(3)
NAME
ftok - convert a pathname and a project identifier to a System V IPC
key
SYNOPSIS
#include
#include
key_t ftok(const char *pathname, int proj_id);
DESCRIPTION
The ftok() function uses the identity of the file named by the given
pathname (which must refer to an existing, accessible file) and the
least significant 8 bits of proj_id (which must be non-zero) to gener-
ate a key_t type System V IPC key, suitable for use with msgget(2),
semget(2), or shmget(2).
The resulting value is the same for all pathnames that name the same
file, when the same value of proj_id is used. The value returned
should be different when the (simultaneously existing) files or the
project IDs differ.
RETURN VALUE
On success the generated key_t value is returned. On failure -1 is
returned, with errno indicating the error as for the stat(2) system
call.
CONFORMING TO
POSIX.1-2001.
NOTES
Under libc4 and libc5 (and under SunOS 4.x) the prototype was:
key_t ftok(char *pathname, char proj_id);
Today proj_id is an int, but still only 8 bits are used. Typical usage
has an ASCII character proj_id, that is why the behavior is said to be
undefined when proj_id is zero.
Of course no guarantee can be given that the resulting key_t is unique.
Typically, a best effort attempt combines the given proj_id byte, the
lower 16 bits of the inode number, and the lower 8 bits of the device
number into a 32-bit result. Collisions may easily happen, for example
between files on /dev/hda1 and files on /dev/sda1.
SEE ALSO
msgget(2), semget(2), shmget(2), stat(2), svipc(7)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU 2001-11-28 FTOK(3)