getmode.c revision 1.5
11.5Ssimonb/* $NetBSD: getmode.c,v 1.5 2004/01/12 02:23:37 simonb Exp $ */ 21.1Stv 31.1Stv/*- 41.1Stv * Copyright (c) 2001 The NetBSD Foundation, Inc. 51.1Stv * All rights reserved. 61.1Stv * 71.1Stv * This code is derived from software contributed to The NetBSD Foundation 81.1Stv * by Todd Vierling. 91.1Stv * 101.1Stv * Redistribution and use in source and binary forms, with or without 111.1Stv * modification, are permitted provided that the following conditions 121.1Stv * are met: 131.1Stv * 1. Redistributions of source code must retain the above copyright 141.1Stv * notice, this list of conditions and the following disclaimer. 151.1Stv * 2. Redistributions in binary form must reproduce the above copyright 161.1Stv * notice, this list of conditions and the following disclaimer in the 171.1Stv * documentation and/or other materials provided with the distribution. 181.1Stv * 3. All advertising materials mentioning features or use of this software 191.1Stv * must display the following acknowledgement: 201.1Stv * This product includes software developed by the NetBSD 211.1Stv * Foundation, Inc. and its contributors. 221.1Stv * 4. Neither the name of The NetBSD Foundation nor the names of its 231.1Stv * contributors may be used to endorse or promote products derived 241.1Stv * from this software without specific prior written permission. 251.1Stv * 261.1Stv * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.1Stv * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.1Stv * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.1Stv * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.1Stv * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.1Stv * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.1Stv * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.1Stv * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.1Stv * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.1Stv * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.1Stv * POSSIBILITY OF SUCH DAMAGE. 371.1Stv */ 381.1Stv 391.3Slukem#include "nbtool_config.h" 401.1Stv#include <stdlib.h> 411.1Stv 421.4Ssimonbvoid * 431.4Ssimonbsetmode(const char *str) 441.4Ssimonb{ 451.1Stv mode_t *mp = malloc(sizeof(mode_t)); 461.1Stv 471.1Stv *mp = strtoul(str, NULL, 8); 481.1Stv 491.1Stv return mp; 501.1Stv} 511.1Stv 521.4Ssimonbmode_t 531.4Ssimonbgetmode(const void *mp, mode_t mode) 541.4Ssimonb{ 551.5Ssimonb mode_t m; 561.4Ssimonb 571.5Ssimonb m = *((const mode_t *)mp); 581.5Ssimonb 591.5Ssimonb mode &= ~ALLPERMS; /* input mode less RWX permissions */ 601.5Ssimonb m &= ALLPERMS; /* new RWX permissions */ 611.5Ssimonb 621.5Ssimonb return m | mode; 631.1Stv} 64