]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libutil/getlocalbase.3
rtld-elf: link udivmoddi4 from compiler_rt
[FreeBSD/FreeBSD.git] / lib / libutil / getlocalbase.3
1 .\"
2 .\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 .\"
4 .\" Copyright 2020 Scott Long
5 .\" Copyright 2020 Stefan Eßer
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 .\" $FreeBSD$
29 .\"
30 .Dd November 25, 2020
31 .Dt GETLOCALBASE 3
32 .Os
33 .Sh NAME
34 .Nm getlocalbase
35 .Nd "return the path to the local software directory"
36 .Sh LIBRARY
37 .Lb libutil
38 .Sh SYNOPSIS
39 .In libutil.h
40 .Ft const char*
41 .Fn getlocalbase "void"
42 .Sh DESCRIPTION
43 The
44 .Fn getlocalbase
45 function returns the path to the local software base directory.
46 Normally this is the
47 .Pa /usr/local
48 directory.
49 First the
50 .Ev LOCALBASE
51 environment variable is checked.
52 If that does not exist then the
53 .Va user.localbase
54 sysctl is checked.
55 If that also does not exist then the value of the
56 .Dv _PATH_LOCALBASE
57 compile-time variable is used.
58 If that is undefined then the default of
59 .Pa /usr/local
60 is used.
61 .Pp
62 The contents of the string returned by the
63 .Fn getlocalbase
64 function shall not be modified.
65 .Sh IMPLEMENTATION NOTES
66 Calls to
67 .Fn getlocalbase
68 will perform a setugid check on the running binary before checking the
69 environment.
70 .Pp
71 The address returned by
72 .Fn getlocalbase
73 will point into the executing processes environment if it is the result of
74 .Fn getenv "LOCALBASE" ,
75 to a static buffer if it is the result of
76 .Fn sysctl "user.localbase" ,
77 and to a constant string if the compiled in default value is returned.
78 .Pp
79 The same value will be returned on successive calls during the run-time
80 of the program, ignoring any changes to the environment variable or the
81 sysctl value that might have been made.
82 .Pp
83 The
84 .Fn getlocalbase
85 function can be compiled with a non-default value of LOCALBASE_CTL_LEN.
86 A value of 0 will disable fetching of the sysctl value, a value less than
87 MAXPATHLEN will put a limit on the maximum string length supported for
88 this sysctl value.
89 If built with a non-default value of LOCALBASE_CTL_LEN, a value of the
90 user.localbase sysctl variable longer than this value will make
91 .Fn getlocalbase
92 return a valid string that is not a valid path prefix in any filesystem.
93 .Sh RETURN VALUES
94 The
95 .Fn getlocalbase
96 function returns a pointer to a string, whose length may exceed MAXPATHLEN,
97 if it has been obtained from the environment.
98 .Sh ENVIRONMENT
99 The
100 .Fn getlocalbase
101 library function retrieves the
102 .Ev LOCALBASE
103 environment variable.
104 .Sh ERRORS
105 The
106 .Fn getlocalbase
107 function always succeeds and returns a valid pointer to a string.
108 .Sh SEE ALSO
109 .Xr env 1 ,
110 .Xr src.conf 5 ,
111 .Xr sysctl 8
112 .Sh HISTORY
113 The
114 .Nm
115 library function first appeared in
116 .Fx 13.0 .
117 .Sh AUTHORS
118 This
119 manual page was written by
120 .An Scott Long Aq Mt scottl@FreeBSD.org and Stefan Eßer Aq Mt se@FreeBSD.org .