1*86d7f5d3SJohn Marino /*
2*86d7f5d3SJohn Marino * Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
3*86d7f5d3SJohn Marino * All rights reserved.
4*86d7f5d3SJohn Marino *
5*86d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without
6*86d7f5d3SJohn Marino * modification, are permitted provided that the following conditions
7*86d7f5d3SJohn Marino * are met:
8*86d7f5d3SJohn Marino * 1. Redistributions of source code must retain the above copyright
9*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer.
10*86d7f5d3SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright
11*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer in the
12*86d7f5d3SJohn Marino * documentation and/or other materials provided with the distribution.
13*86d7f5d3SJohn Marino * 3. The name of the author may not be used to endorse or promote products
14*86d7f5d3SJohn Marino * derived from this software without specific prior written permission.
15*86d7f5d3SJohn Marino *
16*86d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17*86d7f5d3SJohn Marino * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18*86d7f5d3SJohn Marino * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19*86d7f5d3SJohn Marino * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20*86d7f5d3SJohn Marino * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21*86d7f5d3SJohn Marino * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22*86d7f5d3SJohn Marino * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23*86d7f5d3SJohn Marino * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24*86d7f5d3SJohn Marino * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25*86d7f5d3SJohn Marino * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*86d7f5d3SJohn Marino *
27*86d7f5d3SJohn Marino * $FreeBSD: src/lib/libc/gen/ftok.c,v 1.5 1999/08/27 23:58:35 peter Exp $
28*86d7f5d3SJohn Marino * $DragonFly: src/lib/libc/gen/ftok.c,v 1.3 2005/11/13 00:07:42 swildner Exp $
29*86d7f5d3SJohn Marino */
30*86d7f5d3SJohn Marino
31*86d7f5d3SJohn Marino #include <sys/types.h>
32*86d7f5d3SJohn Marino #include <sys/stat.h>
33*86d7f5d3SJohn Marino #include <sys/ipc.h>
34*86d7f5d3SJohn Marino
35*86d7f5d3SJohn Marino key_t
ftok(const char * path,int id)36*86d7f5d3SJohn Marino ftok(const char *path, int id)
37*86d7f5d3SJohn Marino {
38*86d7f5d3SJohn Marino struct stat st;
39*86d7f5d3SJohn Marino
40*86d7f5d3SJohn Marino if (stat(path, &st) < 0)
41*86d7f5d3SJohn Marino return (key_t)-1;
42*86d7f5d3SJohn Marino
43*86d7f5d3SJohn Marino return (key_t) (id << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff));
44*86d7f5d3SJohn Marino }
45