mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 14:53:47 +08:00
[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:
committed by
Alan C. Assis
parent
50fd02c789
commit
badb5c5ac6
@@ -163,6 +163,10 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream,
|
|||||||
uint16_t flags;
|
uint16_t flags;
|
||||||
int width;
|
int width;
|
||||||
int prec;
|
int prec;
|
||||||
|
|
||||||
|
/* For the %m format we may need the current `errno' value */
|
||||||
|
|
||||||
|
int saved_errno = errno;
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
#if defined (CONFIG_LIBC_LONG_LONG) || (ULONG_MAX > 4294967295UL)
|
#if defined (CONFIG_LIBC_LONG_LONG) || (ULONG_MAX > 4294967295UL)
|
||||||
@@ -911,6 +915,11 @@ flt_oper:
|
|||||||
size = 1;
|
size = 1;
|
||||||
goto str_lpad;
|
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':
|
||||||
case 'S':
|
case 'S':
|
||||||
#ifdef CONFIG_LIBC_NUMBERED_ARGS
|
#ifdef CONFIG_LIBC_NUMBERED_ARGS
|
||||||
|
|||||||
Reference in New Issue
Block a user