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_FCNTL_H)
42 #if defined(WITH_JRE_LAYOUT)
43 # if defined(HAVE_LIBGEN_H)
48 #if defined(HAVE_STDINT_H)
52 #if defined(HAVE_STDIO_H)
56 #if defined(HAVE_STDLIB_H)
60 #if defined(HAVE_STRING_H)
64 #if defined(HAVE_UNISTD_H)
68 #if defined(HAVE_SYS_MMAN_H)
69 # include <sys/mman.h>
72 #if defined(HAVE_SYS_SOCKET_H)
73 # include <sys/socket.h>
76 #if defined(HAVE_SYS_STAT_H)
77 # include <sys/stat.h>
80 #if defined(HAVE_SYS_TYPES_H)
81 # include <sys/types.h>
85 /* inline functions ***********************************************************/
87 inline static void system_abort(void)
89 #if defined(HAVE_ABORT)
92 # error abort not available
96 inline static int system_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
98 #if defined(HAVE_ACCEPT)
99 return accept(sockfd, addr, addrlen);
101 # error accept not available
105 inline static int system_access(const char *pathname, int mode)
107 #if defined(HAVE_ACCESS)
108 return access(pathname, mode);
110 # error access not available
114 inline static void *system_calloc(size_t nmemb, size_t size)
116 #if defined(HAVE_CALLOC)
117 return calloc(nmemb, size);
119 # error calloc not available
123 inline static int system_close(int fd)
125 #if defined(HAVE_CLOSE)
128 # error close not available
132 inline static int system_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
134 #if defined(HAVE_CONNECT)
135 return connect(sockfd, serv_addr, addrlen);
137 # error connect not available
141 #if defined(WITH_JRE_LAYOUT)
142 inline static char *system_dirname(char *path)
144 #if defined(HAVE_DIRNAME)
145 return dirname(path);
147 # error dirname not available
152 inline static FILE *system_fopen(const char *path, const char *mode)
154 #if defined(HAVE_FOPEN)
155 return fopen(path, mode);
157 # error fopen not available
161 inline static int system_fclose(FILE *fp)
163 #if defined(HAVE_FCLOSE)
166 # error fclose not available
170 inline static size_t system_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
172 #if defined(HAVE_FREAD)
173 return fread(ptr, size, nmemb, stream);
175 # error fread not available
179 inline static void system_free(void *ptr)
181 #if defined(HAVE_FREE)
184 # error free not available
188 inline static int system_fsync(int fd)
190 #if defined(HAVE_FSYNC)
193 # error fsync not available
197 inline static int system_ftruncate(int fd, off_t length)
199 #if defined(HAVE_FTRUNCATE)
200 return ftruncate(fd, length);
202 # error ftruncate not available
206 inline static int system_gethostname(char *name, size_t len)
208 #if defined(HAVE_GETHOSTNAME)
209 return gethostname(name, len);
211 # error gethostname not available
215 inline static int system_getpagesize(void)
217 #if defined(HAVE_GETPAGESIZE)
218 return getpagesize();
220 # error getpagesize not available
224 inline static int system_getsockname(int s, struct sockaddr *name, socklen_t *namelen)
226 #if defined(HAVE_GETSOCKNAME)
227 return getsockname(s, name, namelen);
229 # error getsockname not available
233 inline static int system_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
235 #if defined(HAVE_GETSOCKOPT)
236 return getsockopt(s, level, optname, optval, optlen);
238 # error getsockopt not available
242 inline static int system_listen(int sockfd, int backlog)
244 #if defined(HAVE_LISTEN)
245 return listen(sockfd, backlog);
247 # error listen not available
251 inline static off_t system_lseek(int fildes, off_t offset, int whence)
253 #if defined(HAVE_LSEEK)
254 return lseek(fildes, offset, whence);
256 # error lseek not available
260 inline static void *system_malloc(size_t size)
262 #if defined(HAVE_MALLOC)
265 # error malloc not available
269 inline static void *system_memcpy(void *dest, const void *src, size_t n)
271 #if defined(HAVE_MEMCPY)
272 return memcpy(dest, src, n);
274 # error memcpy not available
278 inline static void *system_memset(void *s, int c, size_t n)
280 #if defined(HAVE_MEMSET)
281 return memset(s, c, n);
283 # error memset not available
287 inline static int system_mprotect(void *addr, size_t len, int prot)
289 #if defined(HAVE_MPROTECT)
290 return mprotect(addr, len, prot);
292 # error mprotect not available
296 inline static int system_open(const char *pathname, int flags, mode_t mode)
298 #if defined(HAVE_OPEN)
299 return open(pathname, flags, mode);
301 # error open not available
305 inline static ssize_t system_read(int fd, void *buf, size_t count)
307 #if defined(HAVE_READ)
308 return read(fd, buf, count);
310 # error read not available
314 inline static void *system_realloc(void *ptr, size_t size)
316 #if defined(HAVE_REALLOC)
317 return realloc(ptr, size);
319 # error realloc not available
323 inline static int system_scandir(const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const void *, const void *))
325 #if defined(HAVE_SCANDIR)
326 return scandir(dir, namelist, filter, compar);
328 # error scandir not available
332 inline static int system_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
334 #if defined(HAVE_SETSOCKOPT)
335 return setsockopt(s, level, optname, optval, optlen);
337 # error setsockopt not available
341 inline static int system_shutdown(int s, int how)
343 #if defined(HAVE_SHUTDOWN)
344 return shutdown(s, how);
346 # error shutdown not available
350 inline static int system_socket(int domain, int type, int protocol)
352 #if defined(HAVE_SOCKET)
353 return socket(domain, type, protocol);
355 # error socket not available
359 inline static int system_stat(const char *path, struct stat *buf)
361 #if defined(HAVE_STAT)
362 return stat(path, buf);
364 # error stat not available
368 inline static char *system_strdup(const char *s)
370 #if defined(HAVE_STRDUP)
373 # error strdup not available
377 inline static char *system_strerror(int errnum)
379 #if defined(HAVE_STRERROR)
380 return strerror(errnum);
382 # error strerror not available
386 inline static size_t system_strlen(const char *s)
388 #if defined(HAVE_STRLEN)
391 # error strlen not available
395 inline static ssize_t system_write(int fd, const void *buf, size_t count)
397 #if defined(HAVE_WRITE)
398 return write(fd, buf, count);
400 # error write not available
405 /* function prototypes ********************************************************/
407 void *system_mmap_anonymous(void *addr, size_t len, int prot, int flags);
408 int system_processors_online(void);
410 #endif /* _VMCORE_SYSTEM_H */
414 * These are local overrides for various environment variables in Emacs.
415 * Please do not remove this and leave it at the end of the file, where
416 * Emacs will automagically detect them.
417 * ---------------------------------------------------------------------
420 * indent-tabs-mode: t
424 * vim:noexpandtab:sw=4:ts=4: