[llvm-commits] [PATCH] work around a nasty g++/glibc incompatiblity

Török Edwin edwintorok at gmail.com
Sun Jun 14 00:38:34 PDT 2009


On 2009-06-14 00:58, Benjamin Kramer wrote:
> glibc has two versions of strerror_r, a standards compliant one and a
> GNU specific one. The GNU one is chosen when _GNU_SOURCE is defined.
> g++ always defines _GNU_SOURCE on linux platforms because glibc's
> headers won't compile in C++ mode without it. The GNU strerror_r
> doesn't always modify the buffer which causes empty error messages on
> linux. The attached patch fixes this by falling back to the less
> threadsafe method if _GNU_SOURCE is defined.
>

The GNU version always returns a pointer to the error message, it may or
may not use the buffer supplied.
(I think it doesn't use the buffer if it can return a pointer to the
error message table).
Accessing the returned pointer is thread safe in either case, so you
could check if the returned value == buffer, and  if not copy it to
buffer. It would still be thread safe.

Or we could just use a mutex around strerror invocations.

Best regards,
--Edwin




More information about the llvm-commits mailing list