summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2021-05-03 13:48:49 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-05-03 13:55:29 +0200
commitd0f115bb774b4c013be2852296836dadd2d73aa4 (patch)
tree7df280596b69c1c37cb89d29389ee71f8bf68003 /lib
parent015d5be8d66386fb9386f565b9d0e04ca78f8061 (diff)
downloadbarebox-d0f115bb774b4c013be2852296836dadd2d73aa4.tar.gz
barebox-d0f115bb774b4c013be2852296836dadd2d73aa4.tar.xz
vsprintf: introduce %m shorthand for "%s", strerror(errno)
We have many places across the code base that use either do printf("%s..", errno_str()) or printf("%s..", strerror(errno). We already have %pe support for printing arbitrary errors and it's not much work to add %m to print errno as well. Do so. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20210503114901.13095-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/vsprintf.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 1d82adc733..237aab0c02 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -373,12 +373,21 @@ static char *pointer(const char *fmt, char *buf, const char *end, const void *pt
return raw_pointer(buf, end, ptr, field_width, precision, flags);
}
+static char *errno_string(char *buf, const char *end, int field_width, int precision, int flags)
+{
+ return string(buf, end, strerror(errno), field_width, precision, flags);
+}
#else
static char *pointer(const char *fmt, char *buf, const char *end, const void *ptr,
int field_width, int precision, int flags)
{
return raw_pointer(buf, end, ptr, field_width, precision, flags);
}
+
+static char *errno_string(char *buf, const char *end, int field_width, int precision, int flags)
+{
+ return buf;
+}
#endif
/**
@@ -569,6 +578,10 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
case 'u':
break;
+ case 'm':
+ str = errno_string(str, end, field_width, precision, flags);
+ continue;
+
default:
if (str < end)
*str = '%';