From owner-freebsd-hackers Sun Jan 31 10:37:14 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id KAA01767 for freebsd-hackers-outgoing; Sun, 31 Jan 1999 10:37:14 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from wall.polstra.com (rtrwan160.accessone.com [206.213.115.74]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id KAA01761 for ; Sun, 31 Jan 1999 10:37:12 -0800 (PST) (envelope-from jdp@polstra.com) Received: from vashon.polstra.com (vashon.polstra.com [206.213.73.13]) by wall.polstra.com (8.9.1/8.9.1) with ESMTP id KAA27319; Sun, 31 Jan 1999 10:37:10 -0800 (PST) (envelope-from jdp@polstra.com) From: John Polstra Received: (from jdp@localhost) by vashon.polstra.com (8.9.1/8.9.1) id KAA07195; Sun, 31 Jan 1999 10:37:10 -0800 (PST) (envelope-from jdp@polstra.com) Date: Sun, 31 Jan 1999 10:37:10 -0800 (PST) Message-Id: <199901311837.KAA07195@vashon.polstra.com> To: robert+freebsd@cyrus.watson.org Subject: Re: Correct way to write a thread-safe library Newsgroups: polstra.freebsd.hackers In-Reply-To: Organization: Polstra & Co., Seattle, WA Cc: hackers@FreeBSD.ORG Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In article , Robert Watson 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 or 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 . 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