thr_error.c revision 144518
1112919Sjeff/*
2112919Sjeff * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
3112919Sjeff * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu
4112919Sjeff * All rights reserved.
5112919Sjeff *
6112919Sjeff * Redistribution and use in source and binary forms, with or without
7112919Sjeff * modification, are permitted provided that the following conditions
8112919Sjeff * are met:
9112919Sjeff * 1. Redistributions of source code must retain the above copyright
10112919Sjeff *    notice, this list of conditions and the following disclaimer.
11112919Sjeff * 2. Redistributions in binary form must reproduce the above copyright
12112919Sjeff *    notice, this list of conditions and the following disclaimer in the
13112919Sjeff *    documentation and/or other materials provided with the distribution.
14112919Sjeff * 3. All advertising materials mentioning features or use of this software
15112919Sjeff *    must display the following acknowledgement:
16112919Sjeff *	This product includes software developed by John Birrell
17112919Sjeff *  and Chris Provenzano.
18112919Sjeff * 4. Neither the name of the author nor the names of any co-contributors
19112919Sjeff *    may be used to endorse or promote products derived from this software
20112919Sjeff *    without specific prior written permission.
21112919Sjeff *
22112919Sjeff * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
23112919Sjeff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24112919Sjeff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25112919Sjeff * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26112919Sjeff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27112919Sjeff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28112919Sjeff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29112919Sjeff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30112919Sjeff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31112919Sjeff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32112919Sjeff * SUCH DAMAGE.
33112919Sjeff *
34112919Sjeff * $FreeBSD: head/lib/libthr/sys/thr_error.c 144518 2005-04-02 01:20:00Z davidxu $
35112919Sjeff */
36112919Sjeff
37112919Sjeff#include <pthread.h>
38144518Sdavidxu
39144518Sdavidxu#include "libc_private.h"
40112919Sjeff#include "thr_private.h"
41112919Sjeff
42112919Sjeff#undef errno
43112919Sjeffextern	int	errno;
44112919Sjeff
45112919Sjeffint *
46144518Sdavidxu__error(void)
47112919Sjeff{
48144518Sdavidxu	struct pthread *curthread = _get_curthread();
49112919Sjeff
50144518Sdavidxu	if (curthread != NULL && curthread != _thr_initial)
51144518Sdavidxu		return (&curthread->error);
52144518Sdavidxu	else
53112919Sjeff		return (&errno);
54112919Sjeff}
55