printf-hook-builtin: Support GNU %m specifier
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
#include "test_suite.h"
|
#include "test_suite.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
static void verify(char *expected, char *format, ...)
|
static void verify(char *expected, char *format, ...)
|
||||||
{
|
{
|
||||||
FILE *mem;
|
FILE *mem;
|
||||||
@@ -45,6 +47,13 @@ START_TEST(test_printf_strings)
|
|||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST(test_printf_err)
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
verify((char*)strerror(errno), "%m");
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
START_TEST(test_printf_unsigned)
|
START_TEST(test_printf_unsigned)
|
||||||
{
|
{
|
||||||
verify("1 23 456", "%u %lu %llu", 1, (u_long)23, (u_int64_t)456);
|
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);
|
tcase_add_test(tc, test_printf_strings);
|
||||||
suite_add_tcase(s, tc);
|
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");
|
tc = tcase_create("unsiged");
|
||||||
tcase_add_test(tc, test_printf_unsigned);
|
tcase_add_test(tc, test_printf_unsigned);
|
||||||
suite_add_tcase(s, tc);
|
suite_add_tcase(s, tc);
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#define PRINTF_BUF_LEN 8192
|
#define PRINTF_BUF_LEN 8192
|
||||||
#define ARGS_MAX 3
|
#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);
|
slen = strlen(sarg);
|
||||||
goto is_string;
|
goto is_string;
|
||||||
}
|
}
|
||||||
|
case 'm':
|
||||||
|
{
|
||||||
|
/* glibc error string */
|
||||||
|
sarg = strerror(errno);
|
||||||
|
slen = strlen(sarg);
|
||||||
|
goto is_string;
|
||||||
|
}
|
||||||
is_string:
|
is_string:
|
||||||
{
|
{
|
||||||
char sch;
|
char sch;
|
||||||
|
|||||||
Reference in New Issue
Block a user