From 6fe00cba53847664ba92f3dba9028846cd2d4ded Mon Sep 17 00:00:00 2001 From: loremmoqi <780939104@qq.com> Date: Sat, 11 Oct 2025 15:32:47 +0800 Subject: [PATCH 1/3] Fix stdio compatibility with Newlib >= 3.4.0 --- components/libc/posix/io/stdio/stdio.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/libc/posix/io/stdio/stdio.c b/components/libc/posix/io/stdio/stdio.c index 98816c1f281..77aa660e724 100644 --- a/components/libc/posix/io/stdio/stdio.c +++ b/components/libc/posix/io/stdio/stdio.c @@ -104,8 +104,12 @@ int rt_posix_stdio_set_console(const char* device_name, int mode) _GLOBAL_REENT->_stderr = std_console; } -#if (NEWLIB_VERSION_NUM < 30400U) || (NEWLIB_VERSION_NUM >= 40000U && NEWLIB_VERSION_NUM < 40300U) - _GLOBAL_REENT->__sdidinit = 1; /* __sdidinit is obselete */ +#if defined(_REENT_SMALL) || !defined(__sdidinit) + // Newlib >= 3.4.0 or small reent version: no __sdidinit field + // Do nothing +#else + // Older newlib versions (typically < 3.4.0) still define __sdidinit + _GLOBAL_REENT->__sdidinit = 1; #endif } From 443e5bacff7a580b3b189ce19e740f16e6286144 Mon Sep 17 00:00:00 2001 From: loremmoqi <780939104@qq.com> Date: Sat, 11 Oct 2025 21:26:47 +0800 Subject: [PATCH 2/3] Standard comments are in C++ style. --- components/libc/posix/io/stdio/stdio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/libc/posix/io/stdio/stdio.c b/components/libc/posix/io/stdio/stdio.c index 77aa660e724..a7edf49fd22 100644 --- a/components/libc/posix/io/stdio/stdio.c +++ b/components/libc/posix/io/stdio/stdio.c @@ -105,10 +105,10 @@ int rt_posix_stdio_set_console(const char* device_name, int mode) } #if defined(_REENT_SMALL) || !defined(__sdidinit) - // Newlib >= 3.4.0 or small reent version: no __sdidinit field - // Do nothing + /* Newlib >= 3.4.0 or small reent version: no __sdidinit field */ + /* Do nothing */ #else - // Older newlib versions (typically < 3.4.0) still define __sdidinit + /* Older newlib versions (typically < 3.4.0) still define __sdidinit */ _GLOBAL_REENT->__sdidinit = 1; #endif } From bf937621b50e12cc844b4d1285e38b0b774af02a Mon Sep 17 00:00:00 2001 From: loremmoqi <780939104@qq.com> Date: Sun, 12 Oct 2025 21:11:16 +0800 Subject: [PATCH 3/3] delete extra space at the end of this line 109 --- components/libc/posix/io/stdio/stdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/libc/posix/io/stdio/stdio.c b/components/libc/posix/io/stdio/stdio.c index a7edf49fd22..06d341d722e 100644 --- a/components/libc/posix/io/stdio/stdio.c +++ b/components/libc/posix/io/stdio/stdio.c @@ -106,7 +106,7 @@ int rt_posix_stdio_set_console(const char* device_name, int mode) #if defined(_REENT_SMALL) || !defined(__sdidinit) /* Newlib >= 3.4.0 or small reent version: no __sdidinit field */ - /* Do nothing */ + /* Do nothing */ #else /* Older newlib versions (typically < 3.4.0) still define __sdidinit */ _GLOBAL_REENT->__sdidinit = 1;