blob: 9026d298cabf7ac43e05be050156df6de8c5a7fb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
/*
* Copyright (c) 2024 Vaughn Nugent
*
* Package: noscrypt
* File: nc-util.c
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with noscrypt. If not, see http://www.gnu.org/licenses/.
*/
#pragma once
#ifndef NC_UTIL_H
#define NC_UTIL_H
/* NULL */
#ifndef NULL
#define NULL ((void*)0)
#endif /* !NULL */
#ifdef DEBUG
/* Must include assert.h for assertions */
#include <assert.h>
#define DEBUG_ASSERT(x) assert(x);
#define DEBUG_ASSERT2(x, message) assert(x && message);
/*
* Compiler enabled static assertion keywords are
* only available in C11 and later. Later versions
* have macros built-in from assert.h so we can use
* the static_assert macro directly.
*
* Static assertions are only used for testing such as
* sanity checks and this library targets the c89 standard
* so static_assret very likely will not be available.
*/
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define STATIC_ASSERT(x, m) static_assert(x, m)
#elif !defined(STATIC_ASSERT)
#define STATIC_ASSERT(x, m)
#pragma message("Static assertions are not supported by this language version")
#endif
#else
#define DEBUG_ASSERT(x)
#define DEBUG_ASSERT2(x, message)
#define STATIC_ASSERT(x, m)
#endif
#endif /* NC_UTIL_H */
|