[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.
This commit is contained in:
Javier Alonso 2024-12-23 15:30:39 +01:00 committed by Alan C. Assis
parent 50fd02c789
commit badb5c5ac6

View file

@ -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