mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-04-08 12:02:33 +02:00
Add str_true_false()/str_false_true() helper to retur a "true" or "false" string literal. We found more than 10 cases currently exist in the tree. So these helpers can be used for these cases. This patch (of 3): Add str_true_false()/str_false_true() helper to return "true" or "false" string literal. Link: https://lkml.kernel.org/r/20240827024517.914100-1-lihongbo22@huawei.com Link: https://lkml.kernel.org/r/20240827024517.914100-2-lihongbo22@huawei.com Signed-off-by: Hongbo Li <lihongbo22@huawei.com> Cc: Andy Shevchenko <andy@kernel.org> Cc: Anna Schumaker <anna@kernel.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Kees Cook <kees@kernel.org> Cc: Matthew Wilcox <willy@infradead.org> Cc: Trond Myklebust <trondmy@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
63 lines
1.2 KiB
C
63 lines
1.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_STRING_CHOICES_H_
|
|
#define _LINUX_STRING_CHOICES_H_
|
|
|
|
#include <linux/types.h>
|
|
|
|
static inline const char *str_enable_disable(bool v)
|
|
{
|
|
return v ? "enable" : "disable";
|
|
}
|
|
|
|
static inline const char *str_enabled_disabled(bool v)
|
|
{
|
|
return v ? "enabled" : "disabled";
|
|
}
|
|
|
|
static inline const char *str_hi_lo(bool v)
|
|
{
|
|
return v ? "hi" : "lo";
|
|
}
|
|
#define str_lo_hi(v) str_hi_lo(!(v))
|
|
|
|
static inline const char *str_high_low(bool v)
|
|
{
|
|
return v ? "high" : "low";
|
|
}
|
|
#define str_low_high(v) str_high_low(!(v))
|
|
|
|
static inline const char *str_read_write(bool v)
|
|
{
|
|
return v ? "read" : "write";
|
|
}
|
|
#define str_write_read(v) str_read_write(!(v))
|
|
|
|
static inline const char *str_on_off(bool v)
|
|
{
|
|
return v ? "on" : "off";
|
|
}
|
|
|
|
static inline const char *str_yes_no(bool v)
|
|
{
|
|
return v ? "yes" : "no";
|
|
}
|
|
|
|
static inline const char *str_true_false(bool v)
|
|
{
|
|
return v ? "true" : "false";
|
|
}
|
|
#define str_false_true(v) str_true_false(!(v))
|
|
|
|
/**
|
|
* 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
|