newlib: Simplify errno access
Commit Message
I see no reason why every single errno access (read or write) should
trigger a function call to just return an offset into the reent struct.
This seems to have been needed in the past, but it does not seem to be
needed anymore.
Drop the __errno() function, and set the 'errno' macro to point to the
corresponding offset into the _reent struct.
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
newlib/libc/errno/errno.c | 12 ------------
newlib/libc/include/sys/errno.h | 6 ++----
newlib/libc/machine/cris/sys/errno.h | 6 ++----
3 files changed, 4 insertions(+), 20 deletions(-)
Comments
Hi Paul,
On Aug 30 21:19, Paul Cercueil wrote:
> I see no reason why every single errno access (read or write) should
> trigger a function call to just return an offset into the reent struct.
>
> This seems to have been needed in the past, but it does not seem to be
> needed anymore.
>
> Drop the __errno() function, and set the 'errno' macro to point to the
> corresponding offset into the _reent struct.
You can't do that unconditionally. The __errno function is exported
from the Cygwin DLL and actually used by applications. So the __errno
function must exist and return a useful value for backward compat, even
if it's not used by newly compiled code.
Thanks,
Corinna
@@ -7,16 +7,4 @@
#ifdef _REENT_THREAD_LOCAL
_Thread_local int _tls_errno;
-#else /* !_REENT_THREAD_LOCAL */
-
-#ifndef _REENT_ONLY
-
-int *
-__errno ()
-{
- return &_REENT_ERRNO(_REENT);
-}
-
-#endif
-
#endif /* _REENT_THREAD_LOCAL */
@@ -1,6 +1,5 @@
/* errno is not a global variable, because that would make using it
- non-reentrant. Instead, its address is returned by the function
- __errno. */
+ non-reentrant. Instead, it is an offset into the _reent struct. */
#ifndef _SYS_ERRNO_H_
#ifdef __cplusplus
@@ -15,8 +14,7 @@ extern "C" {
#else /* _REENT_THREAD_LOCAL */
#ifndef _REENT_ONLY
-#define errno (*__errno())
-extern int *__errno (void);
+#define errno _REENT_ERRNO(_REENT)
#endif
#endif /* _REENT_THREAD_LOCAL */
@@ -3,8 +3,7 @@
be those of the Linux/CRIS kernel. */
/* errno is not a global variable, because that would make using it
- non-reentrant. Instead, its address is returned by the function
- __errno. */
+ non-reentrant. Instead, it is an offset into the _reent struct. */
#ifndef _SYS_ERRNO_H_
#ifdef __cplusplus
@@ -15,8 +14,7 @@ extern "C" {
#include <sys/reent.h>
#ifndef _REENT_ONLY
-#define errno (*__errno())
-extern int *__errno (void);
+#define errno _REENT_ERRNO(_REENT)
#endif
/* Please don't use these variables directly.