os: support %c in pnprintf

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Peter Hutterer 2013-02-14 16:19:34 +10:00
parent 58ef34ee6d
commit d903d17d7f
2 changed files with 12 additions and 0 deletions

View File

@ -450,6 +450,13 @@ pnprintf(char *string, size_t size, const char *f, va_list args)
string[s_idx++] = number[i];
}
break;
case 'c':
{
char c = va_arg(args, int);
if (s_idx < size - 1)
string[s_idx++] = c;
}
break;
case '%':
string[s_idx++] = '%';
break;

View File

@ -201,6 +201,11 @@ static void logging_format(void)
read_log_msg(logmsg);
assert(strcmp(logmsg, "(EE) test %\n") == 0);
/* character */
LogMessageVerbSigSafe(X_ERROR, -1, "test %c\n", 'a');
read_log_msg(logmsg);
assert(strcmp(logmsg, "(EE) test a\n") == 0);
/* string substitution */
LogMessageVerbSigSafe(X_ERROR, -1, "%s\n", "substituted string");
read_log_msg(logmsg);