19da7bddpfg/*-
29da7bddpfg * SPDX-License-Identifier: BSD-4-Clause
39da7bddpfg *
416b1376jeff * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
516b1376jeff * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu
616b1376jeff * All rights reserved.
716b1376jeff *
816b1376jeff * Redistribution and use in source and binary forms, with or without
916b1376jeff * modification, are permitted provided that the following conditions
1016b1376jeff * are met:
1116b1376jeff * 1. Redistributions of source code must retain the above copyright
1216b1376jeff *    notice, this list of conditions and the following disclaimer.
1316b1376jeff * 2. Redistributions in binary form must reproduce the above copyright
1416b1376jeff *    notice, this list of conditions and the following disclaimer in the
1516b1376jeff *    documentation and/or other materials provided with the distribution.
1616b1376jeff * 3. All advertising materials mentioning features or use of this software
1716b1376jeff *    must display the following acknowledgement:
1816b1376jeff *	This product includes software developed by John Birrell
1916b1376jeff *  and Chris Provenzano.
2016b1376jeff * 4. Neither the name of the author nor the names of any co-contributors
2116b1376jeff *    may be used to endorse or promote products derived from this software
2216b1376jeff *    without specific prior written permission.
2316b1376jeff *
2416b1376jeff * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
2516b1376jeff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2616b1376jeff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2716b1376jeff * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2816b1376jeff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2916b1376jeff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3016b1376jeff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3116b1376jeff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3216b1376jeff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3316b1376jeff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3416b1376jeff * SUCH DAMAGE.
3516b1376jeff *
3616b1376jeff * $FreeBSD$
3716b1376jeff */
3816b1376jeff
3916b1376jeff#include <pthread.h>
40f066519davidxu
41f066519davidxu#include "libc_private.h"
4216b1376jeff#include "thr_private.h"
4316b1376jeff
4416b1376jeff#undef errno
4516b1376jeffextern	int	errno;
4616b1376jeff
478d1dfb4kib__weak_reference(__error_threaded, __error);
4816b1376jeffint *
498d1dfb4kib__error_threaded(void)
5016b1376jeff{
51f53e1c9davidxu	struct pthread *curthread;
5216b1376jeff
53f53e1c9davidxu	if (_thr_initial != NULL) {
54f53e1c9davidxu		curthread = _get_curthread();
55f53e1c9davidxu		if (curthread != NULL && curthread != _thr_initial)
56f53e1c9davidxu			return (&curthread->error);
57f53e1c9davidxu	}
58f53e1c9davidxu	return (&errno);
5916b1376jeff}
60