cmocka  0.3.2
cmocka_private.h
1 /*
2  * Copyright 2008 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CMOCKA_PRIVATE_H_
18 #define CMOCKA_PRIVATE_H_
19 
20 #include <cmocka.h>
21 
23 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
24 
26 #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
27 
29 #define ZERO_STRUCTP(x) do { if ((x) != NULL) memset((char *)(x), 0, sizeof(*(x))); } while(0)
30 
32 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
33 
35 #define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0)
36 
49 #define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
50 
54 #define discard_const_p(type, ptr) ((type *)discard_const(ptr))
55 
56 #endif /* CMOCKA_PRIVATE_H_ */