This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Replace the remaining uses of strerror with safe_strerror
- From: "Christian Biesinger via gdb-patches" <gdb-patches at sourceware dot org>
- To: Pedro Alves <palves at redhat dot com>
- Cc: gdb-patches <gdb-patches at sourceware dot org>
- Date: Mon, 9 Dec 2019 14:11:03 -0500
- Subject: Re: [PATCH] Replace the remaining uses of strerror with safe_strerror
- References: <20191126195901.50696-1-cbiesinger@google.com> <ddc204c8-8353-f230-97f5-a6de9a6ba0b2@redhat.com> <CAPTJ0XH-tVAyf=BGB4HVBapqJ7_gNL5Xvt+vLnHvKRX+8+KtsQ@mail.gmail.com> <ebb496c1-91f2-6330-4143-c8ceab418058@redhat.com>
- Reply-to: Christian Biesinger <cbiesinger at google dot com>
On Fri, Dec 6, 2019 at 4:46 PM Pedro Alves <palves@redhat.com> wrote:
>
> On 12/6/19 8:36 PM, Christian Biesinger wrote:
> > On Fri, Dec 6, 2019 at 2:06 PM Pedro Alves <palves@redhat.com> wrote:
>
> >> GDBserver and (I assume) the IPA can be built with other C runtimes on Linux,
> >> like musl and others. Do you know how musl behaves?
> >
> > Oof, looks like they return int :(
> > http://git.musl-libc.org/cgit/musl/tree/src/string/strerror_r.c
> >
> > I guess I'll change to #if defined(IN_PROCESS_AGENT) && defined(__GLIBC__)?
> >
>
> Crazy thought --- use C++ overload resolution to pick the right thing
> automatically:
>
> /* Called if we have a XSI-compliant strerror_r. */
> static char *select_strerror_r (int, char *buf) { return buf; }
>
> /* Called if we have a GNU strerror_r. */
> static char *select_strerror_r (char *res, char *) { return res; }
>
> #ifdef IN_PROCESS_AGENT
> return select_strerror_r (strerror_r (errnum, buf, buflen), buf);
> #else ...
Ah, great idea. That way I don't even need the #ifdef. Done, will send
a new version now.
Christian