GETLOCALBASE(3)
π
GETLOCALBASE(3) β ok so this is the getlocalbase manual page, section 3, and honestly bestie it's a little cutie
πΈ NAME
getlocalbase β returns the path to the local software directory. That's it, that's the whole vibe β¨
π LIBRARY
System Utilities Library (libutil, -lutil) β yeah you gotta link it, no cap π«Ά
β¨ SYNOPSIS
#include <libutil.h>
const char*
getlocalbase(void);
π DESCRIPTION
okay so the getlocalbase() function returns the path to the local software base directory. Normally this is the /usr/local directory β like, the standard one, the default girlie π
But here's the tea, it does NOT just grab one thing, it checks stuff in order:
- First the
LOCALBASEenvironment variable is checked π - If that does not exist, then the
user.localbasesysctl is checked - If that also does not exist, then the value of the
LOCALBASE_PATHcompile-time variable is used - If that is undefined, then the system default,
_PATH_LOCALBASE, is used π―
β οΈ okay listen: the contents of the string returned by the getlocalbase() function shall not be modified. Do not touch. Not yours. Hands off π
π₯ IMPLEMENTATION NOTES
- Calls to
getlocalbase()will perform asetugidcheck on the running binary before checking the environment. Safety first, always π - The address returned by
getlocalbase()will point into:- the executing process's environment, if it's the result of
getenv(LOCALBASE) - a static buffer, if it's the result of
sysctl(user.localbase) - a constant string, if the compiled-in default value is returned
- the executing process's environment, if it's the result of
- The same value will be returned on successive calls during the run-time of the program β and yes, that's ignoring any changes to the environment variable or the sysctl value that might have been made. So don't come back later expecting a different answer, she's committed π
- The
getlocalbase()function can be compiled with a non-default value ofLOCALBASE_CTL_LEN:- A value of
0will disable fetching of the sysctl value - A value less than
MAXPATHLENwill put a limit on the maximum string length supported for this sysctl value
- A value of
π lowkey important: if built with a non-default value ofLOCALBASE_CTL_LEN, a value of theuser.localbasesysctl variable longer than this value will makegetlocalbase()return a valid string that is not a valid path prefix in any filesystem. Like, it's a real string, it's just not a usable path. Wild. Be aware fr fr.
β RETURN VALUES
The getlocalbase() function returns a pointer to a string, whose length may exceed MAXPATHLEN, if it has been obtained from the environment. Yeah, she can be long, we don't gatekeep π¦
π ENVIRONMENT
- The
getlocalbase()library function retrieves theLOCALBASEenvironment variable. That's her source of truth π
π ERRORS
The getlocalbase() function always succeeds and returns a valid pointer to a string. Iconic behavior honestly, zero drama, she just works periodt β¨
π SEE ALSO
π HISTORY
The getlocalbase library function first appeared in FreeBSD 13.0 π
π«Ά AUTHORS
This manual page was written by Scott Long <scottl@FreeBSD.org> and Stefan EΓer <se@FreeBSD.org> β ty besties for the docs π₯Ή
k that's the whole page!! π oh and the footer info: this one's from the Debian source/version, dated July 11, 2023 β so if you cite her, that's the receipt πβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- π the page's license: BSD-2-Clause
- Copyright 2020 Scott Long
- Copyright 2020 Stefan EΓer
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms