File: gb_common.h

package info (click to toggle)
gambas3 3.20.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 76,984 kB
  • sloc: ansic: 197,178; cpp: 124,076; sh: 18,999; javascript: 7,761; sql: 5,399; makefile: 2,354; perl: 1,397; xml: 490; python: 335
file content (216 lines) | stat: -rw-r--r-- 5,001 bytes parent folder | download | duplicates (2)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/***************************************************************************

  gb_common.h

  (c) 2000-2017 Benoît Minisini <benoit.minisini@gambas-basic.org>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2, or (at your option)
  any later version.

  This program 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 General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  MA 02110-1301, USA.

***************************************************************************/

#ifndef __GB_COMMON_H
#define __GB_COMMON_H

#include "config.h"

#ifdef _GNU_SOURCE
#undef _GNU_SOURCE
#endif
#define _GNU_SOURCE 500

#define _FILE_OFFSET_BITS 64

#define __STDC_FORMAT_MACROS 1
#define _ISOC9X_SOURCE	1
#define _ISOC99_SOURCE	1
#define __USE_ISOC99	1
#define __USE_ISOC9X	1

#if defined(__cplusplus)
#include <cmath>
#else
#include <math.h>
#endif

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <inttypes.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <limits.h>

#if defined(__GNU_LIBRARY__) || defined(OS_BSD)

#include <getopt.h>
#define HAVE_GETOPT_LONG 1

#endif

#if defined(OS_CYGWIN)

	typedef void (*sighandler_t) (int);
	typedef unsigned long ulong;

#endif

#if defined(OS_BSD)

	/* sighandler_t is replaced by sig_t */
	#define sighandler_t sig_t

	typedef unsigned long ulong;

#endif

#ifdef OS_SOLARIS

/* PGS: The following #define prevents /usr/include/sys/mman.h on solaris
		from #define'ing PRIVATE to 0x20, thus breaking Gambas.
		Perhaps Gambas should use a different name?
		BM: I don't use PRIVATE anymore!
*/
	#ifdef _POSIX_C_SOURCE
	/* PGS: Stop compiler warnings when gcc on solaris does remember to define
		_POSIX_C_SOURCE, e.g. when compiling qt related files. */
		#undef _POSIX_C_SOURCE
	#endif

	#define _POSIX_C_SOURCE 3
	/* Get prototype for alloca() */
	#include <alloca.h>
	/* Get definition for index() */
	#include <strings.h>

#endif

#ifdef OS_MACOSX

#include <stdbool.h>
#undef bool

#endif

#ifndef FALSE
	enum
	{
		FALSE = 0,
		TRUE = 1
	};
#endif

#if !defined(__cplusplus)

	#define bool char

#endif

typedef
	unsigned char uchar;

typedef
	size_t offset_t;

#define PUBLIC
#define INLINE __attribute__((always_inline)) inline
#define NOINLINE __attribute__((noinline))
#define EXTERN extern
#define PACKED __attribute__((packed))
#define NORETURN __attribute__((noreturn))
#define CONST __attribute__((const))

#ifndef __WORDSIZE
	#if defined(UINTPTR_MAX) && defined(UINT64_MAX)
		#if (UINTPTR_MAX == UINT64_MAX)
			#define	__WORDSIZE 64
		#else
			#define	__WORDSIZE 32
		#endif
	#endif
#endif

#ifndef __WORDSIZE
	#error "__WORDSIZE is not defined!"
#endif
	
#if __WORDSIZE == 64
#define OS_64BITS 1
#endif

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define OS_LITTLE_ENDIAN 1
#else
#define OS_BIG_ENDIAN 1
#endif

#ifndef LLONG_MAX
#define LLONG_MAX 9223372036854775807LL
#endif

#ifndef PATH_MAX
#define PATH_MAX 4095
#endif

#ifndef MAXPATHLEN
#define MAXPATHLEN 4095
#endif

#define CLEAR(s) (memset(s, 0, sizeof(*s)))

/* Workaround spurious gcc warnings */
#define NO_WARNING(var) var = var

#ifndef offsetof
	#define offsetof(_type, _arg) ((size_t)&(((_type *)0)->_arg))
#endif

#define Max(a, b) ({ __typeof__(a) _a = (a), _b = (b); _a > _b ? _a : _b; })
#define Min(a, b) ({ __typeof__(a) _a = (a), _b = (b); _a < _b ? _a : _b; })
#define MinMax(v, a, b) ({ __typeof__(v) _v = (v), _a = (a), _b = (b); _v < _a ? _a : (_v > _b ? _b : _v); })

#if (defined (__i386__) || defined (__x86_64__)) && defined (__GNUC__) && __GNUC__ >= 2
	#define BREAKPOINT()	{ __asm__ __volatile__ ("int $03"); }
#elif (defined (_MSC_VER) || defined (__DMC__)) && defined (_M_IX86)
	#define BREAKPOINT()	{ __asm int 3h }G_STMT_END
#elif defined (__alpha__) && !defined(__osf__) && defined (__GNUC__) && __GNUC__ >= 2
	#define BREAKPOINT()	{ __asm__ __volatile__ ("bpt"); }
#else	/* !__i386__ && !__alpha__ */
	#define BREAKPOINT()	{ raise(SIGTRAP); }
#endif	/* __i386__ */

#define COPYRIGHT "(c) Benoît Minisini\n\n" \
	"This program is free software; you can redistribute it and/or \n" \
	"modify it under the terms of the GNU General Public License as \n" \
	"published by the Free Software Foundation; either version 2, or \n" \
	"(at your option) any later version.\n\n"

#define $(_x) _x

#define RESTART_SYSCALL(_code) \
	for(;;) \
	{ \
		errno = 0; \
		if ((_code) >= 0 || (errno != EINTR)) \
			break; \
	} if (errno)

#endif /* __GB_COMMON_H */