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(ENABLE_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 int system_atoi(const char *nptr)
116 #if defined(HAVE_ATOI)
119 # error atoi not available
123 inline static void *system_calloc(size_t nmemb, size_t size)
125 #if defined(HAVE_CALLOC)
126 return calloc(nmemb, size);
128 # error calloc not available
132 inline static int system_close(int fd)
134 #if defined(HAVE_CLOSE)
137 # error close not available
141 inline static int system_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
143 #if defined(HAVE_CONNECT)
144 return connect(sockfd, serv_addr, addrlen);
146 # error connect not available
150 #if defined(ENABLE_JRE_LAYOUT)
151 inline static char *system_dirname(char *path)
153 #if defined(HAVE_DIRNAME)
154 return dirname(path);
156 # error dirname not available
161 inline static FILE *system_fopen(const char *path, const char *mode)
163 #if defined(HAVE_FOPEN)
164 return fopen(path, mode);
166 # error fopen not available
170 inline static int system_fclose(FILE *fp)
172 #if defined(HAVE_FCLOSE)
175 # error fclose not available
179 inline static size_t system_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
181 #if defined(HAVE_FREAD)
182 return fread(ptr, size, nmemb, stream);
184 # error fread not available
188 inline static void system_free(void *ptr)
190 #if defined(HAVE_FREE)
193 # error free not available
197 inline static int system_fsync(int fd)
199 #if defined(HAVE_FSYNC)
202 # error fsync not available
206 inline static int system_ftruncate(int fd, off_t length)
208 #if defined(HAVE_FTRUNCATE)
209 return ftruncate(fd, length);
211 # error ftruncate not available
215 inline static int system_gethostname(char *name, size_t len)
217 #if defined(HAVE_GETHOSTNAME)
218 return gethostname(name, len);
220 # error gethostname not available
224 inline static int system_getpagesize(void)
226 #if defined(HAVE_GETPAGESIZE)
227 return getpagesize();
229 # error getpagesize not available
233 inline static int system_getsockname(int s, struct sockaddr *name, socklen_t *namelen)
235 #if defined(HAVE_GETSOCKNAME)
236 return getsockname(s, name, namelen);
238 # error getsockname not available
242 inline static int system_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
244 #if defined(HAVE_GETSOCKOPT)
245 return getsockopt(s, level, optname, optval, optlen);
247 # error getsockopt not available
251 inline static int system_listen(int sockfd, int backlog)
253 #if defined(HAVE_LISTEN)
254 return listen(sockfd, backlog);
256 # error listen not available
260 inline static off_t system_lseek(int fildes, off_t offset, int whence)
262 #if defined(HAVE_LSEEK)
263 return lseek(fildes, offset, whence);
265 # error lseek not available
269 inline static void *system_malloc(size_t size)
271 #if defined(HAVE_MALLOC)
274 # error malloc not available
278 inline static void *system_memcpy(void *dest, const void *src, size_t n)
280 #if defined(HAVE_MEMCPY)
281 return memcpy(dest, src, n);
283 # error memcpy not available
287 inline static void *system_memset(void *s, int c, size_t n)
289 #if defined(HAVE_MEMSET)
290 return memset(s, c, n);
292 # error memset not available
296 inline static int system_mprotect(void *addr, size_t len, int prot)
298 #if defined(HAVE_MPROTECT)
299 return mprotect(addr, len, prot);
301 # error mprotect not available
305 inline static int system_open(const char *pathname, int flags, mode_t mode)
307 #if defined(HAVE_OPEN)
308 return open(pathname, flags, mode);
310 # error open not available
314 inline static ssize_t system_read(int fd, void *buf, size_t count)
316 #if defined(HAVE_READ)
317 return read(fd, buf, count);
319 # error read not available
323 inline static void *system_realloc(void *ptr, size_t size)
325 #if defined(HAVE_REALLOC)
326 return realloc(ptr, size);
328 # error realloc not available
332 #if defined(__LINUX__)
333 inline static int system_scandir(const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const void *, const void *))
334 #elif defined(__IRIX__)
335 inline static int system_scandir(const char *dir, struct dirent ***namelist, int(*filter)(dirent_t *), int(*compar)(dirent_t **, dirent_t **))
337 inline static int system_scandir(const char *dir, struct dirent ***namelist, int(*filter)(struct dirent *), int(*compar)(const void *, const void *))
340 #if defined(HAVE_SCANDIR)
341 return scandir(dir, namelist, filter, compar);
343 # error scandir not available
347 inline static int system_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
349 #if defined(HAVE_SETSOCKOPT)
350 return setsockopt(s, level, optname, optval, optlen);
352 # error setsockopt not available
356 inline static int system_shutdown(int s, int how)
358 #if defined(HAVE_SHUTDOWN)
359 return shutdown(s, how);
361 # error shutdown not available
365 inline static int system_socket(int domain, int type, int protocol)
367 #if defined(HAVE_SOCKET)
368 return socket(domain, type, protocol);
370 # error socket not available
374 inline static int system_stat(const char *path, struct stat *buf)
376 #if defined(HAVE_STAT)
377 return stat(path, buf);
379 # error stat not available
383 inline static char *system_strcat(char *dest, const char *src)
385 #if defined(HAVE_STRCAT)
386 return strcat(dest, src);
388 # error strcat not available
392 inline static char *system_strcpy(char *dest, const char *src)
394 #if defined(HAVE_STRCPY)
395 return strcpy(dest, src);
397 # error strcpy not available
401 inline static char *system_strdup(const char *s)
403 #if defined(HAVE_STRDUP)
406 # error strdup not available
410 inline static char *system_strerror(int errnum)
412 #if defined(HAVE_STRERROR)
413 return strerror(errnum);
415 # error strerror not available
419 inline static size_t system_strlen(const char *s)
421 #if defined(HAVE_STRLEN)
424 # error strlen not available
428 inline static ssize_t system_write(int fd, const void *buf, size_t count)
430 #if defined(HAVE_WRITE)
431 return write(fd, buf, count);
433 # error write not available
438 /* function prototypes ********************************************************/
440 void *system_mmap_anonymous(void *addr, size_t len, int prot, int flags);
441 int system_processors_online(void);
443 #endif /* _VMCORE_SYSTEM_H */
447 * These are local overrides for various environment variables in Emacs.
448 * Please do not remove this and leave it at the end of the file, where
449 * Emacs will automagically detect them.
450 * ---------------------------------------------------------------------
453 * indent-tabs-mode: t
457 * vim:noexpandtab:sw=4:ts=4: