On Thu, Dec 17, 2020 at 01:17:40AM -0300, Érico Nogueira wrote: > On Wed Dec 16, 2020 at 9:08 PM -03, Dmitry V. Levin wrote: > > On Wed, Dec 16, 2020 at 07:30:11PM -0300, Érico Nogueira via > > Elfutils-devel wrote: > > > From: Érico Rolim <erico....@gmail.com> > > > > > > The Linux man pages recommend this version of the function for portable > > > applications. > > > > > > Signed-off-by: Érico Rolim <erico....@gmail.com> > > > > I'd rather not do it this way because __xpg_strerror_r in glibc is a > > wrapper around GNU strerror_r which does this almost always unneeded > > string copying. Instead of penalizing GNU systems, I'd suggest checking > > at configure time what kind of strerror_r do we have, and choosing the > > code appropriately. > > Fair enough. The GNU version of strerror_r does have a nicer API :) [...] > > What if we had something like this: > > > > static const char * > > errnomsg(int error) > > { > > static const char unknown[] = "unknown error"; > > > > #ifdef HAVE_STRERROR_R_POSIX_SIGNATURE > > static __thread char msg[128]; > > return strerror_r (error, msg, sizeof (msg)) ? unknown : msg; > > #else > > return strerror_r (error, unknown, 0); > > #endif > > } > > Would you prefer this go in lib/ as a "general usage" function or do I > just leave it in libdwfl/ for now?
Is there any more potential users besides dwfl_errmsg? If yes, then it would make sense to have it in lib/, but then you'd have to come up with a good name for the function. :) > As a side note, the trick of passing a constant string and buflen=0 is > quite neat, and isn't obvious from reading the man page :) I'd suggest to make it explicitly documented in the manual page. -- ldv