1.\" 2.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3.\" 4.\" Copyright 2020 Scott Long 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.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25.\" SUCH DAMAGE. 26.\" 27.\" $FreeBSD$ 28.\" 29.Dd Oct 28, 2020 30.Dt GETLOCALBASE 3 31.Os 32.Sh NAME 33.Nm getlocalbase 34.Nd "return the path to the local software directory" 35.Sh LIBRARY 36.Lb libutil 37.Sh SYNOPSIS 38.In libutil.h 39.Ft ssize_t 40.Fn getlocalbase "char *path" "size_t len" 41.Sh DESCRIPTION 42The 43.Fn getlocalbase 44function returns the path to the local software base directory. 45Normally this is the 46.Pa /usr/local 47directory. 48First the 49.Ev LOCALBASE 50environment variable is checked. 51If that doesn't exist then the 52.Va user.localbase 53sysctl is checked. 54If that also doesn't exist then the value of the 55.Dv _PATH_LOCALBASE 56compile-time variable is used. 57If that is undefined then the default of 58.Pa /usr/local 59is used. 60.Pp 61The 62.Fa path 63argument points to a caller-supplied buffer to hold the resulting pathname. 64The 65.Fa len 66argument is the length of the caller-supplied buffer. 67.Sh IMPLEMENTATION NOTES 68Calls to 69.Fn getlocalpath 70will perform a setugid check on the running binary before checking the 71environment. 72.Sh RETURN VALUES 73If the request completes without error, the size of the string copied into the 74buffer, including the terminating NUL, is returned. 75If an error occurred or the buffer was too small to hold the string, 76.Fn getlocalbase 77returns -1 and sets 78.Em errno 79to indicate the error condition. 80.Sh ENVIRONMENT 81The 82.Fn getlocalbase 83library function retrieves the 84.Ev LOCALBASE 85environment variable. 86.Sh ERRORS 87The 88.Fn getlocalbase 89function will fail and set 90.Va errno 91for the following conditions: 92.Bl -tag -width Er 93.It Bq Er EINVAL 94One of the passed in parameters is NULL or zero. 95.It Bq Er ENOMEM 96There isn't enough space in the passed in buffer to hold the pathname string. 97.El 98.Sh SEE ALSO 99.Xr env 1 , 100.Xr src.conf 5 , 101.Xr sysctl 8 102.Sh HISTORY 103The 104.Nm 105library function first appeared in 106.Fx 13.0 . 107.Sh AUTHORS 108This 109manual page was written by 110.An Scott Long Aq Mt scottl@FreeBSD.org . 111