Reference

getlocalbase(3)

return the path to the local software base directory

NAME

getlocalbase – return the path to the local software base directory

LIBRARY

System Utilities Library (libutil, -lutil)

SYNOPSIS

#include <libutil.h>

const char *

getlocalbase(void);

DESCRIPTION

The getlocalbase function returns the path to the local software base directory, normally /usr/local.

First the LOCALBASE environment variable is checked. If that variable is undefined or empty, the user.localbase sysctl is checked. If that returns an empty string or an error occurs, the value of _PATH_LOCALBASE is used as a last resort.

If the value obtained through these means is not a valid absolute path shorter than MAXPATHLEN, a constant string which has been deliberately chosen to cause any file system operation using it to fail is returned instead.

The contents of the string returned by getlocalbase shall not be modified by the caller.

IMPLEMENTATION NOTES

The LOCALBASE environment variable will only be used if the process calling getlocalbase is not setugid.

Successive calls to getlocalbase will return the same value throughout the lifetime of the process, regardless of any subsequent changes to the environment or sysctl variables.

The getlocalbase function is thread-safe if and only if it has been called at least once already.

RETURN VALUES

The getlocalbase() function returns a pointer to a null-terminated string.

ENVIRONMENT

LOCALBASE

Path to the local software base directory

SEE ALSO

environ(7), sysctl(8)

HISTORY

The getlocalbase function first appeared in FreeBSD 13.0.

AUTHORS

The getlocalbase function was originally written by Stefan Eßer ⟨[email protected]⟩ and was later reimplemented by Dag-Erling Smørgrav ⟨[email protected]⟩. This manual page was originally written by Scott Long ⟨[email protected]⟩ and Stefan Eßer ⟨[email protected]⟩ and was later substantially rewritten by Dag-Erling Smørgrav ⟨[email protected]⟩.

History