error() usage

fastened fastenedmail@gmail.com
Sun May 4 22:57:35 GMT 2025


The [Error Messages](https://sourceware.org/glibc/manual/2.41/html_node/Error-Messages.html)
man page claims:

"error prints first the program name. If the application defined a
global variable error_print_progname and points it to a function this
function will be called to print the program name. Otherwise the
string from the global variable program_name is used."

>From testing on Debian and Fedora, I have found that setting
`program_name` in a user-defined program does *not* change the output
of an `error()` call; however `program_invocation_name` *does*
(`program_invocation_short_name` does not work).

However, _internal_ to GNU projects (e.g. in [`readelf.c` of
binutils](https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=binutils/readelf.c;h=dd1871d8c75a72bd0ea1ad2b5e5a3bbfd987ef98;hb=HEAD#l223)),
`program_name` does indeed change the output of an `error()` call.
Similarly, in the `error.c` source itself, `program_name` is used in
the defining `error` function. In that source file, `program_name` is
a macro to `program_invocation_name` if `_LIBC` is defined, and
`getprogname()` if not.

I am a relative beginner, so apologies if this is a naive question:
Should the 'correct' variable (at least, seemingly, for GNU/Linux
systems) for user-defined programs - that is,
`program_invocation_name` - be noted in the glibc manual? Or is the
intent of the manual to document *internal* behavior (i.e. its use in
binutils, the source code of `error.c`, etc.)? Perhaps I have missed
something about defining `program_name` in a user program?

Cheers,
fastened


More information about the Libc-help mailing list