This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, libfortran] PR46267 strerror() might not be thread-safe, take 2


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]