aboutsummaryrefslogtreecommitdiff
path: root/include/libtio/cdefs.h
blob: 416fea9eb40e30779a47fbcff41744f7c059c650 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* Pre-ANSI C compilers don't support arguments (and argument types) in
 * function declarations. This macro is inspired from zlib.
 *
 * It is defined outside of the include guard because it is not in
 * the libtio defined namespace, so we want it to be redefined, in case. */

#if defined(OF)
#elif defined(__STDC__) && __STDC__
# define OF(TIO__ARGS) TIO__ARGS
#else
# define OF(TIO__ARGS) ()
#endif

/* "Normal start" of the file is here. */

#ifndef  LIBTIO_CDEFS_H
# define LIBTIO_CDEFS_H 20180710
# include "config.h"
# include <stddef.h>
# include <time.h>

/* Check the library version. */

# define TIO_PREREQ(TIO__MAJ, TIO__MIN) \
	((TIO__MAJ) >  (LIBTIO_MAJOR) || \
	((TIO__MAJ) == (LIBTIO_MAJOR) && (TIO__MIN) >= (LIBTIO_MINOR)))

/* ---
 * Check for compilers.
 * --- */

/* First, GCC. */

# if defined(TIO_GNUC_PREREQ)
# elif defined(__GNUC__) && defined(__GNUC_MINOR__)
#  define TIO_GNUC_PREREQ(TIO__MAJ, TIO__MIN) \
	((__GNUC__ << 16) + __GNUC_MINOR__ >= ((TIO__MAJ) << 16) + (TIO__MIN))
# else
#  define TIO_GNUC_PREREQ(TIO__MAJ, TIO__MIN) 0
# endif

/* Then, Microsoft's Compiler. */

# if defined(TIO_MSC_PREREQ) || defined(_MSC_VER)
#  define TIO_MSC_PREREQ(TIO__MAJ, TIO__MIN) \
	(_MSC_VER >= (TIO__MAJ) * 1000 + (TIO__MIN))
# else
#  define TIO_MSC_PREREQ(TIO__MAJ, TIO__MIN) 0
# endif

/* ---
 * Others.
 * --- */

/* Warn if the function is deprecated. */

# if TIO_GNUC_PREREQ(3, 0)
#  define TIO_DEPRECATED __attribute__((deprecated))
# else
#  define TIO_DEPRECATED
# endif

/* Some platforms require more than simply 'extern'.
 * Here are macros to control this. */

# define TIO_EXTERN(TYPE) \
	extern TYPE
# define TIO_NORETURN \
	__attribute__((noreturn)) extern void
# define TIO_LOCAL(TYPE) \
	static TYPE
# define TIO_HOOK(TYPE) \
	static TYPE

# define TIO_EXTERN_TYPE(TYPE) \
	TYPE
# define TIO_HOOK_TYPE(TYPE) \
	TYPE

# define TIO_LOCAL_DATA(TYPE) \
	static TYPE

/* Also, libtio is made in C, so we might as well define what we want
 * for C++. */

# ifdef  __cplusplus
#  define TIO_BEGIN_NAMESPACE namespace "libtio" {
#  define     TIO_BEGIN_DECLS extern "C" {
#  define       TIO_END_DECLS }
#  define   TIO_END_NAMESPACE }
# else
#  define TIO_BEGIN_NAMESPACE
#  define     TIO_BEGIN_DECLS
#  define       TIO_END_DECLS
#  define   TIO_END_NAMESPACE
# endif

/* Forward declare a structure. */

# define TIO_STRUCT(STRUCT_NAME, STRUCT_TYPEDEF) \
struct STRUCT_NAME; \
typedef struct STRUCT_NAME STRUCT_TYPEDEF;

/* ---
 * Utilities.
 * --- */

TIO_BEGIN_NAMESPACE
TIO_BEGIN_DECLS

/* Memory allocation utilities. */

TIO_EXTERN(void *) tio_alloc
	OF((size_t tio__count, size_t tio__size));
TIO_EXTERN(void) tio_free
	OF((void *tio__mem));

TIO_END_DECLS
TIO_END_NAMESPACE

#endif /* LIBTIO_CDEFS_H */