ftok.c revision 1.3
11.3Scgd/* $NetBSD: ftok.c,v 1.3 1995/02/27 03:43:18 cgd 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.2Sjtc#if defined(LIBC_SCCS) && !defined(lint) 311.3Scgdstatic char *rcsid = "$NetBSD: ftok.c,v 1.3 1995/02/27 03:43:18 cgd Exp $"; 321.2Sjtc#endif /* LIBC_SCCS and not lint */ 331.1Sjtc 341.1Sjtc#include <sys/types.h> 351.1Sjtc#include <sys/stat.h> 361.1Sjtc#include <sys/ipc.h> 371.1Sjtc 381.1Sjtckey_t 391.1Sjtcftok(path, id) 401.1Sjtc const char *path; 411.1Sjtc char id; 421.1Sjtc{ 431.1Sjtc struct stat st; 441.1Sjtc 451.1Sjtc if (stat(path, &st) < 0) 461.1Sjtc return (key_t)-1; 471.1Sjtc 481.3Scgd return (key_t) 491.3Scgd (id << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff)); 501.1Sjtc} 51