2 * *****************************************************************************
4 * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright (c) 2018-2021 Gavin D. Howard and contributors.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * * Redistributions of source code must retain the above copyright notice, this
12 * list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * *****************************************************************************
32 * All bc status codes.
42 #define BC_ENABLED (1)
46 #define DC_ENABLED (1)
50 #ifndef __AFL_HAVE_MANUAL_CONTROL
51 #error Must compile with afl-clang-fast for fuzzing
52 #endif // __AFL_HAVE_MANUAL_CONTROL
53 #endif // BC_ENABLE_AFL
55 #ifndef BC_ENABLE_MEMCHECK
56 #define BC_ENABLE_MEMCHECK (0)
57 #endif // BC_ENABLE_MEMCHECK
61 typedef enum BcStatus {
63 BC_STATUS_SUCCESS = 0,
65 BC_STATUS_ERROR_PARSE,
67 BC_STATUS_ERROR_FATAL,
76 BC_ERR_MATH_NON_INTEGER,
78 BC_ERR_MATH_DIVIDE_BY_ZERO,
80 BC_ERR_FATAL_ALLOC_ERR,
82 BC_ERR_FATAL_FILE_ERR,
83 BC_ERR_FATAL_BIN_FILE,
84 BC_ERR_FATAL_PATH_DIR,
86 BC_ERR_FATAL_OPTION_NO_ARG,
87 BC_ERR_FATAL_OPTION_ARG,
92 BC_ERR_EXEC_READ_EXPR,
99 BC_ERR_EXEC_UNDEF_FUNC,
100 BC_ERR_EXEC_VOID_VAL,
105 BC_ERR_PARSE_COMMENT,
109 BC_ERR_PARSE_EMPTY_EXPR,
113 BC_ERR_PARSE_NO_AUTO,
114 BC_ERR_PARSE_DUP_LOCAL,
116 BC_ERR_PARSE_RET_VOID,
117 BC_ERR_PARSE_REF_VAR,
119 BC_ERR_POSIX_NAME_LEN,
120 BC_ERR_POSIX_COMMENT,
125 BC_ERR_POSIX_REL_POS,
126 BC_ERR_POSIX_MULTIREL,
128 BC_ERR_POSIX_EXP_NUM,
137 BC_ERR_POSIX_START = BC_ERR_POSIX_NAME_LEN,
138 BC_ERR_POSIX_END = BC_ERR_POSIX_BRACE,
143 #define BC_ERR_IDX_MATH (0)
144 #define BC_ERR_IDX_PARSE (1)
145 #define BC_ERR_IDX_EXEC (2)
146 #define BC_ERR_IDX_FATAL (3)
147 #define BC_ERR_IDX_NELEMS (4)
150 #define BC_ERR_IDX_WARN (BC_ERR_IDX_NELEMS)
153 #define BC_UNUSED(e) ((void) (e))
156 #define BC_LIKELY(e) (e)
160 #define BC_UNLIKELY(e) (e)
161 #endif // BC_UNLIKELY
163 #define BC_ERR(e) BC_UNLIKELY(e)
164 #define BC_NO_ERR(s) BC_LIKELY(s)
166 #ifndef BC_DEBUG_CODE
167 #define BC_DEBUG_CODE (0)
168 #endif // BC_DEBUG_CODE
170 #if __STDC_VERSION__ >= 201100L
171 #include <stdnoreturn.h>
172 #define BC_NORETURN _Noreturn
173 #else // __STDC_VERSION__
175 #define BC_MUST_RETURN
176 #endif // __STDC_VERSION__
178 #if defined(__clang__) || defined(__GNUC__)
179 #if defined(__has_attribute)
180 #if __has_attribute(fallthrough)
181 #define BC_FALLTHROUGH __attribute__((fallthrough));
182 #else // __has_attribute(fallthrough)
183 #define BC_FALLTHROUGH
184 #endif // __has_attribute(fallthrough)
185 #else // defined(__has_attribute)
186 #define BC_FALLTHROUGH
187 #endif // defined(__has_attribute)
188 #else // defined(__clang__) || defined(__GNUC__)
189 #define BC_FALLTHROUGH
190 #endif // defined(__clang__) || defined(__GNUC__)
192 // Workarounds for AIX's POSIX incompatibility.
194 #define SIZE_MAX __SIZE_MAX__
197 #define UINTMAX_C __UINTMAX_C
200 #define UINT32_C __UINT32_C
202 #ifndef UINT_FAST32_MAX
203 #define UINT_FAST32_MAX __UINT_FAST32_MAX__
204 #endif // UINT_FAST32_MAX
206 #define UINT16_MAX __UINT16_MAX__
208 #ifndef SIG_ATOMIC_MAX
209 #define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__
210 #endif // SIG_ATOMIC_MAX
212 #endif // BC_STATUS_H