xref: /minix3/lib/libc/gen/ftok.3 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\"	$NetBSD: ftok.3,v 1.18 2014/03/18 18:20:37 riastradh Exp $
22fe8fb19SBen Gras.\"
32fe8fb19SBen Gras.\" Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
42fe8fb19SBen Gras.\" All rights reserved.
52fe8fb19SBen Gras.\"
62fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
72fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
82fe8fb19SBen Gras.\" are met:
92fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
102fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
112fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
122fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
132fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
142fe8fb19SBen Gras.\"
152fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
162fe8fb19SBen Gras.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
172fe8fb19SBen Gras.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
182fe8fb19SBen Gras.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
192fe8fb19SBen Gras.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
202fe8fb19SBen Gras.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
212fe8fb19SBen Gras.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
222fe8fb19SBen Gras.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
232fe8fb19SBen Gras.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
242fe8fb19SBen Gras.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
252fe8fb19SBen Gras.\"
262fe8fb19SBen Gras.Dd April 27, 2010
272fe8fb19SBen Gras.Dt FTOK 3
282fe8fb19SBen Gras.Os
292fe8fb19SBen Gras.Sh NAME
302fe8fb19SBen Gras.Nm ftok
312fe8fb19SBen Gras.Nd create IPC identifier from path name
322fe8fb19SBen Gras.Sh LIBRARY
332fe8fb19SBen Gras.Lb libc
342fe8fb19SBen Gras.Sh SYNOPSIS
352fe8fb19SBen Gras.In sys/types.h
362fe8fb19SBen Gras.In sys/ipc.h
372fe8fb19SBen Gras.Ft key_t
382fe8fb19SBen Gras.Fn ftok "const char *path" "int id"
392fe8fb19SBen Gras.Sh DESCRIPTION
402fe8fb19SBen GrasThe
412fe8fb19SBen Gras.Fn ftok
422fe8fb19SBen Grasfunction attempts to create a unique key suitable for use with the
432fe8fb19SBen Gras.Xr msgget 2 ,
442fe8fb19SBen Gras.Xr semget 2
452fe8fb19SBen Grasand
462fe8fb19SBen Gras.Xr shmget 2
472fe8fb19SBen Grasfunctions given the
482fe8fb19SBen Gras.Fa path
492fe8fb19SBen Grasof an existing file and a user-selectable
502fe8fb19SBen Gras.Fa id .
512fe8fb19SBen Gras.Pp
522fe8fb19SBen GrasThe specified
532fe8fb19SBen Gras.Fa path
542fe8fb19SBen Grasmust specify an existing file that is accessible to the calling process
552fe8fb19SBen Grasor the call will fail.
562fe8fb19SBen GrasAlso, note that links to files will return the same key, given the same
572fe8fb19SBen Gras.Fa id .
582fe8fb19SBen Gras.Pp
592fe8fb19SBen GrasOnly the 8 least significant bits of
602fe8fb19SBen Gras.Fa id
612fe8fb19SBen Grasare used in the key generation; the rest of the bits are ignored.
622fe8fb19SBen Gras.Sh RETURN VALUES
632fe8fb19SBen GrasThe
642fe8fb19SBen Gras.Fn ftok
652fe8fb19SBen Grasfunction will return ((key_t)-1) if
662fe8fb19SBen Gras.Fa path
672fe8fb19SBen Grasdoes not exist or if it cannot be accessed by the calling process.
682fe8fb19SBen Gras.Sh SEE ALSO
692fe8fb19SBen Gras.Xr msgget 2 ,
702fe8fb19SBen Gras.Xr semget 2 ,
712fe8fb19SBen Gras.Xr shmget 2
722fe8fb19SBen Gras.Sh STANDARDS
732fe8fb19SBen GrasThe
742fe8fb19SBen Gras.Fn ftok
752fe8fb19SBen Grasfunction conforms to
762fe8fb19SBen Gras.St -p1003.1 .
772fe8fb19SBen Gras.Sh HISTORY
782fe8fb19SBen GrasThe
792fe8fb19SBen Gras.Fn ftok
802fe8fb19SBen Grasfunction originated with System V and is typically used by programs
812fe8fb19SBen Grasthat use the System V IPC routines.
822fe8fb19SBen Gras.Sh AUTHORS
8384d9c625SLionel Sambuc.An Thorsten Lockert Aq Mt tholo@sigmasoft.com
842fe8fb19SBen Gras.Sh BUGS
852fe8fb19SBen GrasThe returned key is computed based on the device and inode of the
862fe8fb19SBen Grasspecified
872fe8fb19SBen Gras.Fa path
882fe8fb19SBen Grasin combination with the given
892fe8fb19SBen Gras.Fa id .
902fe8fb19SBen GrasThus it is quite possible for the routine to return duplicate keys
912fe8fb19SBen Grasgiven that those fields are not 8- and 16-bit quantities like they
922fe8fb19SBen Graswere on System V based systems where this library routine's ancestor
932fe8fb19SBen Graswere originally created.
94