This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 67b7eff72a111127a1f36840d9cc2d5e3813a5bd Author: Marco Casaroli <[email protected]> AuthorDate: Sat Oct 17 20:12:32 2026 +0200 include: Add NUTTX_NO_EXTENSIONS to keep non-standard names free. The standard headers define names that C and POSIX do not reserve: ERROR and OK (sys/types.h), set_errno() and get_errno() (errno.h), zalloc() (stdlib.h), O_TEXT (fcntl.h), and weak_alias, visibility_hidden, visibility_default and unused_data (nuttx/compiler.h, which sys/types.h includes). A portable program that uses one of these names for its own enum, function, variable or macro does not compile. For example, "enum { OK, ERROR };" or a "static void *zalloc(size_t n)" function fails. A program can now define NUTTX_NO_EXTENSIONS before its first #include. Then the headers do not define these names. No public header uses them, so the other definitions do not change. Nothing changes for programs that do not define the macro. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- include/cxx/cstdlib | 2 ++ include/errno.h | 43 ++++++++++++++++++++++++------------------- include/fcntl.h | 2 ++ include/nuttx/compiler.h | 14 ++++++++++++++ include/stdlib.h | 2 ++ include/sys/types.h | 12 ++++++++---- 6 files changed, 52 insertions(+), 23 deletions(-) diff --git a/include/cxx/cstdlib b/include/cxx/cstdlib index 3c661027ae6..2991902abe3 100644 --- a/include/cxx/cstdlib +++ b/include/cxx/cstdlib @@ -98,7 +98,9 @@ namespace std using ::free; using ::realloc; using ::memalign; +#ifndef NUTTX_NO_EXTENSIONS using ::zalloc; +#endif using ::calloc; #ifdef CONFIG_PSEUDOTERM diff --git a/include/errno.h b/include/errno.h index 1be44998831..2531eded72d 100644 --- a/include/errno.h +++ b/include/errno.h @@ -45,25 +45,30 @@ */ #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 + +/* Not with NUTTX_NO_EXTENSIONS, see nuttx/compiler.h */ + +#ifndef NUTTX_NO_EXTENSIONS +# 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 +#endif /* NUTTX_NO_EXTENSIONS */ /* Definitions of error numbers and the string that would be * returned by strerror(). diff --git a/include/fcntl.h b/include/fcntl.h index 8cd50c6eeda..d6bfb5061c4 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -49,7 +49,9 @@ #define O_WRONLY (1U << 0) /* Open for write access (only) */ #define O_RDWR (2U << 0) /* Open for both read & write access */ #define O_ACCMODE (3U << 0) /* Mask for access mode */ +#ifndef NUTTX_NO_EXTENSIONS /* See nuttx/compiler.h */ #define O_TEXT (1U << 5) /* Open the file in text (translated) mode. */ +#endif #define O_CREAT (1U << 6) /* Create file/sem/mq object */ #define O_EXCL (1U << 7) /* Name must not exist when opened */ #define O_NOCTTY (1U << 8) /* Don't assign a controlling terminal */ diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index 00f926a3510..48bbb031bde 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -1534,6 +1534,20 @@ # define __has_include(x) 0 #endif +/* A program can define NUTTX_NO_EXTENSIONS before the first #include to + * keep some non-standard names free for its own use. Then the headers do + * not define ERROR and OK (sys/types.h), set_errno() and get_errno() + * (errno.h), zalloc() (stdlib.h), O_TEXT (fcntl.h) and the helper macros + * below. The other headers do not use these names. + */ + +#ifdef NUTTX_NO_EXTENSIONS +# undef weak_alias +# undef visibility_hidden +# undef visibility_default +# undef unused_data +#endif + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/include/stdlib.h b/include/stdlib.h index 1fc622fec7a..7df1005fe74 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -246,7 +246,9 @@ void free(FAR void *); FAR void *realloc(FAR void *, size_t) realloc_like(2); FAR void *reallocarray(FAR void *, size_t, size_t) realloc_like2(2, 3); FAR void *memalign(size_t, size_t) malloc_like1(2); +#ifndef NUTTX_NO_EXTENSIONS /* See nuttx/compiler.h */ FAR void *zalloc(size_t) malloc_like1(1); +#endif FAR void *calloc(size_t, size_t) malloc_like2(1, 2); FAR void *aligned_alloc(size_t, size_t) malloc_like1(2); int posix_memalign(FAR void **, size_t, size_t); diff --git a/include/sys/types.h b/include/sys/types.h index 67c1dcf1375..9dedd7d7092 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -305,17 +305,21 @@ struct fsid_s typedef CODE int (*main_t)(int argc, FAR char *argv[]); -/* POSIX-like OS return values: */ +/* POSIX-like OS return values (not with NUTTX_NO_EXTENSIONS, see + * nuttx/compiler.h): + */ -#ifdef OK -# undef OK -#endif +#ifndef NUTTX_NO_EXTENSIONS +# ifdef OK +# undef OK +# endif enum { ERROR = -1, OK = 0 }; +#endif #ifndef __PTHREAD_ATTR_T_DEFINED struct pthread_attr_s;
