getprogname(3bsd)
β¨ 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
- alpine 3.22: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- alpine 3.23: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- alpine 3.24: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- arch rolling: libbsd 0.12.2-2 Β· custom
- debian bookworm: libbsd-dev 0.11.7-2
- debian trixie: libbsd-dev 0.12.2-2
- epel 10: libbsd-devel 0.12.2-4.el10_0 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- epel 9: libbsd-devel 0.12.2-1.el9 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 43: libbsd-devel 0.12.2-6.fc43 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 43: libbsd-devel 0.12.2-6.fc43 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 44: libbsd-devel 0.12.2-7.fc44 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 44: libbsd-devel 0.12.2-7.fc44 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- nixos 26.05: libbsd 0.12.2
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- ubuntu noble: libbsd-dev 0.12.1-1build1
- ubuntu noble: libbsd-dev 0.12.1-1build1.1
- ubuntu questing: libbsd-dev 0.12.2-2build1
- ubuntu resolute: libbsd-dev 0.12.2-2build2
- ubuntu stonking: libbsd-dev 0.12.2-3
- Copyright (c) 2022 Guillem Jover <guillem@hadrons.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms