1*c8a0e2f4SThomas Veerman /* $NetBSD: getmode.c,v 1.8 2008/11/04 23:31:32 dbj Exp $ */
2*c8a0e2f4SThomas Veerman
3*c8a0e2f4SThomas Veerman /*-
4*c8a0e2f4SThomas Veerman * Copyright (c) 2001 The NetBSD Foundation, Inc.
5*c8a0e2f4SThomas Veerman * All rights reserved.
6*c8a0e2f4SThomas Veerman *
7*c8a0e2f4SThomas Veerman * This code is derived from software contributed to The NetBSD Foundation
8*c8a0e2f4SThomas Veerman * by Todd Vierling.
9*c8a0e2f4SThomas Veerman *
10*c8a0e2f4SThomas Veerman * Redistribution and use in source and binary forms, with or without
11*c8a0e2f4SThomas Veerman * modification, are permitted provided that the following conditions
12*c8a0e2f4SThomas Veerman * are met:
13*c8a0e2f4SThomas Veerman * 1. Redistributions of source code must retain the above copyright
14*c8a0e2f4SThomas Veerman * notice, this list of conditions and the following disclaimer.
15*c8a0e2f4SThomas Veerman * 2. Redistributions in binary form must reproduce the above copyright
16*c8a0e2f4SThomas Veerman * notice, this list of conditions and the following disclaimer in the
17*c8a0e2f4SThomas Veerman * documentation and/or other materials provided with the distribution.
18*c8a0e2f4SThomas Veerman *
19*c8a0e2f4SThomas Veerman * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*c8a0e2f4SThomas Veerman * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*c8a0e2f4SThomas Veerman * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*c8a0e2f4SThomas Veerman * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*c8a0e2f4SThomas Veerman * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*c8a0e2f4SThomas Veerman * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*c8a0e2f4SThomas Veerman * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*c8a0e2f4SThomas Veerman * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*c8a0e2f4SThomas Veerman * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*c8a0e2f4SThomas Veerman * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*c8a0e2f4SThomas Veerman * POSSIBILITY OF SUCH DAMAGE.
30*c8a0e2f4SThomas Veerman */
31*c8a0e2f4SThomas Veerman
32*c8a0e2f4SThomas Veerman #include "nbtool_config.h"
33*c8a0e2f4SThomas Veerman #include <stdlib.h>
34*c8a0e2f4SThomas Veerman #include <unistd.h>
35*c8a0e2f4SThomas Veerman
36*c8a0e2f4SThomas Veerman void *
setmode(const char * str)37*c8a0e2f4SThomas Veerman setmode(const char *str)
38*c8a0e2f4SThomas Veerman {
39*c8a0e2f4SThomas Veerman mode_t *mp = malloc(sizeof(mode_t));
40*c8a0e2f4SThomas Veerman
41*c8a0e2f4SThomas Veerman *mp = strtoul(str, NULL, 8);
42*c8a0e2f4SThomas Veerman
43*c8a0e2f4SThomas Veerman return mp;
44*c8a0e2f4SThomas Veerman }
45*c8a0e2f4SThomas Veerman
46*c8a0e2f4SThomas Veerman mode_t
getmode(const void * mp,mode_t mode)47*c8a0e2f4SThomas Veerman getmode(const void *mp, mode_t mode)
48*c8a0e2f4SThomas Veerman {
49*c8a0e2f4SThomas Veerman mode_t m;
50*c8a0e2f4SThomas Veerman
51*c8a0e2f4SThomas Veerman m = *((const mode_t *)mp);
52*c8a0e2f4SThomas Veerman
53*c8a0e2f4SThomas Veerman mode &= ~ALLPERMS; /* input mode less RWX permissions */
54*c8a0e2f4SThomas Veerman m &= ALLPERMS; /* new RWX permissions */
55*c8a0e2f4SThomas Veerman
56*c8a0e2f4SThomas Veerman return m | mode;
57*c8a0e2f4SThomas Veerman }
58