getprogname(3bsd)

πŸ“¦
version 0.12.2 Β· 2 versions
  • 0.12.2 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.11.5 Β· ubuntu jammy
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ getprogname(3bsd) β€” NAME ✨

okay so bestie, this is the getprogname and setprogname page from the BSD world (it's 3bsd, meaning section 3, BSD flavour, and yes we're living in the libbsd cinematic universe). It's literally just "get and set program name" and honestly? iconic. πŸ’…


πŸŽ€ LIBRARY πŸŽ€

Utility functions from BSD systems β€” that's libbsd, and you link it with -lbsd. she's a whole package, fr fr.


🌸 SYNOPSIS 🌸

#include <stdlib.h>
(See libbsd(7) for include usage.)

const char *
getprogname(void);

void
setprogname(const char *progname);

tiny note bestie: peep libbsd(7) for the whole include-usage situation, iykyk.


πŸ¦‹ DESCRIPTION πŸ¦‹

so getprogname() hands you back a string with the current program name, and it's excluding any directory component β€” so no /usr/bin/ nonsense, just the name. And if it literally cannot find the program name from any known source? it returns NULL. not me getting ghosted by a function 😭

then there's setprogname() β€” this one sets the current program name, and it strips any directory component prefix for you. but here's the thing, and it's lowkey important: it keeps a reference to the passed string pointer. so you must not free or modify that string while these functions might still get called. do not touch her. she's holding onto it. periodt. 🫢

now for the tea on implementations: the ones on most BSDs will try to initialize the program name at program startup time, and libbsd will try to infer it from various known sources depending on the target system. sounds great, right? BUT. it is not a portable assumption that the program name will be set without calling setprogname(). so if you want portable programs β€” and bestie, you do β€” you should always call it after starting up. always. no skipping. 🚨


πŸ‘‘ SEE ALSO πŸ‘‘


πŸ’œ HISTORY πŸ’œ

the setprogname() and getprogname() functions first appeared in:

  • NetBSD 1.6
  • FreeBSD 4.4
  • DragonFly 2.1
  • OpenBSD 5.4

four glow-ups, one function. ate. 🌈


and that's the whole page, bestie β€” brought to you by Debian, August 03, 2022, on the getprogname(3bsd) page itself. mwah πŸ’– go set that program name, main character. ⭐

πŸ“¦ where this page comes from