xref: /haiku/src/system/libroot/posix/errno.c (revision 21258e2674226d6aa732321b6f8494841895af5f)
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 
15 int *
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__
26 extern int *(*__errno_location)(void) __attribute__ ((weak, alias("_errnop")));
27 #endif
28 
29 
30 // #pragma mark -
31 
32 
33 int
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 
42 int
43 _to_negative_error(int error)
44 {
45 	return error > 0 ? -error : error;
46 }
47