Main index | Section 3 | Options |
#include <stdlib.h>
The getprogname() function returns the name of the program. If the name has not been set yet, it will return NULL.
The setprogname() function sets the name of the program to be the last component of the progname argument. Since a pointer to the given string is kept as the program name, it should not be modified for the rest of the program's lifetime.
In FreeBSD , 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 another operating system, 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.
#include <stdio.h> #include <stdlib.h>int main(int argc, char** argv) { printf("getprogname(): %s\n", getprogname()); printf("argv[0]: %s\n", argv[0]); return (0); }
When compiled and executed (e.g., with ‘./a.out’) the output of the program is going to look like this:
getprogname(): a.out argv[0]: ./a.out
GETPROGNAME (3) | April 18, 2021 |
Main index | Section 3 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.