GETUSER(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

πŸ’… 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:

  1. it looks first for an environment variable $sysname 🌈
  2. if there is no such variable, sysname calls gethostname(2) and truncates the returned name at the first dot βœ‚οΈ
  3. if gethostname fails, sysname returns 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 πŸ¦‹βœ¨πŸ’œ