1*9e00aa94Sdbj /* $NetBSD: getmode.c,v 1.8 2008/11/04 23:31:32 dbj Exp $ */
29d5d28c2Stv
39d5d28c2Stv /*-
49d5d28c2Stv * Copyright (c) 2001 The NetBSD Foundation, Inc.
59d5d28c2Stv * All rights reserved.
69d5d28c2Stv *
79d5d28c2Stv * This code is derived from software contributed to The NetBSD Foundation
89d5d28c2Stv * by Todd Vierling.
99d5d28c2Stv *
109d5d28c2Stv * Redistribution and use in source and binary forms, with or without
119d5d28c2Stv * modification, are permitted provided that the following conditions
129d5d28c2Stv * are met:
139d5d28c2Stv * 1. Redistributions of source code must retain the above copyright
149d5d28c2Stv * notice, this list of conditions and the following disclaimer.
159d5d28c2Stv * 2. Redistributions in binary form must reproduce the above copyright
169d5d28c2Stv * notice, this list of conditions and the following disclaimer in the
179d5d28c2Stv * documentation and/or other materials provided with the distribution.
189d5d28c2Stv *
199d5d28c2Stv * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
209d5d28c2Stv * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
219d5d28c2Stv * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
229d5d28c2Stv * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
239d5d28c2Stv * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
249d5d28c2Stv * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
259d5d28c2Stv * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
269d5d28c2Stv * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
279d5d28c2Stv * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
289d5d28c2Stv * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
299d5d28c2Stv * POSSIBILITY OF SUCH DAMAGE.
309d5d28c2Stv */
319d5d28c2Stv
32171d6532Slukem #include "nbtool_config.h"
339d5d28c2Stv #include <stdlib.h>
34*9e00aa94Sdbj #include <unistd.h>
359d5d28c2Stv
36a5c6a6feSsimonb void *
setmode(const char * str)37a5c6a6feSsimonb setmode(const char *str)
38a5c6a6feSsimonb {
399d5d28c2Stv mode_t *mp = malloc(sizeof(mode_t));
409d5d28c2Stv
419d5d28c2Stv *mp = strtoul(str, NULL, 8);
429d5d28c2Stv
439d5d28c2Stv return mp;
449d5d28c2Stv }
459d5d28c2Stv
46a5c6a6feSsimonb mode_t
getmode(const void * mp,mode_t mode)47a5c6a6feSsimonb getmode(const void *mp, mode_t mode)
48a5c6a6feSsimonb {
49c7fb3080Ssimonb mode_t m;
50a5c6a6feSsimonb
51c7fb3080Ssimonb m = *((const mode_t *)mp);
52c7fb3080Ssimonb
53c7fb3080Ssimonb mode &= ~ALLPERMS; /* input mode less RWX permissions */
54c7fb3080Ssimonb m &= ALLPERMS; /* new RWX permissions */
55c7fb3080Ssimonb
56c7fb3080Ssimonb return m | mode;
579d5d28c2Stv }
58