ftok.c revision 1.6
11.6Schristos/*	$NetBSD: ftok.c,v 1.6 1998/11/12 16:15:17 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.6Schristos__RCSID("$NetBSD: ftok.c,v 1.6 1998/11/12 16:15:17 christos Exp $");
331.2Sjtc#endif /* LIBC_SCCS and not lint */
341.1Sjtc
351.5Sjtc#include "namespace.h"
361.1Sjtc#include <sys/types.h>
371.1Sjtc#include <sys/stat.h>
381.1Sjtc#include <sys/ipc.h>
391.5Sjtc
401.5Sjtc#ifdef __weak_alias
411.5Sjtc__weak_alias(ftok,_ftok);
421.5Sjtc#endif
431.1Sjtc
441.1Sjtckey_t
451.1Sjtcftok(path, id)
461.1Sjtc	const char *path;
471.6Schristos	int id;
481.1Sjtc{
491.1Sjtc	struct stat st;
501.1Sjtc
511.1Sjtc	if (stat(path, &st) < 0)
521.1Sjtc		return (key_t)-1;
531.1Sjtc
541.3Scgd	return (key_t)
551.3Scgd	    (id << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff));
561.1Sjtc}
57