Skip to content

Commit badb5c5

Browse files
Javinator9889Alan C. Assis
authored andcommitted
[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.
1 parent 50fd02c commit badb5c5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

libs/libc/stdio/lib_libvsprintf.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream,
163163
uint16_t flags;
164164
int width;
165165
int prec;
166+
167+
/* For the %m format we may need the current `errno' value */
168+
169+
int saved_errno = errno;
166170
union
167171
{
168172
#if defined (CONFIG_LIBC_LONG_LONG) || (ULONG_MAX > 4294967295UL)
@@ -911,6 +915,11 @@ static int vsprintf_internal(FAR struct lib_outstream_s *stream,
911915
size = 1;
912916
goto str_lpad;
913917

918+
case 'm': /* Print error message (%m) */
919+
pnt = strerror(saved_errno);
920+
size = strlen(pnt); /* Adjusting the size is not supported by %m */
921+
goto str_lpad;
922+
914923
case 's':
915924
case 'S':
916925
#ifdef CONFIG_LIBC_NUMBERED_ARGS

0 commit comments

Comments
 (0)