TRIMDOMAIN(3)
πΈ 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
fullnameends 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
- Copyright (c) 1999 Brian Somers <brian@Awfulhak.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms