include/errno.h: skip set_errno in interrupt context

set_errno() should not modify the interrupted task's errno.
Add a check using up_interrupt_context() and skip the assignment
when called from an interrupt handler.

Signed-off-by: Jerry Ma <shichunma@bestechnic.com>
This commit is contained in:
shichunma
2026-05-03 08:51:59 +08:00
committed by Alan C. Assis
parent a8a492cb4f
commit 3c9a9d683f
+16
View File
@@ -29,6 +29,10 @@
#include <nuttx/compiler.h>
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
# include <nuttx/irq.h>
#endif
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -41,12 +45,24 @@
*/
#define errno *__errno()
#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
#define set_errno(e) \
do \
{ \
if (!up_interrupt_context()) \
{ \
errno = (int)(e); \
} \
} \
while (0)
#else
#define set_errno(e) \
do \
{ \
errno = (int)(e); \
} \
while (0)
#endif
#define get_errno() errno
/* Definitions of error numbers and the string that would be