Good afternoon NuttX devs, I hope this email finds you well. First of all, Merry Christmas! I have just submitted a PR to the NuttX repo regarding a missing feature in the syslog module. The IEEE Std 1003.1-2024 states that the syslog() call shall accept the %m modifier, which causes the current strerror to be printed - it is a shorthand to "%s", strerror(errno).
The PR is available at https://github.com/apache/nuttx/pull/15320. Have a nice day, Javier Alonso Silva (he, him, his) Geotab Embedded Systems Developer | GEUR *Quickly schedule a meeting <https://calendar.app.google/DRoGm4sLw89JC8At6>* Toll-free Visit +34 900 535 371 www.geotab.com/es Twitter <https://twitter.com/geotab> | Facebook <https://www.facebook.com/Geotab> | YouTube <https://www.youtube.com/user/MyGeotab> | LinkedIn <https://www.linkedin.com/company/geotab/>
From 203505b4a2f2d5798fa107aeefc013ebeed5292f Mon Sep 17 00:00:00 2001 From: Javier Alonso <javieralo...@geotab.com> Date: Mon, 23 Dec 2024 15:30:39 +0100 Subject: [PATCH] [POSIX][Bug] syslog: Add support for `%m` modifier The POSIX standard states that the `syslog()` function generates the body from the message and arguments the same way as `printf()`, > except that the additional conversion specification `%m` shall be > recognized; *https://pubs.opengroup.org/onlinepubs/009695399/functions/syslog.html* What most of the implementations do is to leverage the processing to `vsprintf` internals, to reduce code duplicity. This means the `%m` modifier is present on almost all `printf` implementations. Take the following code snippet as an example: https://onlinegdb.com/YdR9pU6KS. Therefore, for `syslog` to support such a specification, the underlying library shall be updated to support it too. Signed-off-by: Javier Alonso <javieralo...@geotab.com> --- libs/libc/stdio/lib_libvsprintf.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libs/libc/stdio/lib_libvsprintf.c b/libs/libc/stdio/lib_libvsprintf.c index 610a6a42d9..4589154d5d 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 -- 2.47.1