* configure.ac (AC_CHECK_ENABLE_LTDL): Removed.
[cacao.git] / src / vmcore / system.h
1 /* src/vmcore/system.h - system (OS) functions
2
3    Copyright (C) 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _VMCORE_SYSTEM_H
27 #define _VMCORE_SYSTEM_H
28
29 #include "config.h"
30
31 /* NOTE: In this file we check for all system headers, because we wrap
32    all system calls into inline functions for better portability. */
33
34 #if defined(HAVE_DIRENT_H)
35 # include <dirent.h>
36 #endif
37
38 #if defined(HAVE_DLFCN_H)
39 # include <dlfcn.h>
40 #endif
41
42 #if defined(HAVE_FCNTL_H)
43 # include <fcntl.h>
44 #endif
45
46 #if defined(ENABLE_JRE_LAYOUT)
47 # if defined(HAVE_LIBGEN_H)
48 #  include <libgen.h>
49 # endif
50 #endif
51
52 #if defined(HAVE_STDINT_H)
53 # include <stdint.h>
54 #endif
55
56 #if defined(HAVE_STDIO_H)
57 # include <stdio.h>
58 #endif
59
60 #if defined(HAVE_STDLIB_H)
61 # include <stdlib.h>
62 #endif
63
64 #if defined(HAVE_STRING_H)
65 # include <string.h>
66 #endif
67
68 #if defined(HAVE_UNISTD_H)
69 # include <unistd.h>
70 #endif
71
72 #if defined(HAVE_SYS_MMAN_H)
73 # include <sys/mman.h>
74 #endif
75
76 #if defined(HAVE_SYS_SOCKET_H)
77 # include <sys/socket.h>
78 #endif
79
80 #if defined(HAVE_SYS_STAT_H)
81 # include <sys/stat.h>
82 #endif
83
84 #if defined(HAVE_SYS_TYPES_H)
85 # include <sys/types.h>
86 #endif
87
88
89 /* inline functions ***********************************************************/
90
91 inline static void system_abort(void)
92 {
93 #if defined(HAVE_ABORT)
94         abort();
95 #else
96 # error abort not available
97 #endif
98 }
99
100 inline static int system_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
101 {
102 #if defined(HAVE_ACCEPT)
103         return accept(sockfd, addr, addrlen);
104 #else
105 # error accept not available
106 #endif
107 }
108
109 inline static int system_access(const char *pathname, int mode)
110 {
111 #if defined(HAVE_ACCESS)
112         return access(pathname, mode);
113 #else
114 # error access not available
115 #endif
116 }
117
118 inline static int system_atoi(const char *nptr)
119 {
120 #if defined(HAVE_ATOI)
121         return atoi(nptr);
122 #else
123 # error atoi not available
124 #endif
125 }
126
127 inline static void *system_calloc(size_t nmemb, size_t size)
128 {
129 #if defined(HAVE_CALLOC)
130         return calloc(nmemb, size);
131 #else
132 # error calloc not available
133 #endif
134 }
135
136 inline static int system_close(int fd)
137 {
138 #if defined(HAVE_CLOSE)
139         return close(fd);
140 #else
141 # error close not available
142 #endif
143 }
144
145 inline static int system_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
146 {
147 #if defined(HAVE_CONNECT)
148         return connect(sockfd, serv_addr, addrlen);
149 #else
150 # error connect not available
151 #endif
152 }
153
154 #if defined(ENABLE_JRE_LAYOUT)
155 inline static char *system_dirname(char *path)
156 {
157 #if defined(HAVE_DIRNAME)
158         return dirname(path);
159 #else
160 # error dirname not available
161 #endif
162 }
163 #endif
164
165 inline static int system_dlclose(void* handle)
166 {
167 #if defined(HAVE_DLCLOSE)
168         return dlclose(handle);
169 #else
170 # error dlclose not available
171 #endif
172 }
173
174 inline static char* system_dlerror(void)
175 {
176 #if defined(HAVE_DLERROR)
177         return dlerror();
178 #else
179 # error dlerror not available
180 #endif
181 }
182
183 inline static void* system_dlopen(const char* filename, int flag)
184 {
185 #if defined(HAVE_DLOPEN)
186         return dlopen(filename, flag);
187 #else
188 # error dlopen not available
189 #endif
190 }
191
192 inline static void* system_dlsym(void* handle, const char* symbol)
193 {
194 #if defined(HAVE_DLSYM)
195         return dlsym(handle, symbol);
196 #else
197 # error dlsym not available
198 #endif
199 }
200
201 inline static FILE *system_fopen(const char *path, const char *mode)
202 {
203 #if defined(HAVE_FOPEN)
204         return fopen(path, mode);
205 #else
206 # error fopen not available
207 #endif
208 }
209
210 inline static int system_fclose(FILE *fp)
211 {
212 #if defined(HAVE_FCLOSE)
213         return fclose(fp);
214 #else
215 # error fclose not available
216 #endif
217 }
218
219 inline static size_t system_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
220 {
221 #if defined(HAVE_FREAD)
222         return fread(ptr, size, nmemb, stream);
223 #else
224 # error fread not available
225 #endif
226 }
227
228 inline static void system_free(void *ptr)
229 {
230 #if defined(HAVE_FREE)
231         free(ptr);
232 #else
233 # error free not available
234 #endif
235 }
236
237 inline static int system_fsync(int fd)
238 {
239 #if defined(HAVE_FSYNC)
240         return fsync(fd);
241 #else
242 # error fsync not available
243 #endif
244 }
245
246 inline static int system_ftruncate(int fd, off_t length)
247 {
248 #if defined(HAVE_FTRUNCATE)
249         return ftruncate(fd, length);
250 #else
251 # error ftruncate not available
252 #endif
253 }
254
255 inline static int system_gethostname(char *name, size_t len)
256 {
257 #if defined(HAVE_GETHOSTNAME)
258         return gethostname(name, len);
259 #else
260 # error gethostname not available
261 #endif
262 }
263
264 inline static int system_getpagesize(void)
265 {
266 #if defined(HAVE_GETPAGESIZE)
267         return getpagesize();
268 #else
269 # error getpagesize not available
270 #endif
271 }
272
273 inline static int system_getsockname(int s, struct sockaddr *name, socklen_t *namelen)
274 {
275 #if defined(HAVE_GETSOCKNAME)
276         return getsockname(s, name, namelen);
277 #else
278 # error getsockname not available
279 #endif
280 }
281
282 inline static int system_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
283 {
284 #if defined(HAVE_GETSOCKOPT)
285         return getsockopt(s, level, optname, optval, optlen);
286 #else
287 # error getsockopt not available
288 #endif
289 }
290
291 inline static int system_listen(int sockfd, int backlog)
292 {
293 #if defined(HAVE_LISTEN)
294         return listen(sockfd, backlog);
295 #else
296 # error listen not available
297 #endif
298 }
299
300 inline static off_t system_lseek(int fildes, off_t offset, int whence)
301 {
302 #if defined(HAVE_LSEEK)
303         return lseek(fildes, offset, whence);
304 #else
305 # error lseek not available
306 #endif
307 }
308
309 inline static void *system_malloc(size_t size)
310 {
311 #if defined(HAVE_MALLOC)
312         return malloc(size);
313 #else
314 # error malloc not available
315 #endif
316 }
317
318 inline static void *system_memcpy(void *dest, const void *src, size_t n)
319 {
320 #if defined(HAVE_MEMCPY)
321         return memcpy(dest, src, n);
322 #else
323 # error memcpy not available
324 #endif
325 }
326
327 inline static void *system_memset(void *s, int c, size_t n)
328 {
329 #if defined(HAVE_MEMSET)
330         return memset(s, c, n);
331 #else
332 # error memset not available
333 #endif
334 }
335
336 inline static int system_mprotect(void *addr, size_t len, int prot)
337 {
338 #if defined(HAVE_MPROTECT)
339         return mprotect(addr, len, prot);
340 #else
341 # error mprotect not available
342 #endif
343 }
344
345 inline static int system_open(const char *pathname, int flags, mode_t mode)
346 {
347 #if defined(HAVE_OPEN)
348         return open(pathname, flags, mode);
349 #else
350 # error open not available
351 #endif
352 }
353
354 inline static ssize_t system_read(int fd, void *buf, size_t count)
355 {
356 #if defined(HAVE_READ)
357         return read(fd, buf, count);
358 #else
359 # error read not available
360 #endif
361 }
362
363 inline static void *system_realloc(void *ptr, size_t size)
364 {
365 #if defined(HAVE_REALLOC)
366         return realloc(ptr, size);
367 #else
368 # error realloc not available
369 #endif
370 }
371
372 #if defined(__LINUX__)
373 inline static int system_scandir(const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const void *, const void *))
374 #elif defined(__IRIX__)
375 inline static int system_scandir(const char *dir, struct dirent ***namelist, int(*filter)(dirent_t *), int(*compar)(dirent_t **, dirent_t **))
376 #else
377 inline static int system_scandir(const char *dir, struct dirent ***namelist, int(*filter)(struct dirent *), int(*compar)(const void *, const void *))
378 #endif
379 {
380 #if defined(HAVE_SCANDIR)
381         return scandir(dir, namelist, filter, compar);
382 #else
383 # error scandir not available
384 #endif
385 }
386
387 inline static int system_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
388 {
389 #if defined(HAVE_SETSOCKOPT)
390         return setsockopt(s, level, optname, optval, optlen);
391 #else
392 # error setsockopt not available
393 #endif
394 }
395
396 inline static int system_shutdown(int s, int how)
397 {
398 #if defined(HAVE_SHUTDOWN)
399         return shutdown(s, how);
400 #else
401 # error shutdown not available
402 #endif
403 }
404
405 inline static int system_socket(int domain, int type, int protocol)
406 {
407 #if defined(HAVE_SOCKET)
408         return socket(domain, type, protocol);
409 #else
410 # error socket not available
411 #endif
412 }
413
414 inline static int system_stat(const char *path, struct stat *buf)
415 {
416 #if defined(HAVE_STAT)
417         return stat(path, buf);
418 #else
419 # error stat not available
420 #endif
421 }
422
423 inline static char *system_strcat(char *dest, const char *src)
424 {
425 #if defined(HAVE_STRCAT)
426         return strcat(dest, src);
427 #else
428 # error strcat not available
429 #endif
430 }
431
432 inline static char *system_strcpy(char *dest, const char *src)
433 {
434 #if defined(HAVE_STRCPY)
435         return strcpy(dest, src);
436 #else
437 # error strcpy not available
438 #endif
439 }
440
441 inline static char *system_strdup(const char *s)
442 {
443 #if defined(HAVE_STRDUP)
444         return strdup(s);
445 #else
446 # error strdup not available
447 #endif
448 }
449
450 inline static char *system_strerror(int errnum)
451 {
452 #if defined(HAVE_STRERROR)
453         return strerror(errnum);
454 #else
455 # error strerror not available
456 #endif
457 }
458
459 inline static size_t system_strlen(const char *s)
460 {
461 #if defined(HAVE_STRLEN)
462         return strlen(s);
463 #else
464 # error strlen not available
465 #endif
466 }
467
468 inline static ssize_t system_write(int fd, const void *buf, size_t count)
469 {
470 #if defined(HAVE_WRITE)
471         return write(fd, buf, count);
472 #else
473 # error write not available
474 #endif
475 }
476
477
478 /* function prototypes ********************************************************/
479
480 void *system_mmap_anonymous(void *addr, size_t len, int prot, int flags);
481 int   system_processors_online(void);
482
483 #endif /* _VMCORE_SYSTEM_H */
484
485
486 /*
487  * These are local overrides for various environment variables in Emacs.
488  * Please do not remove this and leave it at the end of the file, where
489  * Emacs will automagically detect them.
490  * ---------------------------------------------------------------------
491  * Local variables:
492  * mode: c
493  * indent-tabs-mode: t
494  * c-basic-offset: 4
495  * tab-width: 4
496  * End:
497  * vim:noexpandtab:sw=4:ts=4:
498  */