186d7f5d3SJohn Marino /*
286d7f5d3SJohn Marino * Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
386d7f5d3SJohn Marino * All rights reserved.
486d7f5d3SJohn Marino *
586d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without
686d7f5d3SJohn Marino * modification, are permitted provided that the following conditions
786d7f5d3SJohn Marino * are met:
886d7f5d3SJohn Marino * 1. Redistributions of source code must retain the above copyright
986d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer.
1086d7f5d3SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright
1186d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer in the
1286d7f5d3SJohn Marino * documentation and/or other materials provided with the distribution.
1386d7f5d3SJohn Marino * 3. The name of the author may not be used to endorse or promote products
1486d7f5d3SJohn Marino * derived from this software without specific prior written permission.
1586d7f5d3SJohn Marino *
1686d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1786d7f5d3SJohn Marino * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1886d7f5d3SJohn Marino * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1986d7f5d3SJohn Marino * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2086d7f5d3SJohn Marino * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
2186d7f5d3SJohn Marino * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2286d7f5d3SJohn Marino * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2386d7f5d3SJohn Marino * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2486d7f5d3SJohn Marino * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2586d7f5d3SJohn Marino * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2686d7f5d3SJohn Marino *
2786d7f5d3SJohn Marino * $FreeBSD: src/lib/libc/gen/ftok.c,v 1.5 1999/08/27 23:58:35 peter Exp $
2886d7f5d3SJohn Marino * $DragonFly: src/lib/libc/gen/ftok.c,v 1.3 2005/11/13 00:07:42 swildner Exp $
2986d7f5d3SJohn Marino */
3086d7f5d3SJohn Marino
3186d7f5d3SJohn Marino #include <sys/types.h>
3286d7f5d3SJohn Marino #include <sys/stat.h>
3386d7f5d3SJohn Marino #include <sys/ipc.h>
3486d7f5d3SJohn Marino
3586d7f5d3SJohn Marino key_t
ftok(const char * path,int id)3686d7f5d3SJohn Marino ftok(const char *path, int id)
3786d7f5d3SJohn Marino {
3886d7f5d3SJohn Marino struct stat st;
3986d7f5d3SJohn Marino
4086d7f5d3SJohn Marino if (stat(path, &st) < 0)
4186d7f5d3SJohn Marino return (key_t)-1;
4286d7f5d3SJohn Marino
4386d7f5d3SJohn Marino return (key_t) (id << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff));
4486d7f5d3SJohn Marino }
45