1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to you under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14  * implied.  See the License for the specific language governing
15  * permissions and limitations under the License.
16  */
17 #ifndef AVRO_PRIVATE_H
18 #define AVRO_PRIVATE_H
19 #ifdef __cplusplus
20 extern "C" {
21 #define CLOSE_EXTERN }
22 #else
23 #define CLOSE_EXTERN
24 #endif
25 
26 #include <errno.h>
27 
28 #include "avro/errors.h"
29 #include "avro/platform.h"
30 
31 #ifdef HAVE_CONFIG_H
32 /* This is only true for now in the autotools build */
33 #include "config.h"
34 #endif
35 
36 #ifdef _WIN32
37 #define snprintf _snprintf
38 #endif
39 
40 /* Note that AVRO_PLATFORM_IS_BIG_ENDIAN is *always* defined. It is
41  * either TRUE (1) or FALSE (0).
42  */
43 #ifdef _WIN32
44   #define AVRO_PLATFORM_IS_BIG_ENDIAN (0)
45 #else // UNIX
46   #include <sys/param.h>
47   #if BYTE_ORDER == BIG_ENDIAN
48     #define AVRO_PLATFORM_IS_BIG_ENDIAN (1)
49   #else
50     #define AVRO_PLATFORM_IS_BIG_ENDIAN (0)
51   #endif
52 #endif
53 
54 /* Add definition of EILSEQ if it is not defined in errno.h. */
55 #include <errno.h>
56 #ifndef EILSEQ
57 #define EILSEQ 138
58 #endif
59 
60 
61 #define check(rval, call) { rval = call; if(rval) return rval; }
62 
63 #define check_set(rval, call, ...)			\
64 	{						\
65 		rval = call;				\
66 		if (rval) {				\
67 			avro_set_error(__VA_ARGS__);	\
68 			return rval;			\
69 		}					\
70 	}
71 
72 #define check_prefix(rval, call, ...)			\
73 	{						\
74 		rval = call;				\
75 		if (rval) {				\
76 			avro_prefix_error(__VA_ARGS__);	\
77 			return rval;			\
78 		}					\
79 	}
80 
81 #define check_param(result, test, name)					\
82 	{								\
83 		if (!(test)) {						\
84 			avro_set_error("Invalid " name " in %s",	\
85 				       __FUNCTION__);			\
86 			return result;					\
87 		}							\
88 	}
89 
90 #define AVRO_UNUSED(var) (void)var;
91 
92 #define container_of(ptr_, type_, member_)  \
93     ((type_ *)((char *)ptr_ - (size_t)&((type_ *)0)->member_))
94 
95 #define nullstrcmp(s1, s2) \
96     (((s1) && (s2)) ? strcmp(s1, s2) : ((s1) || (s2)))
97 
98 CLOSE_EXTERN
99 #endif
100