FreeWRL/FreeX3D  3.0.0
system.h
1 /*
2 
3 
4 FreeWRL support library.
5 Internal header: system dependencies.
6 
7 */
8 
9 /****************************************************************************
10  This file is part of the FreeWRL/FreeX3D Distribution.
11 
12  Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
13 
14  FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
15  it under the terms of the GNU Lesser Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  FreeWRL/FreeX3D is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  GNU General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
26 ****************************************************************************/
27 #include <config.h>
28 
29 #ifndef __LIBFREEWRL_SYSTEM_H__
30 #define __LIBFREEWRL_SYSTEM_H__
31 
48 /* do we have JavaScript? */
49 // OLD_IPHONE_AQUA #if defined(IPHONE) || defined(_ANDROID) || defined (AQUA) || defined(NO_JAVASCRIPT)
50 #if defined(_ANDROID) || defined(NO_JAVASCRIPT)
51 
52  //QNX port had javascript. I think you could do it in android and iphone too
53  //there's some confusion when they say 'no scripting' for those mobile platforms
54  //I think its OK to have our type of scripting because BB/QNX said no scripting, and
55  //then listed libmozjs185 as a lib that was already ported and avilable on QNX.
56  #undef JAVASCRIPT_SM
57  #undef JAVASCRIPT_DUK
58  #define JAVASCRIPT_STUB 1
59 #else
60  /* Everything has JavaScript - define your choice of the following 3 in your config.h */
61  //#define JAVASCRIPT_STUB
62  //#define JAVASCRIPT_SM
63  //#define JAVASCRIPT_DUK
64 #endif
65 
66 #if HAVE_STDINT_H
67 # include <stdint.h>
68 #endif
69 
70 #if HAVE_CTYPE_H
71 #include <ctype.h>
72 #endif
73 
74 #if STDC_HEADERS
75 # include <stdio.h>
76 # include <stdlib.h>
77 # include <string.h>
78 #else
79 # if !HAVE_STRCHR
80 # define strchr index
81 # define strrchr rindex
82 # endif
83 char *strchr (), *strrchr ();
84 # if !HAVE_MEMCPY
85 # define memcpy(d, s, n) bcopy ((s), (d), (n))
86 # define memmove(d, s, n) bcopy ((s), (d), (n))
87 # endif
88 #endif
89 
90 #if defined(_ANDROID) || defined(ANDROIDNDK)
91 #include <stddef.h>
92 typedef int bool;
93 # define false 0
94 # define true 1
95 # define __bool_true_false_are_defined 1
96 #else
97 #if HAVE_STDBOOL_H
98 # include <stdbool.h>
99 #else
100 # if ! HAVE__BOOL
101 # ifdef __cplusplus
102 typedef bool _Bool;
103 # else
104 typedef unsigned char _Bool;
105 # endif
106 # endif
107 # define bool _Bool
108 # define false 0
109 # define true 1
110 # define __bool_true_false_are_defined 1
111 #endif
112 #endif
113 
114 #if defined(_ANDROID) || defined(ANDROIDNDK)
115 #include <stdbool.h>
116 #define JS_FALSE false
117 #define JS_TRUE true
118 #endif
119 
120 #ifndef TRUE
121 #define TRUE 1
122 #endif
123 #ifndef FALSE
124 #define FALSE 0
125 #endif
126 
127 #if HAVE_UNISTD_H
128 # if HAVE_SYS_TYPES_H
129 # include <sys/types.h>
130 # endif
131 # include <unistd.h>
132 #endif
133 
134 #if defined(HAVE_LIMITS_H)
135 # include <limits.h>
136 #endif
137 
138 #if defined(HAVE_STRING_H)
139 # include <string.h>
140 #endif
141 
142 #if !defined(HAVE_STRNLEN)
143 #define strnlen __fw_strnlen
144 size_t __fw_strnlen(const char *s, size_t maxlen);
145 #endif
146 
147 #if !defined(HAVE_STRNDUP)
148 # define strndup __fw_strndup
149 char *__fw_strndup(const char *s, size_t n);
150 #endif
151 
152 
153 #if defined(HAVE_SYS_WAIT_H)
154 # include <sys/wait.h>
155 #endif
156 #ifndef WEXITSTATUS
157 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
158 #endif
159 #ifndef WIFEXITED
160 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
161 #endif
162 
163 #if HAVE_MATH_H
164 # include <math.h>
165 #endif
166 
167 /* Those macro may not be declared everywhere */
168 
169 #if !defined(min)
170  #define min(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
171 #endif
172 
173 #if !defined(max)
174  #define max(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
175 #endif
176 
177 
178 #if HAVE_SYS_STAT_H
179 #include <sys/stat.h>
180 #endif
181 
182 #if HAVE_SYS_TIME_H
183 # include <sys/time.h>
184 #endif
185 #if HAVE_TIME_H
186 # include <time.h>
187 #endif
188 
189 
190 #if HAVE_FCNTL_H
191 # include <fcntl.h>
192 #endif
193 
194 #if !defined(assert)
195 # include <assert.h>
196 #endif
197 
201 #if defined(_MSC_VER)
202 #include <Windows.h>
203 /* FIXME: those calls to bzero & bcopy shall be remove from libeai ;)... */
204 
205 /* http://www.opengroup.org/onlinepubs/000095399/functions/bzero.html */
206 /* http://www.opengroup.org/onlinepubs/000095399/functions/bcopy.html */
207 #define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
208 #define bcopy(b1,b2,len) (memmove((b2), (b1), (len)), (void) 0)
209 
210 /* borrowed from CScripts.c */
211 #define PATH_MAX _MAX_PATH /*32kb*/
212 
218 /* _strdup is defined in string.h */
219 # include <string.h>
220 # define strdup _strdup
221 
222 /* _unlink is defined in io.h and (needs stdio.h) */
223 # include <io.h>
224 # include <stdio.h>
225 # define unlink _unlink
226 
227 /* _access is defined in io.h and error constants in errno.h */
228 # include <io.h>
229 # include <errno.h>
230 # define access _access
231 
232 /* _getpid is defined in process.h */
233 # include <process.h>
234 # define getpid _getpid
235 
236 /* _tempnam is defined in stdio.h */
237 # include <stdio.h>
238 # define tempnam _tempnam
239 
240 /* _stat is defined in sys/stat.h (needs sys/types.h) */
241 # include <sys/types.h>
242 # include <sys/stat.h>
243 # define stat _stat
244 /* NOTE: http://msdn.microsoft.com/en-us/library/14h5k7ff.aspx
245  stat usage:
246  If path contains the location of a directory, it cannot
247  contain a trailing backslash. If it does, -1 will be returned
248  and errno will be set to ENOENT.
249 */
250 
251 
252 #define snprintf _snprintf
253 
254 #define fmin min
255 #define fmax max
256 
257 #endif /* _MSC_VER */
258 
259 double Time1970sec(void);
260 
261 
262 #endif /* __LIBFREEWRL_SYSTEM_H__ */