thr_error.c revision 113657
135538Sjb/* 235538Sjb * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. 335538Sjb * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu 435538Sjb * All rights reserved. 535538Sjb * 635538Sjb * Redistribution and use in source and binary forms, with or without 735538Sjb * modification, are permitted provided that the following conditions 835538Sjb * are met: 935538Sjb * 1. Redistributions of source code must retain the above copyright 1035538Sjb * notice, this list of conditions and the following disclaimer. 1135538Sjb * 2. Redistributions in binary form must reproduce the above copyright 1235538Sjb * notice, this list of conditions and the following disclaimer in the 1335538Sjb * documentation and/or other materials provided with the distribution. 1435538Sjb * 3. All advertising materials mentioning features or use of this software 1535538Sjb * must display the following acknowledgement: 1635538Sjb * This product includes software developed by John Birrell 1735538Sjb * and Chris Provenzano. 1835538Sjb * 4. Neither the name of the author nor the names of any co-contributors 1935538Sjb * may be used to endorse or promote products derived from this software 2035538Sjb * without specific prior written permission. 2135538Sjb * 2235538Sjb * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 2335538Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2435538Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2535538Sjb * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2635538Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2735538Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2835538Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2935538Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3035538Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3135538Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3235538Sjb * SUCH DAMAGE. 3335538Sjb * 3450476Speter * $FreeBSD: head/lib/libkse/sys/thr_error.c 113657 2003-04-18 05:02:39Z deischen $ 3535538Sjb */ 3635538Sjb#include <pthread.h> 37113657Sdeischen#include "libc_private.h" 38103388Smini#include "thr_private.h" 3935538Sjbextern int errno; 4035538Sjb 4135538Sjbint * __error() 4235538Sjb{ 43113657Sdeischen struct pthread *curthread; 44113657Sdeischen 45113657Sdeischen if (__isthreaded == 0) 46113657Sdeischen return (&errno); 47113657Sdeischen else { 48113657Sdeischen curthread = _get_curthread(); 49113657Sdeischen if ((curthread == NULL) || (curthread == _thr_initial)) 50113657Sdeischen return (&errno); 51113657Sdeischen else 52113657Sdeischen return (&curthread->error); 5335538Sjb } 5435538Sjb} 55