Skip to content

Commit

Permalink
lib/string_choices: Add str_plural() helper
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Michal Wajdeczko authored and Kees Cook committed Feb 29, 2024
1 parent 08d45ee commit 9ca5fac
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/linux/string_choices.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9ca5fac

Please sign in to comment.