1/*
2** Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3** Distributed under the terms of the MIT License.
4*/
5
6/* Provides user space storage for "errno", located in TLS
7 */
8
9#include <errno.h>
10
11#include "support/TLS.h"
12#include "tls.h"
13
14
15int *
16_errnop(void)
17{
18	return (int *)tls_address(TLS_ERRNO_SLOT);
19}
20
21
22// This is part of the Linuxbase binary specification
23// and is referenced by some code in libgcc.a.
24// ToDo: maybe we even want to include this always
25#ifdef __linux__
26extern int *(*__errno_location)(void) __attribute__ ((weak, alias("_errnop")));
27#endif
28
29
30// #pragma mark -
31
32
33int
34_to_positive_error(int error)
35{
36	if (error < 0)
37		return error == B_NO_MEMORY ? -B_POSIX_ENOMEM : -error;
38	return error;
39}
40
41
42int
43_to_negative_error(int error)
44{
45	return error > 0 ? -error : error;
46}
47