projects
/
linux.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
08d45ee
)
lib/string_choices: Add str_plural() helper
author
Michal Wajdeczko
<michal.wajdeczko@intel.com>
Wed, 14 Feb 2024 16:50:15 +0000
(17:50 +0100)
committer
Kees Cook
<keescook@chromium.org>
Thu, 29 Feb 2024 21:38:01 +0000
(13:38 -0800)
Add str_plural() helper to replace existing open implementations
used by many drivers and help improve future user facing messages.
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Link:
https://lore.kernel.org/r/20240214165015.1656-1-michal.wajdeczko@intel.com
Signed-off-by: Kees Cook <keescook@chromium.org>
include/linux/string_choices.h
patch
|
blob
|
history
diff --git
a/include/linux/string_choices.h
b/include/linux/string_choices.h
index 3c1091941eb89759c16efe2e301cb8a37f06d62c..d9ebe20229f810d1f002c14ef0e918a0a851123d 100644
(file)
--- a/
include/linux/string_choices.h
+++ b/
include/linux/string_choices.h
@@
-42,4
+42,15
@@
static inline const char *str_yes_no(bool v)
return v ? "yes" : "no";
}
+/**
+ * str_plural - Return the simple pluralization based on English counts
+ * @num: Number used for deciding pluralization
+ *
+ * If @num is 1, returns empty string, otherwise returns "s".
+ */
+static inline const char *str_plural(size_t num)
+{
+ return num == 1 ? "" : "s";
+}
+
#endif