1b364683ea65e24070c77f1673a8c155665eb894eElliott Hughes/*	$OpenBSD: ftok.c,v 1.8 2014/11/15 22:38:47 guenther Exp $ */
20133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes/*
30133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
40133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * All rights reserved.
50133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes *
60133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * Redistribution and use in source and binary forms, with or without
70133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * modification, are permitted provided that the following conditions
80133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * are met:
90133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * 1. Redistributions of source code must retain the above copyright
100133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes *    notice, this list of conditions and the following disclaimer.
110133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * 2. Redistributions in binary form must reproduce the above copyright
120133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes *    notice, this list of conditions and the following disclaimer in the
130133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes *    documentation and/or other materials provided with the distribution.
140133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * 3. The name of the author may not be used to endorse or promote products
150133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes *    derived from this software without specific prior written permission.
160133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes *
170133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
180133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
190133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
200133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
210133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
220133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
230133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
240133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
250133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
260133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
270133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes */
280133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes
290133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes#include <sys/stat.h>
300133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes#include <sys/ipc.h>
310133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes
320133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hugheskey_t
330133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughesftok(const char *path, int id)
340133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes{
350133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes	struct stat st;
360133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes
370133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes	if (stat(path, &st) < 0)
380133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes		return (key_t)-1;
390133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes
400133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes	return (key_t)
410133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes	    ((id & 0xff) << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff));
420133944b09d1c0a35041f7a41eb6bfb660144f4fElliott Hughes}
43