Hi,

I don't use OpenBSD, but I've played with it and am interested in making
my code portable to it. A trend which the GNU C Library recently got on
board with is to use a thread-local storage buffer for strerror() which
makes it safe to use across multiple threads. I was wondering if there
is a particular reason OpenBSD has not taken this approach, perhaps just
because it hasn't been raised, or if it doesn't support thread-local
storage.

>From the strerror() code [1] it seems that, if OpenBSD supports a C11
compiler, it should be as easy as adding the _Thread_local (or otherwise
the GCC/Clang-specific __thread) keyword to the static buffer.

Whether thread-local storage is allowed was clarified in POSIX [2] by a
Technical Corrigendum although I have not referred to an official copy;
they affirmed it can be used, so if this change were to be made in
OpenBSD, it should not break conforming applications.

Off-topic, but since I know someone will ask: I dislike strerror_r() and
strerror_l() because they are allowed to fail, and since POSIX places no
restrictions, that means they are allowed to fail for any reason. Even
on failure, plain strerror() is always required to return a valid NUL-
terminated string of some sort, which makes it convenient.

In order to use perror(), one has to assign the error number to errno,
which in the case of functions like POSIX threads seems to somewhat
defeat the point of the design of the interfaces in my opinion.

Thanks,
John 

[1] 
https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/lib/libc/string/strerror.c
[2] https://www.austingroupbugs.net/view.php?id=656

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to