[PATCH v3 05/12] tools/nolibc: implement %m if errno is not defined

Benjamin Berg posted 12 patches 1 week ago
[PATCH v3 05/12] tools/nolibc: implement %m if errno is not defined
Posted by Benjamin Berg 1 week ago
From: Benjamin Berg <benjamin.berg@intel.com>

For improved compatibility, print %m as "unknown error" when nolibc is
compiled using NOLIBC_IGNORE_ERRNO.

Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
---
 tools/include/nolibc/stdio.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h
index 724d05ce6962..1f16dab2ac88 100644
--- a/tools/include/nolibc/stdio.h
+++ b/tools/include/nolibc/stdio.h
@@ -321,11 +321,13 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char
 				if (!outstr)
 					outstr="(null)";
 			}
-#ifndef NOLIBC_IGNORE_ERRNO
 			else if (c == 'm') {
+#ifdef NOLIBC_IGNORE_ERRNO
+				outstr = "unknown error";
+#else
 				outstr = strerror(errno);
-			}
 #endif /* NOLIBC_IGNORE_ERRNO */
+			}
 			else if (c == '%') {
 				/* queue it verbatim */
 				continue;
-- 
2.51.0
Re: [PATCH v3 05/12] tools/nolibc: implement %m if errno is not defined
Posted by Thomas Weißschuh 6 days, 8 hours ago
On 2025-09-24 16:20:52+0200, Benjamin Berg wrote:
> From: Benjamin Berg <benjamin.berg@intel.com>
> 
> For improved compatibility, print %m as "unknown error" when nolibc is
> compiled using NOLIBC_IGNORE_ERRNO.
> 
> Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>

Thanks for taking care of this.

Acked-by: Thomas Weißschuh <linux@weissschuh.net>

> ---
>  tools/include/nolibc/stdio.h | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h
> index 724d05ce6962..1f16dab2ac88 100644
> --- a/tools/include/nolibc/stdio.h
> +++ b/tools/include/nolibc/stdio.h
> @@ -321,11 +321,13 @@ int __nolibc_printf(__nolibc_printf_cb cb, intptr_t state, size_t n, const char
>  				if (!outstr)
>  					outstr="(null)";
>  			}
> -#ifndef NOLIBC_IGNORE_ERRNO
>  			else if (c == 'm') {
> +#ifdef NOLIBC_IGNORE_ERRNO
> +				outstr = "unknown error";
> +#else
>  				outstr = strerror(errno);
> -			}
>  #endif /* NOLIBC_IGNORE_ERRNO */
> +			}
>  			else if (c == '%') {
>  				/* queue it verbatim */
>  				continue;
> -- 
> 2.51.0
>