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