[musl] Re: Tweaking the program name for <err.h> functions
Rich Felker
dalias at libc.org
Sun Mar 10 19:39:56 UTC 2024
On Sun, Mar 10, 2024 at 02:01:18PM +0000, NRK wrote:
> > or add locks; that is:
> >
> > lock()
> > fprintf("%s: ", __progname);
> > vfprintf(...);
> > unlock();
> >
> > [...]
> >
> > locking code is error-prone, I'd say.
>
> These interfaces do not guarantee the output to be atomic. If you were
> expecting it to be atomic then that's just *another* reason to roll it
> yourself because a good ton of existing implementation doesn't lock.
Also, the whole reason this comes up is gratuitous impedance mismatch
bringing in the need for a separate fprintf call to do the prefix (and
possibly newline suffix, if you want that). They could have been
designed to be one-line macros, ala...
#define warn(f,...) fprintf(stderr, "%s: " f, __progname, __VA_ARGS__)
or similar. I really see no justifiable reason for people writing new
software to want to enhance the err.h functions rather than just
rolling a one-line macro that can be better tailored to their specific
needs.
Rich
More information about the libbsd
mailing list