* m4/assertion.m4: Fixed copyright header.
[cacao.git] / src / vmcore / system.h
1 /* src/vmcore/system.h - system (OS) functions
2
3    Copyright (C) 2007
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_FCNTL_H)
35 # include <fcntl.h>
36 #endif
37
38 #if defined(HAVE_STDINT_H)
39 # include <stdint.h>
40 #endif
41
42 #if defined(HAVE_STDLIB_H)
43 # include <stdlib.h>
44 #endif
45
46 #if defined(HAVE_STRING_H)
47 # include <string.h>
48 #endif
49
50 #if defined(HAVE_UNISTD_H)
51 # include <unistd.h>
52 #endif
53
54 #if defined(HAVE_SYS_MMAN_H)
55 # include <sys/mman.h>
56 #endif
57
58 #if defined(HAVE_SYS_SOCKET_H)
59 # include <sys/socket.h>
60 #endif
61
62 #if defined(HAVE_SYS_TYPES_H)
63 # include <sys/types.h>
64 #endif
65
66
67 /* inline functions ***********************************************************/
68
69 inline static int system_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
70 {
71 #if defined(HAVE_ACCEPT)
72         return accept(sockfd, addr, addrlen);
73 #else
74 # error accept not available
75 #endif
76 }
77
78 inline static void *system_calloc(size_t nmemb, size_t size)
79 {
80 #if defined(HAVE_CALLOC)
81         return calloc(nmemb, size);
82 #else
83 # error calloc not available
84 #endif
85 }
86
87 inline static int system_close(int fd)
88 {
89 #if defined(HAVE_CLOSE)
90         return close(fd);
91 #else
92 # error close not available
93 #endif
94 }
95
96 inline static int system_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
97 {
98 #if defined(HAVE_CONNECT)
99         return connect(sockfd, serv_addr, addrlen);
100 #else
101 # error connect not available
102 #endif
103 }
104
105 inline static void system_free(void *ptr)
106 {
107 #if defined(HAVE_FREE)
108         free(ptr);
109 #else
110 # error free not available
111 #endif
112 }
113
114 inline static int system_fsync(int fd)
115 {
116 #if defined(HAVE_FSYNC)
117         return fsync(fd);
118 #else
119 # error fsync not available
120 #endif
121 }
122
123 inline static int system_ftruncate(int fd, off_t length)
124 {
125 #if defined(HAVE_FTRUNCATE)
126         return ftruncate(fd, length);
127 #else
128 # error ftruncate not available
129 #endif
130 }
131
132 inline static int system_gethostname(char *name, size_t len)
133 {
134 #if defined(HAVE_GETHOSTNAME)
135         return gethostname(name, len);
136 #else
137 # error gethostname not available
138 #endif
139 }
140
141 inline static int system_getpagesize(void)
142 {
143 #if defined(HAVE_GETPAGESIZE)
144         return getpagesize();
145 #else
146 # error getpagesize not available
147 #endif
148 }
149
150 inline static int system_getsockname(int s, struct sockaddr *name, socklen_t *namelen)
151 {
152 #if defined(HAVE_GETSOCKNAME)
153         return getsockname(s, name, namelen);
154 #else
155 # error getsockname not available
156 #endif
157 }
158
159 inline static int system_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
160 {
161 #if defined(HAVE_GETSOCKOPT)
162         return getsockopt(s, level, optname, optval, optlen);
163 #else
164 # error getsockopt not available
165 #endif
166 }
167
168 inline static int system_listen(int sockfd, int backlog)
169 {
170 #if defined(HAVE_LISTEN)
171         return listen(sockfd, backlog);
172 #else
173 # error listen not available
174 #endif
175 }
176
177 inline static off_t system_lseek(int fildes, off_t offset, int whence)
178 {
179 #if defined(HAVE_LSEEK)
180         return lseek(fildes, offset, whence);
181 #else
182 # error lseek not available
183 #endif
184 }
185
186 inline static void *system_malloc(size_t size)
187 {
188 #if defined(HAVE_MALLOC)
189         return malloc(size);
190 #else
191 # error malloc not available
192 #endif
193 }
194
195 inline static void *system_memcpy(void *dest, const void *src, size_t n)
196 {
197 #if defined(HAVE_MEMCPY)
198         return memcpy(dest, src, n);
199 #else
200 # error memcpy not available
201 #endif
202 }
203
204 inline static void *system_memset(void *s, int c, size_t n)
205 {
206 #if defined(HAVE_MEMSET)
207         return memset(s, c, n);
208 #else
209 # error memset not available
210 #endif
211 }
212
213 inline static int system_mprotect(void *addr, size_t len, int prot)
214 {
215 #if defined(HAVE_MPROTECT)
216         return mprotect(addr, len, prot);
217 #else
218 # error mprotect not available
219 #endif
220 }
221
222 inline static int system_open(const char *pathname, int flags, mode_t mode)
223 {
224 #if defined(HAVE_OPEN)
225         return open(pathname, flags, mode);
226 #else
227 # error open not available
228 #endif
229 }
230
231 inline static ssize_t system_read(int fd, void *buf, size_t count)
232 {
233 #if defined(HAVE_READ)
234         return read(fd, buf, count);
235 #else
236 # error read not available
237 #endif
238 }
239
240 inline static void *system_realloc(void *ptr, size_t size)
241 {
242 #if defined(HAVE_REALLOC)
243         return realloc(ptr, size);
244 #else
245 # error realloc not available
246 #endif
247 }
248
249 inline static int system_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
250 {
251 #if defined(HAVE_SETSOCKOPT)
252         return setsockopt(s, level, optname, optval, optlen);
253 #else
254 # error setsockopt not available
255 #endif
256 }
257
258 inline static int system_shutdown(int s, int how)
259 {
260 #if defined(HAVE_SHUTDOWN)
261         return shutdown(s, how);
262 #else
263 # error shutdown not available
264 #endif
265 }
266
267 inline static int system_socket(int domain, int type, int protocol)
268 {
269 #if defined(HAVE_SOCKET)
270         return socket(domain, type, protocol);
271 #else
272 # error socket not available
273 #endif
274 }
275
276 inline static ssize_t system_write(int fd, const void *buf, size_t count)
277 {
278 #if defined(HAVE_WRITE)
279         return write(fd, buf, count);
280 #else
281 # error write not available
282 #endif
283 }
284
285
286 /* function prototypes ********************************************************/
287
288 void *system_mmap_anonymous(void *addr, size_t len, int prot, int flags);
289 int   system_processors_online(void);
290
291 #endif /* _VMCORE_SYSTEM_H */
292
293
294 /*
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  * ---------------------------------------------------------------------
299  * Local variables:
300  * mode: c
301  * indent-tabs-mode: t
302  * c-basic-offset: 4
303  * tab-width: 4
304  * End:
305  * vim:noexpandtab:sw=4:ts=4:
306  */