1331722Seadler/*
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$
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
45276630Skib__weak_reference(__error_threaded, __error);
46112919Sjeffint *
47276630Skib__error_threaded(void)
48112919Sjeff{
49160284Sdavidxu	struct pthread *curthread;
50112919Sjeff
51160284Sdavidxu	if (_thr_initial != NULL) {
52160284Sdavidxu		curthread = _get_curthread();
53160284Sdavidxu		if (curthread != NULL && curthread != _thr_initial)
54160284Sdavidxu			return (&curthread->error);
55160284Sdavidxu	}
56160284Sdavidxu	return (&errno);
57112919Sjeff}
58