thr_error.c revision 174112
11638Srgrimes/* 21638Srgrimes * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 31638Srgrimes * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu 41638Srgrimes * All rights reserved. 51638Srgrimes * 61638Srgrimes * Redistribution and use in source and binary forms, with or without 71638Srgrimes * modification, are permitted provided that the following conditions 81638Srgrimes * are met: 91638Srgrimes * 1. Redistributions of source code must retain the above copyright 101638Srgrimes * notice, this list of conditions and the following disclaimer. 111638Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 121638Srgrimes * notice, this list of conditions and the following disclaimer in the 131638Srgrimes * documentation and/or other materials provided with the distribution. 141638Srgrimes * 3. All advertising materials mentioning features or use of this software 151638Srgrimes * must display the following acknowledgement: 161638Srgrimes * This product includes software developed by John Birrell 171638Srgrimes * and Chris Provenzano. 181638Srgrimes * 4. Neither the name of the author nor the names of any co-contributors 191638Srgrimes * may be used to endorse or promote products derived from this software 201638Srgrimes * without specific prior written permission. 211638Srgrimes * 221638Srgrimes * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 231638Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241638Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251638Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261638Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271638Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281638Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291638Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301638Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311638Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321638Srgrimes * SUCH DAMAGE. 3369257Sru * 341638Srgrimes * $FreeBSD: head/lib/libkse/sys/thr_error.c 174112 2007-11-30 17:20:29Z deischen $ 351638Srgrimes */ 361638Srgrimes#include <errno.h> 371638Srgrimes#include <pthread.h> 381638Srgrimes#include "libc_private.h" 391638Srgrimes#include "thr_private.h" 401638Srgrimes 411638Srgrimes#undef errno 421638Srgrimesextern int errno; 431638Srgrimes 441638SrgrimesLT10_COMPAT_DEFAULT(__error); 451638Srgrimes 461638Srgrimesint * 471638Srgrimes__error(void) 481638Srgrimes{ 491638Srgrimes struct pthread *curthread; 501638Srgrimes 511638Srgrimes if (__isthreaded == 0) 521638Srgrimes return (&errno); 531638Srgrimes else if (_kse_in_critical()) 541638Srgrimes return &(_get_curkse()->k_error); 551638Srgrimes else { 561638Srgrimes curthread = _get_curthread(); 571638Srgrimes if ((curthread == NULL) || (curthread == _thr_initial)) 581638Srgrimes return (&errno); 591638Srgrimes else 601638Srgrimes return (&curthread->error); 611638Srgrimes } 621638Srgrimes} 631638Srgrimes