xref: /openbsd-src/lib/libc/gen/setmode.3 (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1.\"	$OpenBSD: setmode.3,v 1.8 2000/12/24 00:30:51 aaron Exp $
2.\"
3.\" Copyright (c) 1989, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd June 9, 1993
35.Dt SETMODE 3
36.Os
37.Sh NAME
38.Nm getmode ,
39.Nm setmode
40.Nd modify mode bits
41.Sh SYNOPSIS
42.Fd #include <unistd.h>
43.Ft mode_t
44.Fn getmode "const void *set" "mode_t mode"
45.Ft void *
46.Fn setmode "const char *mode_str"
47.Sh DESCRIPTION
48The
49.Fn getmode
50function returns a copy of the file permission bits
51.Fa mode
52as altered by the values pointed to by
53.Fa set .
54While only the mode bits are altered, other parts of the file mode
55may be examined.
56.Pp
57The
58.Fn setmode
59function takes an absolute (octal) or symbolic value, as described in
60.Xr chmod 1 ,
61as an argument
62and returns a pointer to mode values to be supplied to
63.Fn getmode .
64Because some of the symbolic values are relative to the file
65creation mask,
66.Fn setmode
67may call
68.Xr umask 2 .
69If this occurs, the file creation mask will be restored before
70.Fn setmode
71returns.
72If the calling program changes the value of its file creation mask
73after calling
74.Fn setmode ,
75.Fn setmode
76must be called again if
77.Fn getmode
78is to modify future file modes correctly.
79.Pp
80If the mode passed to
81.Fn setmode
82is invalid,
83.Fn setmode
84returns
85.Dv NULL .
86The caller is responsible for freeing the pointer that
87.Fn setmode
88returns.
89.Sh ERRORS
90The
91.Fn setmode
92function may fail and set
93.Va errno
94for any of the errors specified for the library routine
95.Xr malloc 3 .
96.Sh SEE ALSO
97.Xr chmod 1 ,
98.Xr stat 2 ,
99.Xr umask 2 ,
100.Xr malloc 3
101.Sh HISTORY
102The
103.Fn getmode
104and
105.Fn setmode
106functions first appeared in
107.Bx 4.4 .
108