Skip to content

Commit 9ca5fac

Browse files
mwajdeczkees
authored andcommitted
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>
1 parent 08d45ee commit 9ca5fac

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

include/linux/string_choices.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,15 @@ static inline const char *str_yes_no(bool v)
4242
return v ? "yes" : "no";
4343
}
4444

45+
/**
46+
* str_plural - Return the simple pluralization based on English counts
47+
* @num: Number used for deciding pluralization
48+
*
49+
* If @num is 1, returns empty string, otherwise returns "s".
50+
*/
51+
static inline const char *str_plural(size_t num)
52+
{
53+
return num == 1 ? "" : "s";
54+
}
55+
4556
#endif

0 commit comments

Comments
 (0)