---
name: "getlocalbase"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/getlocalbase"
---

# 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)](/environ/7.md), [sysctl(8)](/sysctl/8.md)

## HISTORY

The **getlocalbase** function first appeared in FreeBSD 13.0.

## AUTHORS

The **getlocalbase** function was originally written by Stefan Eßer ⟨*se@FreeBSD.org*⟩ and was later reimplemented by Dag-Erling Smørgrav ⟨*des@FreeBSD.org*⟩. This manual page was originally written by Scott Long ⟨*scottl@FreeBSD.org*⟩ and Stefan Eßer ⟨*se@FreeBSD.org*⟩ and was later substantially rewritten by Dag-Erling Smørgrav ⟨*des@FreeBSD.org*⟩.
