---
name: "mac_from_text"
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_from_text"
---

# mac\_from\_text(3)

convert MAC label to/from text representation

## NAME

**mac\_from\_text**, **mac\_to\_text** – convert MAC label to/from text representation

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

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

*int*\

**mac\_from\_text**(*mac\_t \*mac*, *const char \*text*);

*int*\

**mac\_to\_text**(*mac\_t label*, *char \*\*text*);

## DESCRIPTION

The **mac\_from\_text**() function converts the text representation of a label into the internal policy label format (*mac\_t*) and places it in *\*mac*, which must later be freed with [mac\_free(3)](/mac_free/3.md).

The **mac\_to\_text**() function allocates storage for *\*text*, which will be set to the text representation of *label* and must later be freed with [free(3)](/free/3.md).

Refer to [maclabel(7)](/maclabel/7.md) for the MAC label format.

## RETURN VALUES

The **mac\_from\_text()** and **mac\_to\_text()** functions return the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error.

## COMPATIBILITY

POSIX.1e does not define a format for text representations of MAC labels.

POSIX.1e requires that text strings allocated using **mac\_to\_text**() be freed using [mac\_free(3)](/mac_free/3.md); in the FreeBSD implementation, they must be freed using [free(3)](/free/3.md), as [mac\_free(3)](/mac_free/3.md) is used only to free memory used for type *mac\_t*.

## ERRORS

- \[ENOMEM\]

  Insufficient memory was available to allocate internal storage.

## SEE ALSO

[free(3)](/free/3.md), [mac(3)](/mac/3.md), [mac\_get(3)](/mac_get/3.md), [mac\_is\_present(3)](/mac_is_present/3.md), [mac\_prepare(3)](/mac_prepare/3.md), [mac\_set(3)](/mac_set/3.md), [posix1e(3)](/posix1e/3.md), [mac(4)](/mac/4.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.
