aboutsummaryrefslogtreecommitdiff
path: root/include/libcasio/cdefs.h
blob: d00639ba8f99842711f98f59b13e4431d1fb03c0 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* ****************************************************************************
 * libcasio/cdefs.h -- C helpers.
 * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
 *
 * This file is part of libcasio.
 * libcasio 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 3.0 of the License,
 * or (at your option) any later version.
 *
 * libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************* */
/* 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 libcasio defined namespace, so we want it to be redefined, in case. */

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

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

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

/* Check the library version. */

# define LIBCASIO_PREREQ(CASIO__MAJ, CASIO__MIN) \
	((CASIO__MAJ) >  (LIBCASIO_MAJOR) || \
	((CASIO__MAJ) == (LIBCASIO_MAJOR) && (CASIO__MIN) >= (LIBCASIO_MINOR)))

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

/* First, GCC. */

# if defined(CASIO_GNUC_PREREQ)
# elif defined(__GNUC__) && defined(__GNUC_MINOR__)
#  define CASIO_GNUC_PREREQ(CASIO__MAJ, CASIO__MIN) \
	((__GNUC__ << 16) + __GNUC_MINOR__ >= ((CASIO__MAJ) << 16) + (CASIO__MIN))
# else
#  define CASIO_GNUC_PREREQ(CASIO__MAJ, CASIO__MIN) 0
# endif

/* Then, Microsoft's Compiler. */

# if defined(CASIO_MSC_PREREQ) || defined(_MSC_VER)
#  define CASIO_MSC_PREREQ(CASIO__MAJ, CASIO__MIN) \
	(_MSC_VER >= (CASIO__MAJ) * 1000 + (CASIO__MIN))
# else
#  define CASIO_MSC_PREREQ(CASIO__MAJ, CASIO__MIN) 0
# endif

/* ---
 * Check for subsystems.
 * --- */

/* Macros defined by the `libcasio/config.h` header:
 * - `LIBCASIO_DISABLED_FILE`: can we use the standard FILE operations?
 * - `LIBCASIO_DISABLED_LIBUSB`: can we use libusb? */

/* Can we use the Linux and the MacOS/OS X listing?
 * XXX: what about Linux distributions not using the Linux standard
 * filesystem? */

# if defined(__linux__)
# else
#  define LIBCASIO_DISABLED_LINUX_SERIAL
# endif

# if defined(__APPLE__) && defined(__MACH__)
# else
#  define LIBCASIO_DISABLED_MAC_SERIAL
# endif

/* Can we use the POSIX (STREAMS) interface? */

# if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
# else
#  define LIBCASIO_DISABLED_STREAMS
# endif

/* Can we use the Windows (Win32/Win64) API? */

# if defined(_WIN16) || defined(_WIN32) || defined(_WIN64) \
	|| defined(__WINDOWS__)
# else
#  define LIBCASIO_DISABLED_WINDOWS
# endif

/* ---
 * Extern functions.
 * --- */

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

# define CASIO_EXTERN extern
# define CASIO_EXPORT
# define CASIO_LOCAL  static

/* ---
 * Enumerations.
 * --- */

/* Enumerations can be great thanks to the compiler: better warnings,
 * better debug, better coding! */

# if   defined(LIBCASIO_USE_ENUMS)
# elif defined(__STDC__) && __STDC__
#  define LIBCASIO_USE_ENUMS 1
# else /* K&R C, no enums! */
#  define LIBCASIO_USE_ENUMS 0
# endif

/* ---
 * C++ declarations and namespaces management.
 * --- */

/* libcasio is made in C. */

# if 0 /* hey, what about this? */
#  define CASIO_BEGIN_NAMESPACE namespace casio {
#  define   CASIO_END_NAMESPACE }
# endif

# ifdef  __cplusplus
#  define CASIO_BEGIN_NAMESPACE
#  define     CASIO_BEGIN_DECLS extern "C" {
#  define       CASIO_END_DECLS }
#  define   CASIO_END_NAMESPACE
# else
#  define CASIO_BEGIN_NAMESPACE
#  define     CASIO_BEGIN_DECLS
#  define       CASIO_END_DECLS
#  define   CASIO_END_NAMESPACE
# endif

/* ---
 * Various function attributes.
 * --- */

/* Warn if the result is unused.
 * To do that, we'll use the `CASIO_WUR` attribute. */

# if CASIO_GNUC_PREREQ(4, 0)
#  define CASIO_WUR __attribute__((warn_unused_result))
# elif CASIO_MSC_PREREQ(17, 0)
#  include <sal.h>
#  define CASIO_WUR _Check_return_
# else
#  define CASIO_WUR
# endif

/* Warn if the function is deprecated. */

# if CASIO_GNUC_PREREQ(3, 0)
#  define CASIO_DEPRECATED __attribute__((deprecated))
# else
#  define CASIO_DEPRECATED
# endif

# include "cdefs/integers.h"
# include "cdefs/endian.h"
#endif /* LIBCASIO_CDEFS_H */