GETPROGNAME(3)

NAME
getprogname, setprogname - get/set the name of the current program

SYNOPSIS
#include <stdlib.h>
const char *
getprogname(void);
void
setprogname(const char *name);

DESCRIPTION
These utility functions get and set the current program's name as used by various error-reporting functions.

getprogname() returns the name of the current program. This function is typically useful when generating error messages or other diagnostic output. If the program name has not been set, getprogname() will return NULL.

The setprogname() function sets the name of the program to be the last path component of the progname argument. Internally, only the pointer to the given string is kept as the program name, so it should not be modified and the storage for the string must remain valid for the rest of the program's lifetime.

In OpenBSD, the name of the program is set by the start-up code that is run before main(); thus, running setprogname() is not necessary. Programs that desire maximum portability should still call it; on other operating systems, these functions may be implemented in a portability library. Calling setprogname() allows the aforementioned library to learn the program name without modifications to the start-up code.

SEE ALSO
err(3), setproctitle(3)

HISTORY
The getprogname and setprogname functions first appeared in OpenBSD 5.4.

CAVEATS
The string returned by getprogname() is supplied by the invoking process and should not be trusted by setuid or setgid programs.