TRIMDOMAIN(3)

πŸ“¦
version 73 Β· 3 versions
, in nixpkgs unstable

🌸 TRIMDOMAIN(3) β€” trimdomain(3), the glow-up your hostname didn't know it needed πŸ’…

Okay so bestie, you know how your hostname is out here giving laptop.whatever.domain energy when you literally just need laptop? That's this function. It's trimdomain(3) from the <kbd>LOCAL</kbd> manual, and it is lowkey iconic. Let's get into it 🫢

✨ NAME ✨

trimdomain β€” trim the current domain name from a host name πŸŽ€

πŸ“š LIBRARY πŸ“š

System Utilities Library (libutil, -lutil) β€” yes, that's where she lives. Link her in, bestie ⭐

πŸ¦‹ SYNOPSIS πŸ¦‹

#include <sys/types.h>
#include <libutil.h>

void
trimdomain(char *fullhost, int hostsize);

Two includes, one function, zero return value. It's giving "all vibes, no receipts" and I respect it 😭

πŸ’– DESCRIPTION πŸ’–

So here's the tea β˜•: trimdomain() removes the current domain name from the fullhost name you pass in β€” and the way it does it is honestly so simple it ate: it writes a NUL character right over the first period of the passed name. Periodt. Literally over the period πŸ’€

Where does the "current domain name" come from? She calls gethostname(3) and then removes everything up to the first period. That's the domain. And the way this is determined β€” the first time this function is called, and then it's cached for future use. Cached! She remembered so you don't have to πŸ™ˆ

But she's not out here trimming just anything, okay? She's got standards ✨. trimdomain() will only trim the domain name if:

  • the passed fullname ends with the current domain name, and
  • the length of the resulting host name does not exceed hostsize.

No match? No room? She simply does not engage. Boundaries, queen πŸ‘‘

πŸ–₯️ the DISPLAY spec situation πŸ–₯️

Now this part is actually so clever it's giving main character energy. If the passed fullname is actually a DISPLAY specification of the form:

host.domain:nn[.nn]

…and the domain name is the same as the local domain name, then trimdomain() will remove the embedded domain name, copying the screen and display numbers to the end of the base host name, and the result is:

host:nn[.nn]

Like, she trims the domain and relocates the display numbers? The math is mathing. Slay πŸ’…πŸ”₯

πŸŽ€ RETURN VALUES πŸŽ€

The trimdomain() function does not return a value. It's a void. She gives nothing back and honestly? Same, bestie. We love a no-strings-attached icon 😌

πŸ” SEE ALSO πŸ”

  • gethostname(3) β€” the source of the domain-name lore, go read her too 🌈

okay that's the whole page!! from Debian, dated April 7, 1999, filing under TRIMDOMAIN(3) β€” she's old, she's local, she's still cute. mwah πŸ’‹πŸ’–

πŸ“¦ where this page comes from
  • nixpkgs unstable: libutil 73
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms