diff --git a/include/errno.h b/include/errno.h index 9caf44d60a..b88ee3a15d 100644 --- a/include/errno.h +++ b/include/errno.h @@ -42,7 +42,7 @@ #define set_errno(e) \ do \ { \ - errno = (int)(e); \ + errno = (int)(e); \ } \ while (0) #define get_errno() errno diff --git a/libs/libc/errno/lib_errno.c b/libs/libc/errno/lib_errno.c index 92582d61c2..101f5dd02e 100644 --- a/libs/libc/errno/lib_errno.c +++ b/libs/libc/errno/lib_errno.c @@ -29,6 +29,12 @@ #include +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static int g_errno; + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -57,5 +63,5 @@ FAR int *__errno(void) /* And return the return refernce to the error number */ - return &tlsinfo->tl_errno; + return tlsinfo ? &tlsinfo->tl_errno : &g_errno; }