1df57947fSPedro F. Giffuni /*-
2df57947fSPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause
3df57947fSPedro F. Giffuni *
470d5093aSJeff Roberson * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
570d5093aSJeff Roberson * Copyright (c) 1994 by Chris Provenzano, proven@mit.edu
670d5093aSJeff Roberson * All rights reserved.
770d5093aSJeff Roberson *
870d5093aSJeff Roberson * Redistribution and use in source and binary forms, with or without
970d5093aSJeff Roberson * modification, are permitted provided that the following conditions
1070d5093aSJeff Roberson * are met:
1170d5093aSJeff Roberson * 1. Redistributions of source code must retain the above copyright
1270d5093aSJeff Roberson * notice, this list of conditions and the following disclaimer.
1370d5093aSJeff Roberson * 2. Redistributions in binary form must reproduce the above copyright
1470d5093aSJeff Roberson * notice, this list of conditions and the following disclaimer in the
1570d5093aSJeff Roberson * documentation and/or other materials provided with the distribution.
1670d5093aSJeff Roberson * 3. All advertising materials mentioning features or use of this software
1770d5093aSJeff Roberson * must display the following acknowledgement:
1870d5093aSJeff Roberson * This product includes software developed by John Birrell
1970d5093aSJeff Roberson * and Chris Provenzano.
2070d5093aSJeff Roberson * 4. Neither the name of the author nor the names of any co-contributors
2170d5093aSJeff Roberson * may be used to endorse or promote products derived from this software
2270d5093aSJeff Roberson * without specific prior written permission.
2370d5093aSJeff Roberson *
2470d5093aSJeff Roberson * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
2570d5093aSJeff Roberson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2670d5093aSJeff Roberson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2770d5093aSJeff Roberson * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2870d5093aSJeff Roberson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2970d5093aSJeff Roberson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3070d5093aSJeff Roberson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3170d5093aSJeff Roberson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3270d5093aSJeff Roberson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3370d5093aSJeff Roberson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3470d5093aSJeff Roberson * SUCH DAMAGE.
3570d5093aSJeff Roberson */
3670d5093aSJeff Roberson
3770d5093aSJeff Roberson #include <pthread.h>
38a091d823SDavid Xu
39a091d823SDavid Xu #include "libc_private.h"
4070d5093aSJeff Roberson #include "thr_private.h"
4170d5093aSJeff Roberson
42*1235d276SBrooks Davis extern int __libsys_errno;
4370d5093aSJeff Roberson
448495e8b1SKonstantin Belousov __weak_reference(__error_threaded, __error);
4570d5093aSJeff Roberson int *
__error_threaded(void)468495e8b1SKonstantin Belousov __error_threaded(void)
4770d5093aSJeff Roberson {
489bbc6c7fSDavid Xu struct pthread *curthread;
4970d5093aSJeff Roberson
509bbc6c7fSDavid Xu if (_thr_initial != NULL) {
519bbc6c7fSDavid Xu curthread = _get_curthread();
52a091d823SDavid Xu if (curthread != NULL && curthread != _thr_initial)
53a091d823SDavid Xu return (&curthread->error);
549bbc6c7fSDavid Xu }
55*1235d276SBrooks Davis return (&__libsys_errno);
5670d5093aSJeff Roberson }
57