---
name: "mac_prepare"
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/mac_prepare"
---

# mac\_prepare(3)

allocate appropriate storage for mac\_t

## NAME

**mac\_prepare**, **mac\_prepare\_type**, **mac\_prepare\_file\_label**, **mac\_prepare\_ifnet\_label**, **mac\_prepare\_process\_label** – allocate appropriate storage for *mac\_t*

## SYNOPSIS

**#include \<sys/mac.h\>**

*int*\

**mac\_prepare**(*mac\_t \*mac*, *const char \*elements*);

*int*\

**mac\_prepare\_type**(*mac\_t \*mac*, *const char \*name*);

*int*\

**mac\_prepare\_file\_label**(*mac\_t \*mac*);

*int*\

**mac\_prepare\_ifnet\_label**(*mac\_t \*mac*);

*int*\

**mac\_prepare\_process\_label**(*mac\_t \*mac*);

## DESCRIPTION

The **mac\_prepare** family of functions allocates the appropriate amount of storage and initializes *\*mac* for use by [mac\_get(3)](/mac_get/3.md). When the resulting label is passed into the [mac\_get(3)](/mac_get/3.md) functions, the kernel will attempt to fill in the label elements specified when the label was prepared. Elements are specified in a nul-terminated string, using commas to delimit fields. Element names may be prefixed with the ‘?’ character to indicate that a failure by the kernel to retrieve that element should not be considered fatal.

The **mac\_prepare**() function accepts a list of policy names as a parameter, and allocates the storage to fit those label elements accordingly. The remaining functions in the family make use of system defaults defined in [mac.conf(5)](/mac.conf/5.md) instead of an explicit *elements* argument, deriving the default from the specified object type.

**mac\_prepare\_type**() allocates the storage to fit an object label of the type specified by the *name* argument. The **mac\_prepare\_file\_label**(), **mac\_prepare\_ifnet\_label**(), and **mac\_prepare\_process\_label**() functions are equivalent to invocations of **mac\_prepare\_type**() with arguments of "file", "ifnet", and "process" respectively.

## RETURN VALUES

The **mac\_prepare()** function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

## SEE ALSO

[mac(3)](/mac/3.md), [mac\_free(3)](/mac_free/3.md), [mac\_get(3)](/mac_get/3.md), [mac\_is\_present(3)](/mac_is_present/3.md), [mac\_set(3)](/mac_set/3.md), [mac(4)](/mac/4.md), [mac.conf(5)](/mac.conf/5.md), [maclabel(7)](/maclabel/7.md)

## STANDARDS

POSIX.1e is described in IEEE POSIX.1e draft 17.

## HISTORY

Support for Mandatory Access Control was introduced in FreeBSD 5.0 as part of the TrustedBSD Project. Support for generic object types first appeared in FreeBSD 5.2.
