1 /* src/vmcore/system.h - system (OS) functions
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_FCNTL_H)
38 #if defined(HAVE_STDINT_H)
42 #if defined(HAVE_STDLIB_H)
46 #if defined(HAVE_STRING_H)
50 #if defined(HAVE_UNISTD_H)
54 #if defined(HAVE_SYS_MMAN_H)
55 # include <sys/mman.h>
58 #if defined(HAVE_SYS_SOCKET_H)
59 # include <sys/socket.h>
62 #if defined(HAVE_SYS_TYPES_H)
63 # include <sys/types.h>
67 /* inline functions ***********************************************************/
69 inline static int system_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
71 #if defined(HAVE_ACCEPT)
72 return accept(sockfd, addr, addrlen);
74 # error accept not available
78 inline static void *system_calloc(size_t nmemb, size_t size)
80 #if defined(HAVE_CALLOC)
81 return calloc(nmemb, size);
83 # error calloc not available
87 inline static int system_close(int fd)
89 #if defined(HAVE_CLOSE)
92 # error close not available
96 inline static int system_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
98 #if defined(HAVE_CONNECT)
99 return connect(sockfd, serv_addr, addrlen);
101 # error connect not available
105 inline static void system_free(void *ptr)
107 #if defined(HAVE_FREE)
110 # error free not available
114 inline static int system_fsync(int fd)
116 #if defined(HAVE_FSYNC)
119 # error fsync not available
123 inline static int system_ftruncate(int fd, off_t length)
125 #if defined(HAVE_FTRUNCATE)
126 return ftruncate(fd, length);
128 # error ftruncate not available
132 inline static int system_gethostname(char *name, size_t len)
134 #if defined(HAVE_GETHOSTNAME)
135 return gethostname(name, len);
137 # error gethostname not available
141 inline static int system_getpagesize(void)
143 #if defined(HAVE_GETPAGESIZE)
144 return getpagesize();
146 # error getpagesize not available
150 inline static int system_getsockname(int s, struct sockaddr *name, socklen_t *namelen)
152 #if defined(HAVE_GETSOCKNAME)
153 return getsockname(s, name, namelen);
155 # error getsockname not available
159 inline static int system_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
161 #if defined(HAVE_GETSOCKOPT)
162 return getsockopt(s, level, optname, optval, optlen);
164 # error getsockopt not available
168 inline static int system_listen(int sockfd, int backlog)
170 #if defined(HAVE_LISTEN)
171 return listen(sockfd, backlog);
173 # error listen not available
177 inline static off_t system_lseek(int fildes, off_t offset, int whence)
179 #if defined(HAVE_LSEEK)
180 return lseek(fildes, offset, whence);
182 # error lseek not available
186 inline static void *system_malloc(size_t size)
188 #if defined(HAVE_MALLOC)
191 # error malloc not available
195 inline static void *system_memcpy(void *dest, const void *src, size_t n)
197 #if defined(HAVE_MEMCPY)
198 return memcpy(dest, src, n);
200 # error memcpy not available
204 inline static void *system_memset(void *s, int c, size_t n)
206 #if defined(HAVE_MEMSET)
207 return memset(s, c, n);
209 # error memset not available
213 inline static int system_mprotect(void *addr, size_t len, int prot)
215 #if defined(HAVE_MPROTECT)
216 return mprotect(addr, len, prot);
218 # error mprotect not available
222 inline static int system_open(const char *pathname, int flags, mode_t mode)
224 #if defined(HAVE_OPEN)
225 return open(pathname, flags, mode);
227 # error open not available
231 inline static ssize_t system_read(int fd, void *buf, size_t count)
233 #if defined(HAVE_READ)
234 return read(fd, buf, count);
236 # error read not available
240 inline static void *system_realloc(void *ptr, size_t size)
242 #if defined(HAVE_REALLOC)
243 return realloc(ptr, size);
245 # error realloc not available
249 inline static int system_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
251 #if defined(HAVE_SETSOCKOPT)
252 return setsockopt(s, level, optname, optval, optlen);
254 # error setsockopt not available
258 inline static int system_shutdown(int s, int how)
260 #if defined(HAVE_SHUTDOWN)
261 return shutdown(s, how);
263 # error shutdown not available
267 inline static int system_socket(int domain, int type, int protocol)
269 #if defined(HAVE_SOCKET)
270 return socket(domain, type, protocol);
272 # error socket not available
276 inline static ssize_t system_write(int fd, const void *buf, size_t count)
278 #if defined(HAVE_WRITE)
279 return write(fd, buf, count);
281 # error write not available
286 /* function prototypes ********************************************************/
288 void *system_mmap_anonymous(void *addr, size_t len, int prot, int flags);
289 int system_processors_online(void);
291 #endif /* _VMCORE_SYSTEM_H */
295 * These are local overrides for various environment variables in Emacs.
296 * Please do not remove this and leave it at the end of the file, where
297 * Emacs will automagically detect them.
298 * ---------------------------------------------------------------------
301 * indent-tabs-mode: t
305 * vim:noexpandtab:sw=4:ts=4: