xref: /f-stack/tools/libutil/getlocalbase.3 (revision 22ce4aff)
1*22ce4affSfengbojiang.\"
2*22ce4affSfengbojiang.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*22ce4affSfengbojiang.\"
4*22ce4affSfengbojiang.\" Copyright 2020 Scott Long
5*22ce4affSfengbojiang.\" Copyright 2020 Stefan Eßer
6*22ce4affSfengbojiang.\"
7*22ce4affSfengbojiang.\" Redistribution and use in source and binary forms, with or without
8*22ce4affSfengbojiang.\" modification, are permitted provided that the following conditions
9*22ce4affSfengbojiang.\" are met:
10*22ce4affSfengbojiang.\" 1. Redistributions of source code must retain the above copyright
11*22ce4affSfengbojiang.\"    notice, this list of conditions and the following disclaimer.
12*22ce4affSfengbojiang.\" 2. Redistributions in binary form must reproduce the above copyright
13*22ce4affSfengbojiang.\"    notice, this list of conditions and the following disclaimer in the
14*22ce4affSfengbojiang.\"    documentation and/or other materials provided with the distribution.
15*22ce4affSfengbojiang.\"
16*22ce4affSfengbojiang.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*22ce4affSfengbojiang.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*22ce4affSfengbojiang.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*22ce4affSfengbojiang.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*22ce4affSfengbojiang.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*22ce4affSfengbojiang.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*22ce4affSfengbojiang.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*22ce4affSfengbojiang.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*22ce4affSfengbojiang.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*22ce4affSfengbojiang.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*22ce4affSfengbojiang.\" SUCH DAMAGE.
27*22ce4affSfengbojiang.\"
28*22ce4affSfengbojiang.\" $FreeBSD$
29*22ce4affSfengbojiang.\"
30*22ce4affSfengbojiang.Dd November 25, 2020
31*22ce4affSfengbojiang.Dt GETLOCALBASE 3
32*22ce4affSfengbojiang.Os
33*22ce4affSfengbojiang.Sh NAME
34*22ce4affSfengbojiang.Nm getlocalbase
35*22ce4affSfengbojiang.Nd "return the path to the local software directory"
36*22ce4affSfengbojiang.Sh LIBRARY
37*22ce4affSfengbojiang.Lb libutil
38*22ce4affSfengbojiang.Sh SYNOPSIS
39*22ce4affSfengbojiang.In libutil.h
40*22ce4affSfengbojiang.Ft const char*
41*22ce4affSfengbojiang.Fn getlocalbase "void"
42*22ce4affSfengbojiang.Sh DESCRIPTION
43*22ce4affSfengbojiangThe
44*22ce4affSfengbojiang.Fn getlocalbase
45*22ce4affSfengbojiangfunction returns the path to the local software base directory.
46*22ce4affSfengbojiangNormally this is the
47*22ce4affSfengbojiang.Pa /usr/local
48*22ce4affSfengbojiangdirectory.
49*22ce4affSfengbojiangFirst the
50*22ce4affSfengbojiang.Ev LOCALBASE
51*22ce4affSfengbojiangenvironment variable is checked.
52*22ce4affSfengbojiangIf that does not exist then the
53*22ce4affSfengbojiang.Va user.localbase
54*22ce4affSfengbojiangsysctl is checked.
55*22ce4affSfengbojiangIf that also does not exist then the value of the
56*22ce4affSfengbojiang.Dv _PATH_LOCALBASE
57*22ce4affSfengbojiangcompile-time variable is used.
58*22ce4affSfengbojiangIf that is undefined then the default of
59*22ce4affSfengbojiang.Pa /usr/local
60*22ce4affSfengbojiangis used.
61*22ce4affSfengbojiang.Pp
62*22ce4affSfengbojiangThe contents of the string returned by the
63*22ce4affSfengbojiang.Fn getlocalbase
64*22ce4affSfengbojiangfunction shall not be modified.
65*22ce4affSfengbojiang.Sh IMPLEMENTATION NOTES
66*22ce4affSfengbojiangCalls to
67*22ce4affSfengbojiang.Fn getlocalbase
68*22ce4affSfengbojiangwill perform a setugid check on the running binary before checking the
69*22ce4affSfengbojiangenvironment.
70*22ce4affSfengbojiang.Pp
71*22ce4affSfengbojiangThe address returned by
72*22ce4affSfengbojiang.Fn getlocalbase
73*22ce4affSfengbojiangwill point into the executing processes environment if it is the result of
74*22ce4affSfengbojiang.Fn getenv "LOCALBASE" ,
75*22ce4affSfengbojiangto a static buffer if it is the result of
76*22ce4affSfengbojiang.Fn sysctl "user.localbase" ,
77*22ce4affSfengbojiangand to a constant string if the compiled in default value is returned.
78*22ce4affSfengbojiang.Pp
79*22ce4affSfengbojiangThe same value will be returned on successive calls during the run-time
80*22ce4affSfengbojiangof the program, ignoring any changes to the environment variable or the
81*22ce4affSfengbojiangsysctl value that might have been made.
82*22ce4affSfengbojiang.Pp
83*22ce4affSfengbojiangThe
84*22ce4affSfengbojiang.Fn getlocalbase
85*22ce4affSfengbojiangfunction can be compiled with a non-default value of LOCALBASE_CTL_LEN.
86*22ce4affSfengbojiangA value of 0 will disable fetching of the sysctl value, a value less than
87*22ce4affSfengbojiangMAXPATHLEN will put a limit on the maximum string length supported for
88*22ce4affSfengbojiangthis sysctl value.
89*22ce4affSfengbojiangIf built with a non-default value of LOCALBASE_CTL_LEN, a value of the
90*22ce4affSfengbojianguser.localbase sysctl variable longer than this value will make
91*22ce4affSfengbojiang.Fn getlocalbase
92*22ce4affSfengbojiangreturn a valid string that is not a valid path prefix in any filesystem.
93*22ce4affSfengbojiang.Sh RETURN VALUES
94*22ce4affSfengbojiangThe
95*22ce4affSfengbojiang.Fn getlocalbase
96*22ce4affSfengbojiangfunction returns a pointer to a string, whose length may exceed MAXPATHLEN,
97*22ce4affSfengbojiangif it has been obtained from the environment.
98*22ce4affSfengbojiang.Sh ENVIRONMENT
99*22ce4affSfengbojiangThe
100*22ce4affSfengbojiang.Fn getlocalbase
101*22ce4affSfengbojianglibrary function retrieves the
102*22ce4affSfengbojiang.Ev LOCALBASE
103*22ce4affSfengbojiangenvironment variable.
104*22ce4affSfengbojiang.Sh ERRORS
105*22ce4affSfengbojiangThe
106*22ce4affSfengbojiang.Fn getlocalbase
107*22ce4affSfengbojiangfunction always succeeds and returns a valid pointer to a string.
108*22ce4affSfengbojiang.Sh SEE ALSO
109*22ce4affSfengbojiang.Xr env 1 ,
110*22ce4affSfengbojiang.Xr src.conf 5 ,
111*22ce4affSfengbojiang.Xr sysctl 8
112*22ce4affSfengbojiang.Sh HISTORY
113*22ce4affSfengbojiangThe
114*22ce4affSfengbojiang.Nm
115*22ce4affSfengbojianglibrary function first appeared in
116*22ce4affSfengbojiang.Fx 13.0 .
117*22ce4affSfengbojiang.Sh AUTHORS
118*22ce4affSfengbojiangThis
119*22ce4affSfengbojiangmanual page was written by
120*22ce4affSfengbojiang.An Scott Long Aq Mt [email protected] and Stefan Eßer Aq Mt [email protected] .
121