lkml.org 
[lkml]   [2018]   [Oct]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH 3/7] kernel.h: implement fmtmatch() wrapper around fmtcheck()
Date
Some users may prefer to check a "user-supplied" string upfront and
return EINVAL rather than using the the template as a fallback for
printf'ing later. fmtmatch() is simply a shorthand for

fmtcheck(a, b, c | FMTCHECK_SILENT) == a.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
include/linux/kernel.h | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 8e9154e100c3..c2b710426227 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -507,11 +507,18 @@ _fmtcheck(const char *fmt, const char *tmpl, unsigned flags)
return fmt;
}
#endif
+
+static inline bool
+_fmtmatch(const char *fmt, const char *tmpl, unsigned flags)
+{
+ return _fmtcheck(fmt, tmpl, flags | FMTCHECK_SILENT) == fmt;
+}
/*
* Use of fmtcheck is pointless if the template is not a string
* literal, so try to enforce that.
*/
#define fmtcheck(fmt, tmpl, flags) _fmtcheck(fmt, "" tmpl "", flags)
+#define fmtmatch(fmt, tmpl, flags) _fmtmatch(fmt, "" tmpl "", flags)

extern __scanf(2, 3)
int sscanf(const char *, const char *, ...);
--
2.19.1.6.gbde171bbf5
\
 
 \ /
  Last update: 2018-10-27 01:25    [W:0.297 / U:0.832 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site