11.12Skamil/* $NetBSD: ftok.c,v 1.12 2018/07/26 00:05:28 kamil 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 * 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.4Schristos#include <sys/cdefs.h> 291.2Sjtc#if defined(LIBC_SCCS) && !defined(lint) 301.12Skamil__RCSID("$NetBSD: ftok.c,v 1.12 2018/07/26 00:05:28 kamil Exp $"); 311.2Sjtc#endif /* LIBC_SCCS and not lint */ 321.1Sjtc 331.5Sjtc#include "namespace.h" 341.1Sjtc#include <sys/types.h> 351.1Sjtc#include <sys/stat.h> 361.1Sjtc#include <sys/ipc.h> 371.5Sjtc 381.7Slukem#include <assert.h> 391.7Slukem#include <errno.h> 401.7Slukem 411.5Sjtc#ifdef __weak_alias 421.9Smycroft__weak_alias(ftok,_ftok) 431.5Sjtc#endif 441.1Sjtc 451.1Sjtckey_t 461.11Smattftok(const char *path, int id) 471.1Sjtc{ 481.1Sjtc struct stat st; 491.7Slukem 501.7Slukem _DIAGASSERT(path != NULL); 511.1Sjtc 521.1Sjtc if (stat(path, &st) < 0) 531.1Sjtc return (key_t)-1; 541.1Sjtc 551.3Scgd return (key_t) 561.12Skamil ((unsigned int)id << 24 | (st.st_dev & 0xff) << 16 | 571.12Skamil (st.st_ino & 0xffff)); 581.1Sjtc} 59