1 /* src/vmcore/system.h - system (OS) functions
3 Copyright (C) 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
26 #ifndef _VMCORE_SYSTEM_H
27 #define _VMCORE_SYSTEM_H
31 /* NOTE: In this file we check for all system headers, because we wrap
32 all system calls into inline functions for better portability. */
34 #if defined(HAVE_DIRENT_H)
38 #if defined(HAVE_DLFCN_H)
42 #if defined(HAVE_FCNTL_H)
46 #if defined(ENABLE_JRE_LAYOUT)
47 # if defined(HAVE_LIBGEN_H)
52 #if defined(HAVE_STDINT_H)
56 #if defined(HAVE_STDIO_H)
60 #if defined(HAVE_STDLIB_H)
64 #if defined(HAVE_STRING_H)
68 #if defined(HAVE_UNISTD_H)
72 #if defined(HAVE_SYS_MMAN_H)
73 # include <sys/mman.h>
76 #if defined(HAVE_SYS_SOCKET_H)
77 # include <sys/socket.h>
80 #if defined(HAVE_SYS_STAT_H)
81 # include <sys/stat.h>
84 #if defined(HAVE_SYS_TYPES_H)
85 # include <sys/types.h>
89 /* inline functions ***********************************************************/
91 inline static void system_abort(void)
93 #if defined(HAVE_ABORT)
96 # error abort not available
100 inline static int system_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
102 #if defined(HAVE_ACCEPT)
103 return accept(sockfd, addr, addrlen);
105 # error accept not available
109 inline static int system_access(const char *pathname, int mode)
111 #if defined(HAVE_ACCESS)
112 return access(pathname, mode);
114 # error access not available
118 inline static int system_atoi(const char *nptr)
120 #if defined(HAVE_ATOI)
123 # error atoi not available
127 inline static void *system_calloc(size_t nmemb, size_t size)
129 #if defined(HAVE_CALLOC)
130 return calloc(nmemb, size);
132 # error calloc not available
136 inline static int system_close(int fd)
138 #if defined(HAVE_CLOSE)
141 # error close not available
145 inline static int system_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
147 #if defined(HAVE_CONNECT)
148 return connect(sockfd, serv_addr, addrlen);
150 # error connect not available
154 #if defined(ENABLE_JRE_LAYOUT)
155 inline static char *system_dirname(char *path)
157 #if defined(HAVE_DIRNAME)
158 return dirname(path);
160 # error dirname not available
165 inline static int system_dlclose(void* handle)
167 #if defined(HAVE_DLCLOSE)
168 return dlclose(handle);
170 # error dlclose not available
174 inline static char* system_dlerror(void)
176 #if defined(HAVE_DLERROR)
179 # error dlerror not available
183 inline static void* system_dlopen(const char* filename, int flag)
185 #if defined(HAVE_DLOPEN)
186 return dlopen(filename, flag);
188 # error dlopen not available
192 inline static void* system_dlsym(void* handle, const char* symbol)
194 #if defined(HAVE_DLSYM)
195 return dlsym(handle, symbol);
197 # error dlsym not available
201 inline static FILE *system_fopen(const char *path, const char *mode)
203 #if defined(HAVE_FOPEN)
204 return fopen(path, mode);
206 # error fopen not available
210 inline static int system_fclose(FILE *fp)
212 #if defined(HAVE_FCLOSE)
215 # error fclose not available
219 inline static size_t system_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
221 #if defined(HAVE_FREAD)
222 return fread(ptr, size, nmemb, stream);
224 # error fread not available
228 inline static void system_free(void *ptr)
230 #if defined(HAVE_FREE)
233 # error free not available
237 inline static int system_fsync(int fd)
239 #if defined(HAVE_FSYNC)
242 # error fsync not available
246 inline static int system_ftruncate(int fd, off_t length)
248 #if defined(HAVE_FTRUNCATE)
249 return ftruncate(fd, length);
251 # error ftruncate not available
255 inline static int system_gethostname(char *name, size_t len)
257 #if defined(HAVE_GETHOSTNAME)
258 return gethostname(name, len);
260 # error gethostname not available
264 inline static int system_getpagesize(void)
266 #if defined(HAVE_GETPAGESIZE)
267 return getpagesize();
269 # error getpagesize not available
273 inline static int system_getsockname(int s, struct sockaddr *name, socklen_t *namelen)
275 #if defined(HAVE_GETSOCKNAME)
276 return getsockname(s, name, namelen);
278 # error getsockname not available
282 inline static int system_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
284 #if defined(HAVE_GETSOCKOPT)
285 return getsockopt(s, level, optname, optval, optlen);
287 # error getsockopt not available
291 inline static int system_listen(int sockfd, int backlog)
293 #if defined(HAVE_LISTEN)
294 return listen(sockfd, backlog);
296 # error listen not available
300 inline static off_t system_lseek(int fildes, off_t offset, int whence)
302 #if defined(HAVE_LSEEK)
303 return lseek(fildes, offset, whence);
305 # error lseek not available
309 inline static void *system_malloc(size_t size)
311 #if defined(HAVE_MALLOC)
314 # error malloc not available
318 inline static void *system_memcpy(void *dest, const void *src, size_t n)
320 #if defined(HAVE_MEMCPY)
321 return memcpy(dest, src, n);
323 # error memcpy not available
327 inline static void *system_memset(void *s, int c, size_t n)
329 #if defined(HAVE_MEMSET)
330 return memset(s, c, n);
332 # error memset not available
336 inline static int system_mprotect(void *addr, size_t len, int prot)
338 #if defined(HAVE_MPROTECT)
339 return mprotect(addr, len, prot);
341 # error mprotect not available
345 inline static int system_open(const char *pathname, int flags, mode_t mode)
347 #if defined(HAVE_OPEN)
348 return open(pathname, flags, mode);
350 # error open not available
354 inline static ssize_t system_read(int fd, void *buf, size_t count)
356 #if defined(HAVE_READ)
357 return read(fd, buf, count);
359 # error read not available
363 inline static void *system_realloc(void *ptr, size_t size)
365 #if defined(HAVE_REALLOC)
366 return realloc(ptr, size);
368 # error realloc not available
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 **))
377 inline static int system_scandir(const char *dir, struct dirent ***namelist, int(*filter)(struct dirent *), int(*compar)(const void *, const void *))
380 #if defined(HAVE_SCANDIR)
381 return scandir(dir, namelist, filter, compar);
383 # error scandir not available
387 inline static int system_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
389 #if defined(HAVE_SETSOCKOPT)
390 return setsockopt(s, level, optname, optval, optlen);
392 # error setsockopt not available
396 inline static int system_shutdown(int s, int how)
398 #if defined(HAVE_SHUTDOWN)
399 return shutdown(s, how);
401 # error shutdown not available
405 inline static int system_socket(int domain, int type, int protocol)
407 #if defined(HAVE_SOCKET)
408 return socket(domain, type, protocol);
410 # error socket not available
414 inline static int system_stat(const char *path, struct stat *buf)
416 #if defined(HAVE_STAT)
417 return stat(path, buf);
419 # error stat not available
423 inline static char *system_strcat(char *dest, const char *src)
425 #if defined(HAVE_STRCAT)
426 return strcat(dest, src);
428 # error strcat not available
432 inline static char *system_strcpy(char *dest, const char *src)
434 #if defined(HAVE_STRCPY)
435 return strcpy(dest, src);
437 # error strcpy not available
441 inline static char *system_strdup(const char *s)
443 #if defined(HAVE_STRDUP)
446 # error strdup not available
450 inline static char *system_strerror(int errnum)
452 #if defined(HAVE_STRERROR)
453 return strerror(errnum);
455 # error strerror not available
459 inline static size_t system_strlen(const char *s)
461 #if defined(HAVE_STRLEN)
464 # error strlen not available
468 inline static ssize_t system_write(int fd, const void *buf, size_t count)
470 #if defined(HAVE_WRITE)
471 return write(fd, buf, count);
473 # error write not available
478 /* function prototypes ********************************************************/
480 void *system_mmap_anonymous(void *addr, size_t len, int prot, int flags);
481 int system_processors_online(void);
483 #endif /* _VMCORE_SYSTEM_H */
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 * ---------------------------------------------------------------------
493 * indent-tabs-mode: t
497 * vim:noexpandtab:sw=4:ts=4: