ftok.c revision 1.4
11.4Schristos/*	$NetBSD: ftok.c,v 1.4 1997/07/13 19:45:53 christos Exp $	*/
21.3Scgd
31.1Sjtc/*
41.1Sjtc * Copyright (c) 1994 SigmaSoft, Th. Lockert <tholo@sigmasoft.com>
51.1Sjtc * All rights reserved.
61.1Sjtc *
71.1Sjtc * Redistribution and use in source and binary forms, with or without
81.1Sjtc * modification, are permitted provided that the following conditions
91.1Sjtc * are met:
101.1Sjtc * 1. Redistributions of source code must retain the above copyright
111.1Sjtc *    notice, this list of conditions and the following disclaimer.
121.1Sjtc * 2. Redistributions in binary form must reproduce the above copyright
131.1Sjtc *    notice, this list of conditions and the following disclaimer in the
141.1Sjtc *    documentation and/or other materials provided with the distribution.
151.1Sjtc * 3. The name of the author may not be used to endorse or promote products
161.1Sjtc *    derived from this software without specific prior written permission.
171.1Sjtc *
181.1Sjtc * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
191.1Sjtc * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
201.1Sjtc * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
211.1Sjtc * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
221.1Sjtc * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
231.1Sjtc * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
241.1Sjtc * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
251.1Sjtc * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
261.1Sjtc * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
271.1Sjtc * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
281.1Sjtc */
291.2Sjtc
301.4Schristos#include <sys/cdefs.h>
311.2Sjtc#if defined(LIBC_SCCS) && !defined(lint)
321.4Schristos__RCSID("$NetBSD: ftok.c,v 1.4 1997/07/13 19:45:53 christos Exp $");
331.2Sjtc#endif /* LIBC_SCCS and not lint */
341.1Sjtc
351.1Sjtc#include <sys/types.h>
361.1Sjtc#include <sys/stat.h>
371.1Sjtc#include <sys/ipc.h>
381.1Sjtc
391.1Sjtckey_t
401.1Sjtcftok(path, id)
411.1Sjtc	const char *path;
421.1Sjtc	char id;
431.1Sjtc{
441.1Sjtc	struct stat st;
451.1Sjtc
461.1Sjtc	if (stat(path, &st) < 0)
471.1Sjtc		return (key_t)-1;
481.1Sjtc
491.3Scgd	return (key_t)
501.3Scgd	    (id << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff));
511.1Sjtc}
52