xref: /freebsd/lib/libc/gen/setmode.3 (revision 5e3934b15a2741b2de6b217e77dc9d798d740804)
1.\" Copyright (c) 1989, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd July 18, 2019
29.Dt SETMODE 3
30.Os
31.Sh NAME
32.Nm getmode ,
33.Nm setmode
34.Nd modify mode bits
35.Sh LIBRARY
36.Lb libc
37.Sh SYNOPSIS
38.In unistd.h
39.Ft mode_t
40.Fn getmode "const void *set" "mode_t mode"
41.Ft void *
42.Fn setmode "const char *mode_str"
43.Sh DESCRIPTION
44The
45.Fn getmode
46function
47returns a copy of the file permission bits
48.Fa mode
49as altered by the values pointed to by
50.Fa set .
51While only the mode bits are altered, other parts of the file mode
52may be examined.
53.Pp
54The
55.Fn setmode
56function
57takes an absolute (octal) or symbolic value, as described in
58.Xr chmod 1 ,
59as an argument
60and returns a pointer to mode values to be supplied to
61.Fn getmode .
62Because some of the symbolic values are relative to the file
63creation mask,
64.Fn setmode
65may call
66.Xr umask 2 .
67If this occurs, the file creation mask will be restored before
68.Fn setmode
69returns.
70If the calling program changes the value of its file creation mask
71after calling
72.Fn setmode ,
73.Fn setmode
74must be called again if
75.Fn getmode
76is to modify future file modes correctly.
77.Pp
78If the mode passed to
79.Fn setmode
80is invalid or if memory cannot be allocated for the return value,
81.Fn setmode
82returns
83.Dv NULL .
84.Pp
85The value returned from
86.Fn setmode
87is obtained from
88.Fn malloc
89and should be returned to the system with
90.Fn free
91when the program is done with it, generally after a call to
92.Fn getmode .
93.Sh ERRORS
94The
95.Fn setmode
96function
97may fail and set errno for any of the errors specified for the library
98routine
99.Xr malloc 3
100or
101.Xr strtol 3 .
102In addition,
103.Fn setmode
104will fail and set
105.Va errno
106to:
107.Bl -tag -width Er
108.It Bq Er EINVAL
109The
110.Fa mode
111argument does not represent a valid mode.
112.El
113.Sh SEE ALSO
114.Xr chmod 1 ,
115.Xr stat 2 ,
116.Xr umask 2 ,
117.Xr malloc 3
118.Sh HISTORY
119The
120.Fn getmode
121and
122.Fn setmode
123functions first appeared in
124.Bx 4.4 .
125.Sh BUGS
126The
127.Fn setmode
128function is not thread safe.
129Files created in other threads while
130.Fn setmode
131is being called may be created with a umask of 0.
132