xref: /freebsd/sys/compat/linuxkpi/common/include/linux/string_helpers.h (revision ae1084ff01bf9d9a9a2c56caf6c7095f3e96f579)
138138bebSJean-Sébastien Pédron /*-
238138bebSJean-Sébastien Pédron  * SPDX-License-Identifier: BSD-2-Clause
338138bebSJean-Sébastien Pédron  *
438138bebSJean-Sébastien Pédron  * Copyright (c) 2023 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
538138bebSJean-Sébastien Pédron  *
638138bebSJean-Sébastien Pédron  * Redistribution and use in source and binary forms, with or without
738138bebSJean-Sébastien Pédron  * modification, are permitted provided that the following conditions
838138bebSJean-Sébastien Pédron  * are met:
938138bebSJean-Sébastien Pédron  * 1. Redistributions of source code must retain the above copyright
1038138bebSJean-Sébastien Pédron  *    notice unmodified, this list of conditions, and the following
1138138bebSJean-Sébastien Pédron  *    disclaimer.
1238138bebSJean-Sébastien Pédron  * 2. Redistributions in binary form must reproduce the above copyright
1338138bebSJean-Sébastien Pédron  *    notice, this list of conditions and the following disclaimer in the
1438138bebSJean-Sébastien Pédron  *    documentation and/or other materials provided with the distribution.
1538138bebSJean-Sébastien Pédron  *
1638138bebSJean-Sébastien Pédron  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1738138bebSJean-Sébastien Pédron  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1838138bebSJean-Sébastien Pédron  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1938138bebSJean-Sébastien Pédron  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2038138bebSJean-Sébastien Pédron  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2138138bebSJean-Sébastien Pédron  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2238138bebSJean-Sébastien Pédron  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2338138bebSJean-Sébastien Pédron  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2438138bebSJean-Sébastien Pédron  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2538138bebSJean-Sébastien Pédron  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2638138bebSJean-Sébastien Pédron  */
2738138bebSJean-Sébastien Pédron 
2838138bebSJean-Sébastien Pédron #ifndef	_LINUXKPI_LINUX_STRING_HELPERS_H_
2938138bebSJean-Sébastien Pédron #define	_LINUXKPI_LINUX_STRING_HELPERS_H_
3038138bebSJean-Sébastien Pédron 
3138138bebSJean-Sébastien Pédron #include <sys/types.h>
3238138bebSJean-Sébastien Pédron 
3338138bebSJean-Sébastien Pédron static inline const char *
str_yes_no(bool value)3438138bebSJean-Sébastien Pédron str_yes_no(bool value)
3538138bebSJean-Sébastien Pédron {
3638138bebSJean-Sébastien Pédron 	if (value)
3738138bebSJean-Sébastien Pédron 		return "yes";
3838138bebSJean-Sébastien Pédron 	else
3938138bebSJean-Sébastien Pédron 		return "no";
4038138bebSJean-Sébastien Pédron }
4138138bebSJean-Sébastien Pédron 
42*ae1084ffSVladimir Kondratyev static inline const char *
str_on_off(bool value)43*ae1084ffSVladimir Kondratyev str_on_off(bool value)
44*ae1084ffSVladimir Kondratyev {
45*ae1084ffSVladimir Kondratyev 	if (value)
46*ae1084ffSVladimir Kondratyev 		return "on";
47*ae1084ffSVladimir Kondratyev 	else
48*ae1084ffSVladimir Kondratyev 		return "off";
49*ae1084ffSVladimir Kondratyev }
50*ae1084ffSVladimir Kondratyev 
51*ae1084ffSVladimir Kondratyev static inline const char *
str_enabled_disabled(bool value)52*ae1084ffSVladimir Kondratyev str_enabled_disabled(bool value)
53*ae1084ffSVladimir Kondratyev {
54*ae1084ffSVladimir Kondratyev 	if (value)
55*ae1084ffSVladimir Kondratyev 		return "enabled";
56*ae1084ffSVladimir Kondratyev 	else
57*ae1084ffSVladimir Kondratyev 		return "disabled";
58*ae1084ffSVladimir Kondratyev }
59*ae1084ffSVladimir Kondratyev 
60*ae1084ffSVladimir Kondratyev static inline const char *
str_enable_disable(bool value)61*ae1084ffSVladimir Kondratyev str_enable_disable(bool value)
62*ae1084ffSVladimir Kondratyev {
63*ae1084ffSVladimir Kondratyev 	if (value)
64*ae1084ffSVladimir Kondratyev 		return "enable";
65*ae1084ffSVladimir Kondratyev 	else
66*ae1084ffSVladimir Kondratyev 		return "disable";
67*ae1084ffSVladimir Kondratyev }
68*ae1084ffSVladimir Kondratyev 
69*ae1084ffSVladimir Kondratyev #endif
70