Virgil IoT KIT
macros.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2020 Virgil Security, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // (1) Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // (2) Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in
14 // the documentation and/or other materials provided with the
15 // distribution.
16 //
17 // (3) Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
22 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 // DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
34 
75 #ifndef VS_MACROS_H
76 #define VS_MACROS_H
77 
79 
90 #define CHECK(CONDITION, MESSAGE, ...) do { \
91  if (!(CONDITION)) { \
92  VS_LOG_ERROR((MESSAGE), ##__VA_ARGS__); \
93  goto terminate; \
94  } \
95  } while(0)
96 
108 #define CHECK_RET(CONDITION, RETCODE, MESSAGE, ...) do { \
109  if (!(CONDITION)) { \
110  VS_LOG_ERROR((MESSAGE), ##__VA_ARGS__); \
111  return (RETCODE); \
112  } \
113  } while(0)
114 
125 #define BOOL_CHECK(CONDITION, MESSAGE, ...) CHECK((CONDITION), (MESSAGE), ##__VA_ARGS__)
126 
137 #define BOOL_CHECK_RET(CONDITION, MESSAGE, ...) CHECK_RET((CONDITION), false, (MESSAGE), ##__VA_ARGS__)
138 
151 #define MEMCMP_CHECK(BUF1, BUF2, SIZE) \
152  CHECK(VS_IOT_MEMCMP((BUF1), (BUF2), (SIZE)) == 0, \
153  #BUF1 " is not equal to " #BUF2 " while comparing %d bytes", \
154  (int)(SIZE))
155 
171 #define MEMCMP_CHECK_RET(BUF1, BUF2, SIZE, RETCODE) \
172  CHECK_RET(VS_IOT_MEMCMP((BUF1), (BUF2), (SIZE)) == 0, (RETCODE), \
173  #BUF1 " is not equal to " #BUF2 " while comparing %d bytes", \
174  (int)(SIZE))
175 
185 #define CHECK_NOT_ZERO(ARG) CHECK((ARG), "Argument " #ARG " must not be zero")
186 
199 #define CHECK_NOT_ZERO_RET(ARG, RETCODE) CHECK_RET((ARG), (RETCODE), "Argument " #ARG " must not be zero") \
200 
201 #endif // VS_MACROS_H
logger.h
Logger implementation.