libroot_debug: Merge guarded heap into libroot_debug.
[haiku.git] / src / system / libroot / posix / errno.c
blob96cb89a4ca87208439a28cc27a4e3baab7eb69cb
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 */
6 /* Provides user space storage for "errno", located in TLS
7 */
9 #include <errno.h>
11 #include "support/TLS.h"
12 #include "tls.h"
15 int *
16 _errnop(void)
18 return (int *)tls_address(TLS_ERRNO_SLOT);
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
30 // #pragma mark -
33 int
34 _to_positive_error(int error)
36 if (error < 0)
37 return error == B_NO_MEMORY ? -B_POSIX_ENOMEM : -error;
38 return error;
42 int
43 _to_negative_error(int error)
45 return error > 0 ? -error : error;