diff options
-rw-r--r-- | include/libbb.h | 7 | ||||
-rw-r--r-- | libbb/appletlib.c | 2 | ||||
-rw-r--r-- | libbb/ptr_to_globals.c | 4 |
3 files changed, 7 insertions, 6 deletions
diff --git a/include/libbb.h b/include/libbb.h index 83ecca47f..df7e45404 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -339,12 +339,13 @@ struct BUG_off_t_size_is_misdetected { | |||
339 | #endif | 339 | #endif |
340 | #endif | 340 | #endif |
341 | 341 | ||
342 | #if defined(__GLIBC__) | 342 | #if defined(errno) |
343 | /* glibc uses __errno_location() to get a ptr to errno */ | 343 | /* If errno is a define, assume it's "define errno (*__errno_location())" |
344 | /* We can just memorize it once - no multithreading in busybox :) */ | 344 | * and we will cache it's result in this variable */ |
345 | extern int *const bb_errno; | 345 | extern int *const bb_errno; |
346 | #undef errno | 346 | #undef errno |
347 | #define errno (*bb_errno) | 347 | #define errno (*bb_errno) |
348 | #define bb_cached_errno_ptr 1 | ||
348 | #endif | 349 | #endif |
349 | 350 | ||
350 | #if !(ULONG_MAX > 0xffffffff) | 351 | #if !(ULONG_MAX > 0xffffffff) |
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index a515c3fe3..717c63649 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -303,7 +303,7 @@ void lbb_prepare(const char *applet | |||
303 | void lbb_prepare(const char *applet | 303 | void lbb_prepare(const char *applet |
304 | IF_FEATURE_INDIVIDUAL(, char **argv)) | 304 | IF_FEATURE_INDIVIDUAL(, char **argv)) |
305 | { | 305 | { |
306 | #ifdef __GLIBC__ | 306 | #ifdef bb_cached_errno_ptr |
307 | (*(int **)not_const_pp(&bb_errno)) = __errno_location(); | 307 | (*(int **)not_const_pp(&bb_errno)) = __errno_location(); |
308 | barrier(); | 308 | barrier(); |
309 | #endif | 309 | #endif |
diff --git a/libbb/ptr_to_globals.c b/libbb/ptr_to_globals.c index 8ba9cd154..2232c6864 100644 --- a/libbb/ptr_to_globals.c +++ b/libbb/ptr_to_globals.c | |||
@@ -14,7 +14,7 @@ struct globals; | |||
14 | * but here we make it live in R/W memory */ | 14 | * but here we make it live in R/W memory */ |
15 | struct globals *ptr_to_globals; | 15 | struct globals *ptr_to_globals; |
16 | 16 | ||
17 | #ifdef __GLIBC__ | 17 | #ifdef errno |
18 | int *bb_errno; | 18 | int *bb_errno; |
19 | #endif | 19 | #endif |
20 | 20 | ||
@@ -27,7 +27,7 @@ int *bb_errno; | |||
27 | * on weird architectures, compilers, linkers and so on */ | 27 | * on weird architectures, compilers, linkers and so on */ |
28 | struct globals *const ptr_to_globals __attribute__ ((section (".data"))); | 28 | struct globals *const ptr_to_globals __attribute__ ((section (".data"))); |
29 | 29 | ||
30 | #ifdef __GLIBC__ | 30 | #ifdef errno |
31 | int *const bb_errno __attribute__ ((section (".data"))); | 31 | int *const bb_errno __attribute__ ((section (".data"))); |
32 | #endif | 32 | #endif |
33 | 33 | ||