das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
defs.h
Go to the documentation of this file.
1/* Copyright (C) 2020 Chris Piker <chris-piker@uiowa.edu>
2 *
3 * This file is part of das2C, the Core Das2 C Library.
4 *
5 * das2C is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License version 2.1 as published
7 * by the Free Software Foundation.
8 *
9 * das2C is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * version 2.1 along with das2C; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18
25#include <limits.h>
26#include <stdbool.h>
27#include <stdint.h>
28#include <stddef.h>
29
30
31#ifndef _das_defs_h_
32#define _das_defs_h_
33
34/* Get compile time byte order, results in faster code that avoids
35 * runtime checks. For some newer chips this may not work as the
36 * processor can be switched from big endian to little endian at runtime.
37 *
38 * At the end of the day either HOST_IS_LSB_FIRST will be defined, or it won't.
39 * If this macro is defined then the host computer stores the least significant
40 * byte of a word in the lowest address, i.e. it's a little endian machine. If
41 * this macro is not defined then the host computer stores the list significant
42 * byte of a word in the highest address, i.e. it a big endian machine.
43 */
44#if defined __linux || defined __APPLE__
45
46#if defined __linux
47#include <endian.h>
48#elif defined __APPLE__
49#include <machine/endian.h>
50#endif
51
52#if __BYTE_ORDER == __LITTLE_ENDIAN
53#define HOST_IS_LSB_FIRST
54#else
55#undef HOST_IS_LSB_FIRST
56#endif
57
58#if defined __LP64__
59#define HOST_IS_64_BIT
60#endif
61
62#else /* End Linux Section */
63
64#ifdef __sun
65
66#include <sys/isa_defs.h>
67#ifdef _LITTLE_ENDIAN
68#define HOST_IS_LSB_FIRST
69#else
70#undef HOST_IS_LSB_FIRST
71#endif
72
73#else
74
75#ifdef _WIN32
76
80#define HOST_IS_LSB_FIRST
81
82#ifdef _WIN64
83#define HOST_IS_64_BIT
84#endif
85
86#else
87
88
89#ifdef __EMSCRIPTEN__
90/* Web assembly environment is defined as little endian */
91#define HOST_IS_LSB_FIRST
92#include <emscripten.h>
93#else
94
95#error "unknown byte order!"
96
97#endif /* webassembly */
98#endif /* _WIN32 */
99#endif /* __sun */
100#endif /* __linux */
101
102/* Setup the DLL macros for windows. GCC and clang builds that compile with
103 -fvisibility=hidden export only DAS_API names from a shared library, the
104 same set a Windows DLL exports. Emscripten is left alone, its exports come
105 from the link line. */
106#if defined(_WIN32) && defined(DAS_USE_DLL)
107# ifdef BUILDING_DLL
108# define DAS_API __declspec(dllexport)
109# else
110# define DAS_API __declspec(dllimport)
111# endif
112#elif defined(__GNUC__) && !defined(__EMSCRIPTEN__) && !defined(_WIN32)
113# define DAS_API __attribute__((visibility("default")))
114#else
115#define DAS_API
116#endif
117
118#if defined(_WIN32)
119#define DAS_DEPRECATED __declspec(deprecated)
120#else
121#define DAS_DEPRECATED __attribute__((__deprecated__))
122#endif
123
124/* Ask the compiler to check printf-style calls the way it checks printf
125 itself. FMT_IDX and ARG_IDX are 1-based parameter positions of the format
126 string and the first variadic argument. Not part of any C standard;
127 expands to nothing where the compiler lacks it. */
128#if defined(__GNUC__) || defined(__clang__)
129#define _das_fmt_check(FMT_IDX, ARG_IDX) \
130 __attribute__((__format__(__printf__, FMT_IDX, ARG_IDX)))
131#else
132#define _das_fmt_check(FMT_IDX, ARG_IDX)
133#endif
134
135#ifdef _WIN32
137#define DAS_DSEPC '\\'
138
140#define DAS_DSEPS "\\"
141
142#else
143
145#define DAS_DSEPC '/'
146
148#define DAS_DSEPS "/"
149#endif
150
152#define DAS_FIELD_SZ(type, field) (sizeof(((type*)NULL)->field))
153
154#ifdef __cplusplus
155extern "C" {
156#endif
157
168#define DAS_22_STREAM_VER "2.2"
169#define DAS_30_STREAM_VER "3.0"
170
171
172/* On Solaris systems NAME_MAX is not defined because pathconf() is supposed
173 * to be used to get the exact limit by filesystem. Since all the filesystems
174 * in common use today have support 255 characters, let's just define that
175 * to be NAME_MAX in the absence of something better.
176 */
177#ifdef __sun
178#ifndef NAME_MAX
179#define NAME_MAX 255
180#endif
181#endif
182
183/* Make it obvious when we are just moving data as opposed to characters */
184typedef uint8_t ubyte;
185
189typedef int DasErrCode;
190
192#define DAS_OKAY 0
193
194#define DASERR_NOTIMP 8
195#define DASERR_ASSERT 9
196#define DASERR_INIT 11
197#define DASERR_BUF 12
198#define DASERR_UTIL 13
199#define DASERR_ENC 14
200#define DASERR_UNITS 15
201#define DASERR_DESC 16
202#define DASERR_PLANE 17
203#define DASERR_PKT 18
204#define DASERR_STREAM 19
205#define DASERR_OOB 20
206#define DASERR_IO 22
207#define DASERR_DSDF 23
208#define DASERR_DFT 24
209#define DASERR_LOG 25
210#define DASERR_ARRAY 26
211#define DASERR_VAR 27
212#define DASERR_DIM 28
213#define DASERR_DS 29
214#define DASERR_BLDR 30
215#define DASERR_HTTP 31
216#define DASERR_DATUM 32
217#define DASERR_VALUE 33
218#define DASERR_OP 34
219#define DASERR_CRED 35
220#define DASERR_NODE 36
221#define DASERR_TIME 37
222#define DASERR_PROP 38
223#define DASERR_SERIAL 39
224#define DASERR_ITER 40
225#define DASERR_SPICE 41
226#define DASERR_URI 42
227#define DASERR_FORM 43
228#define DASERR_GEN 44
229#define DASERR_MAX 44
230
231#ifdef __cplusplus
232 }
233#endif
234
235#endif /* _das_defs_h_ */
236
237
int DasErrCode
return code type 0 indicates success, negative integer indicates failure
Definition defs.h:189