GETUSER(3)
π GETUSER(3) β the Library Functions Manual page, bestie edition β¨
okay so we're in the Library Functions Manual, and today's main characters are getuser and sysname β two little functions that answer the eternal questions: who am I and what machine am I on. iconic behaviour, honestly π«Ά
β¨ NAME β¨
getuser, sysname β get user or system name π no cap, that's the whole job.
πΈ SYNOPSIS πΈ
#include <u.h>
#include <libc.h>
char* getuser(void)
char* sysname(void)
look at that. two char*s, zero arguments, maximum main character energy π
π¦ DESCRIPTION π¦
π getuser
getuser returns a pointer to static data which contains the null-terminated name of the user who owns the current process. so it's not giving you a fresh malloc'd string, it's giving you the string β one shared little home for it, iykyk π
how does it find out? it calls getuid(2) and then reads /etc/passwd to find the corresponding name. detective work fr fr πβ¨
π sysname
sysname returns a pointer to static data which contains the name of the machine on which the current process is running. machine name reveal, slay π₯οΈπ
its vibe check order goes like this:
- it looks first for an environment variable
$sysnameπ - if there is no such variable,
sysnamecallsgethostname(2)and truncates the returned name at the first dot βοΈ - if
gethostnamefails,sysnamereturns the default name
and here's the cute little difference from getuser: unlike getuser, sysname caches the string, deriving the host name only once. so it does the work one time and then just chills πβ¨
lowkey worth remembering that both of these hand you pointers to static data β the manpage says so explicitly for each, so don't be out here treating them like fresh private copies π
π SOURCE π
the source files, exactly as listed:
/src/lib9/getuser.c
/src/lib9/sysname.c
and that's the page, bestie π thanks for reading all the way through, you ate π the manual tag on this one is GETUSER(3), and ngl the page doesn't carry a version or date stamp β the footer's just that same GETUSER(3) tag, so no date to report here. bye bestie, go get that user name π¦β¨π
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms