This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch, libfortran] PR46267 strerror() might not be thread-safe, take 2
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Janne Blomqvist <blomqvist dot janne at gmail dot com>
- Cc: Fortran List <fortran at gcc dot gnu dot org>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 21 Jan 2011 18:36:33 +0100
- Subject: Re: [Patch, libfortran] PR46267 strerror() might not be thread-safe, take 2
- References: <AANLkTinhTAfgxwPnHEtBndLrR8mGco+nvXXC7vG_1jjC@mail.gmail.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Fri, Jan 21, 2011 at 07:24:56PM +0200, Janne Blomqvist wrote:
> @@ -141,6 +141,38 @@ gfc_xtoa (GFC_UINTEGER_LARGEST n, char *buffer, size_t len)
> return p;
> }
>
> +
> +/* Hopefully thread-safe wrapper for a strerror() style function. */
> +
> +char *
> +gf_strerror (int errnum,
> +#ifdef HAVE_STRERROR_R
> + char * buf, size_t buflen)
> +{
> + /* TODO: How to prevent the compiler warning due to strerror_r of
> + the untaken branch having the wrong return type? */
> + if (__builtin_classify_type (strerror_r (0, buf, 0)) == 5)
> + {
> + /* GNU strerror_r() */
> + return strerror_r (errnum, buf, buflen);
> + }
> + else
> + {
> + /* POSIX strerror_r () */
> + strerror_r (errnum, buf, buflen);
> + return buf;
> + }
> +#else
> + char * buf __attribute__((unused)),
> + size_t buflen __attribute__((unused)))
> +{
> + /* strerror () is not necessarily thread-safe, but should at least
> + be available everywhere. */
> + return strerror (errnum);
> +#endif
> +}
The #ifdef inside of the parameters ending inside function
looks very ugly, you can use unused attribute unconditionally
and start #ifdef only within function body.
Jakub