bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] strerror_r: guarantee unchanged errno


From: Bruno Haible
Subject: Re: [PATCH] strerror_r: guarantee unchanged errno
Date: Thu, 19 May 2011 22:25:08 +0200
User-agent: KMail/1.9.9

Hi Eric,

> * lib/strerror_r.c (strerror_r): Guarantee unchanged errno.
>
> ... preserving errno is important when replacing sterror_r on platforms
> that return -1.

Makes sense, yes. 

> --- a/lib/strerror.c
> +++ b/lib/strerror.c
> @@ -50,6 +50,7 @@ strerror (int n)
>      static char const fmt[] = "Unknown error (%d)";
>      verify (sizeof (buf) >= sizeof (fmt) + INT_STRLEN_BOUND (n));
>      sprintf (buf, fmt, n);
> +    errno = ret;
>      return buf;
>    }
>  }

It's surprising. But indeed, POSIX says:
  "Upon completion, whether successful or not, strerror() shall return
   a pointer to the generated message string."
So we are free to set errno even when returning a string.

Bruno
-- 
In memoriam Anne Boleyn <http://en.wikipedia.org/wiki/Anne_Boleyn>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]