xref: /freebsd/lib/libc/gen/ftok.3 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
185c30cfaSJoerg Wunsch.\" Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
285c30cfaSJoerg Wunsch.\" All rights reserved.
385c30cfaSJoerg Wunsch.\"
485c30cfaSJoerg Wunsch.\" Redistribution and use in source and binary forms, with or without
585c30cfaSJoerg Wunsch.\" modification, are permitted provided that the following conditions
685c30cfaSJoerg Wunsch.\" are met:
785c30cfaSJoerg Wunsch.\" 1. Redistributions of source code must retain the above copyright
885c30cfaSJoerg Wunsch.\"    notice, this list of conditions and the following disclaimer.
985c30cfaSJoerg Wunsch.\" 2. Redistributions in binary form must reproduce the above copyright
1085c30cfaSJoerg Wunsch.\"    notice, this list of conditions and the following disclaimer in the
1185c30cfaSJoerg Wunsch.\"    documentation and/or other materials provided with the distribution.
1285c30cfaSJoerg Wunsch.\" 3. The name of the author may not be used to endorse or promote products
1385c30cfaSJoerg Wunsch.\"    derived from this software without specific prior written permission.
1485c30cfaSJoerg Wunsch.\"
1585c30cfaSJoerg Wunsch.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1685c30cfaSJoerg Wunsch.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1785c30cfaSJoerg Wunsch.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1885c30cfaSJoerg Wunsch.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1985c30cfaSJoerg Wunsch.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2085c30cfaSJoerg Wunsch.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2185c30cfaSJoerg Wunsch.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2285c30cfaSJoerg Wunsch.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2385c30cfaSJoerg Wunsch.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2485c30cfaSJoerg Wunsch.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*a6d40b0aSGuilherme Janczak.Dd November 28, 2022
2674804d58SMike Pritchard.Dt FTOK 3
27aa12cea2SUlrich Spörlein.Os
2885c30cfaSJoerg Wunsch.Sh NAME
2985c30cfaSJoerg Wunsch.Nm ftok
30e2cc67efSMike Pritchard.Nd create IPC identifier from path name
3125bb73e0SAlexey Zelkin.Sh LIBRARY
3225bb73e0SAlexey Zelkin.Lb libc
3385c30cfaSJoerg Wunsch.Sh SYNOPSIS
3432eef9aeSRuslan Ermilov.In sys/ipc.h
3585c30cfaSJoerg Wunsch.Ft key_t
361d235314SBruce Evans.Fn ftok "const char *path" "int id"
3785c30cfaSJoerg Wunsch.Sh DESCRIPTION
3885c30cfaSJoerg WunschThe
3985c30cfaSJoerg Wunsch.Fn ftok
4085c30cfaSJoerg Wunschfunction attempts to create a unique key suitable for use with the
41e64e7115SEdward Tomasz Napierala.Xr msgget 2 ,
4285c30cfaSJoerg Wunsch.Xr semget 2
4385c30cfaSJoerg Wunschand
4485c30cfaSJoerg Wunsch.Xr shmget 2
4585c30cfaSJoerg Wunschfunctions given the
4685c30cfaSJoerg Wunsch.Fa path
4785c30cfaSJoerg Wunschof an existing file and a user-selectable
4885c30cfaSJoerg Wunsch.Fa id .
4985c30cfaSJoerg Wunsch.Pp
5085c30cfaSJoerg WunschThe specified
5185c30cfaSJoerg Wunsch.Fa path
5285c30cfaSJoerg Wunschmust specify an existing file that is accessible to the calling process
531a0a9345SRuslan Ermilovor the call will fail.
541a0a9345SRuslan ErmilovAlso, note that links to files will return the
5585c30cfaSJoerg Wunschsame key, given the same
5685c30cfaSJoerg Wunsch.Fa id .
5785c30cfaSJoerg Wunsch.Sh RETURN VALUES
5885c30cfaSJoerg WunschThe
5985c30cfaSJoerg Wunsch.Fn ftok
6085c30cfaSJoerg Wunschfunction will return -1 if
6185c30cfaSJoerg Wunsch.Fa path
6285c30cfaSJoerg Wunschdoes not exist or if it cannot be accessed by the calling process.
6385c30cfaSJoerg Wunsch.Sh SEE ALSO
640aee91e1SChristian Brueffer.Xr msgget 2 ,
6585c30cfaSJoerg Wunsch.Xr semget 2 ,
660aee91e1SChristian Brueffer.Xr shmget 2
6785c30cfaSJoerg Wunsch.Sh HISTORY
6885c30cfaSJoerg WunschThe
6985c30cfaSJoerg Wunsch.Fn ftok
70d6c9f122SJoerg Wunschfunction originates with System V and is typically used by programs
7185c30cfaSJoerg Wunschthat use the System V IPC routines.
72a5941fc2SPhilippe Charnier.Sh AUTHORS
738fbf3d50SBaptiste Daroussin.An Thorsten Lockert Aq Mt tholo@sigmasoft.com
7485c30cfaSJoerg Wunsch.Sh BUGS
75d6c9f122SJoerg WunschThe returned key is computed based on the device minor number and inode of the
7685c30cfaSJoerg Wunschspecified
7785c30cfaSJoerg Wunsch.Fa path
78d6c9f122SJoerg Wunschin combination with the lower 8 bits of the given
7985c30cfaSJoerg Wunsch.Fa id .
80e83201b4SWolfram SchneiderThus it is quite possible for the routine to return duplicate keys.
81