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

# trimdomain(3)

trim the current domain name from a host name

## NAME

**trimdomain** – trim the current domain name from a host name

## LIBRARY

System Utilities Library (libutil, -lutil)

## SYNOPSIS

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

**#include \<libutil.h\>**

*void*\

**trimdomain**(*char \*fullhost*, *size\_t hostsize*);

## DESCRIPTION

The function **trimdomain**() removes the current domain name from the passed *fullhost* name by writing a NUL character over the first period of the passed name. The current domain name is determined by calling [gethostname(3)](/gethostname/3.md) and removing everything up to the first period. The name is determined the first time this function is called and is cached for future use.

The **trimdomain**() function will only trim the domain name if the passed *fullhost* ends with the current domain name and if the length of the resulting host name does not exceed *hostsize*.

If the passed *fullhost* is actually an X11 DISPLAY specification of the form *host*.*domain*:*display*\[.screen\], and the domain name is the same as the local domain name, **trimdomain**() will remove the embedded domain name, copying the screen and display numbers to the end of the base host name and resulting in *host*:*display*\[.*screen*\].

## RETURN VALUES

The **trimdomain**() function does not return a value.

## SEE ALSO

[gethostname(3)](/gethostname/3.md)

## HISTORY

The function **trimdomain**() first appeared in FreeBSD 3.2.
