printf-hook-builtin: Support GNU %m specifier

This commit is contained in:
Martin Willi
2013-10-11 11:06:09 +02:00
parent cabe5c0ff4
commit 7e6a4cdc84
2 changed files with 21 additions and 0 deletions
+13
View File
@@ -15,6 +15,8 @@
#include "test_suite.h"
#include <errno.h>
static void verify(char *expected, char *format, ...)
{
FILE *mem;
@@ -45,6 +47,13 @@ START_TEST(test_printf_strings)
}
END_TEST
START_TEST(test_printf_err)
{
errno = EINVAL;
verify((char*)strerror(errno), "%m");
}
END_TEST
START_TEST(test_printf_unsigned)
{
verify("1 23 456", "%u %lu %llu", 1, (u_long)23, (u_int64_t)456);
@@ -93,6 +102,10 @@ Suite *printf_suite_create()
tcase_add_test(tc, test_printf_strings);
suite_add_tcase(s, tc);
tc = tcase_create("err");
tcase_add_test(tc, test_printf_err);
suite_add_tcase(s, tc);
tc = tcase_create("unsiged");
tcase_add_test(tc, test_printf_unsigned);
suite_add_tcase(s, tc);
@@ -46,6 +46,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#define PRINTF_BUF_LEN 8192
#define ARGS_MAX 3
@@ -682,6 +683,13 @@ int builtin_vsnprintf(char *buffer, size_t n, const char *format, va_list ap)
slen = strlen(sarg);
goto is_string;
}
case 'm':
{
/* glibc error string */
sarg = strerror(errno);
slen = strlen(sarg);
goto is_string;
}
is_string:
{
char sch;