Date: Sun, 31 Jan 1999 10:37:10 -0800 (PST) From: John Polstra <jdp@polstra.com> To: robert+freebsd@cyrus.watson.org Cc: hackers@FreeBSD.ORG Subject: Re: Correct way to write a thread-safe library Message-ID: <199901311837.KAA07195@vashon.polstra.com> In-Reply-To: <Pine.BSF.3.96.990130120203.1285A-100000@fledge.watson.org>
next in thread | previous in thread | raw e-mail | index | archive | help
In article <Pine.BSF.3.96.990130120203.1285A-100000@fledge.watson.org>, Robert Watson <robert+freebsd@cyrus.watson.org> wrote: > > So here I am, chugging away at a library I'm writing, and I notice that > the spec requires me to report errors via errno. I immediatly recall a > long discussion of errno changes a long time ago and macro definitions of > it. So my question is this--what is the correct way for me to write a > thread-safe library that can be used by threaded and non-threaded code, > and that also uses errno to report errors? The general idea is that in <errno.h> or <sys/errno.h> you define "errno" as something like this: #define errno (* __error()) and then make "__error()" return a pointer to where the possibly thread-specific value is stored. You can look at our existing libc and libc_r code for an example. The C standard explicitly allows for this by requiring "errno" to be an lvalue but not necessarily a simple variable. It also requires compilation units that reference "errno" to include <errno.h>. John -- John Polstra jdp@polstra.com John D. Polstra & Co., Inc. Seattle, Washington USA "Nobody ever went broke underestimating the taste of the American public." -- H. L. Mencken To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199901311837.KAA07195>