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