summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorMichal Wajdeczko <michal.wajdeczko@intel.com>2024-02-14 19:50:15 +0300
committerKees Cook <keescook@chromium.org>2024-03-01 00:38:01 +0300
commit9ca5facd0400f610f3f7f71aeb7fc0b949a48c67 (patch)
tree63383d5e3e84cfa66c550985ed1e178ad61edcb0 /include/linux
parent08d45ee84bb2650e237e150caca87cc4ded9b3e2 (diff)
downloadlinux-9ca5facd0400f610f3f7f71aeb7fc0b949a48c67.tar.xz
lib/string_choices: Add str_plural() helper
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>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/string_choices.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/linux/string_choices.h b/include/linux/string_choices.h
index 3c1091941eb8..d9ebe20229f8 100644
--- 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