diff --git a/libs/libc/stdio/lib_libvsprintf.c b/libs/libc/stdio/lib_libvsprintf.c index 610a6a42d99..4589154d5d8 100644 --- a/libs/libc/stdio/lib_libvsprintf.c +++ b/libs/libc/stdio/lib_libvsprintf.c @@ -163,6 +163,10 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream, uint16_t flags; int width; int prec; + + /* For the %m format we may need the current `errno' value */ + + int saved_errno = errno; union { #if defined (CONFIG_LIBC_LONG_LONG) || (ULONG_MAX > 4294967295UL) @@ -911,6 +915,11 @@ flt_oper: size = 1; goto str_lpad; + case 'm': /* Print error message (%m) */ + pnt = strerror(saved_errno); + size = strlen(pnt); /* Adjusting the size is not supported by %m */ + goto str_lpad; + case 's': case 'S': #ifdef CONFIG_LIBC_NUMBERED_ARGS