2 * nut_bool.h - Network UPS Tools boolean type definitions
3 * which should ensure a "nut_bool_t" name with
4 * lower-case values "true" and "false"
6 * Inspired by earlier efforts and numerous definitions in NUT codebase.
7 * Copyright (C) 2024 Jim Klimov <jimklimov+nut@gmail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #ifndef NUT_BOOL_H_SEEN
25 #define NUT_BOOL_H_SEEN 1
33 /* "config.h" is generated by autotools and lacks a header guard, so
34 * we use an unambiguously named macro we know we must have, as one.
35 * It must be the first header: be sure to know all about system config.
37 #ifndef NUT_NETVERSION
41 /* See also https://en.cppreference.com/w/cpp/header/cstdbool for more
42 * info about what should be available where per standard approach. */
44 # if defined HAVE_CSTDBOOL_H || defined HAVE_CSTDBOOL
47 # ifdef HAVE_STDBOOL_H
53 # ifdef HAVE_STDBOOL_H
58 /* Is the goal achieved by the system headers or compiler itself,
59 * so we can just alias to existing type and its values? */
60 #if defined __bool_true_false_are_defined && __bool_true_false_are_defined
61 typedef bool nut_bool_t
;
62 #elif defined FOUND__BOOL_TYPE && defined HAVE__BOOL_VALUE_LOWERCASE
63 typedef FOUND__BOOL_TYPE nut_bool_t
;
64 #elif defined FOUND_BOOL_TYPE && defined HAVE_BOOL_VALUE_LOWERCASE
65 typedef FOUND_BOOL_TYPE nut_bool_t
;
66 #elif defined FOUND_BOOLEAN_TYPE && defined HAVE_BOOLEAN_VALUE_LOWERCASE
67 typedef FOUND_BOOLEAN_TYPE nut_bool_t
;
68 #elif defined FOUND_BOOL_T_TYPE && defined HAVE_BOOL_T_VALUE_LOWERCASE
69 typedef FOUND_BOOL_T_TYPE nut_bool_t
;
71 /* Need a new type; can we use an enum with lower-case values? */
72 # if (defined true && defined false) || defined HAVE__BOOL_VALUE_LOWERCASE || defined HAVE_BOOL_VALUE_LOWERCASE || defined HAVE_BOOLEAN_VALUE_LOWERCASE || defined HAVE_BOOL_T_VALUE_LOWERCASE
73 /* Lower-case true/false are known */
74 # if defined FOUND__BOOL_TYPE
75 /* Got a C99 built-in mandated by the standard */
76 typedef FOUND__BOOL_TYPE nut_bool_t
;
78 typedef int nut_bool_t
;
80 # elif defined FOUND__BOOL_VALUE_TRUE && defined FOUND__BOOL_VALUE_FALSE
81 typedef enum nut_bool_enum
{ false = FOUND__BOOL_VALUE_FALSE
, true = FOUND__BOOL_VALUE_TRUE
} nut_bool_t
;
82 # elif defined FOUND_BOOL_VALUE_TRUE && defined FOUND_BOOL_VALUE_FALSE
83 typedef enum nut_bool_enum
{ false = FOUND_BOOL_VALUE_FALSE
, true = FOUND_BOOL_VALUE_TRUE
} nut_bool_t
;
84 # elif defined FOUND_BOOLEAN_VALUE_TRUE && defined FOUND_BOOLEAN_VALUE_FALSE
85 typedef enum nut_bool_enum
{ false = FOUND_BOOLEAN_VALUE_FALSE
, true = FOUND_BOOLEAN_VALUE_TRUE
} nut_bool_t
;
86 # elif defined FOUND_BOOL_T_VALUE_TRUE && defined FOUND_BOOL_T_VALUE_FALSE
87 typedef enum nut_bool_enum
{ false = FOUND_BOOL_T_VALUE_FALSE
, true = FOUND_BOOL_T_VALUE_TRUE
} nut_bool_t
;
89 typedef enum nut_bool_enum
{ false = 0, true = 1 } nut_bool_t
;
99 #endif /* NUT_BOOL_H_SEEN */