* configure.ac (AC_CHECK_FUNCS): Added read, write.
[cacao.git] / src / vmcore / system.h
1 /* src/vmcore/system.h - system (OS) functions
2
3    Copyright (C) 2007
4    CACAOVM - Verein zu Foerderung der freien virtuellen Machine 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
59 /* inline functions ***********************************************************/
60
61 inline static void *system_calloc(size_t nmemb, size_t size)
62 {
63 #if defined(HAVE_CALLOC)
64         return calloc(nmemb, size);
65 #else
66 # error calloc not available
67 #endif
68 }
69
70 inline static int system_close(int fd)
71 {
72 #if defined(HAVE_CLOSE)
73         return close(fd);
74 #else
75 # error close not available
76 #endif
77 }
78
79 inline static void system_free(void *ptr)
80 {
81 #if defined(HAVE_FREE)
82         free(ptr);
83 #else
84 # error free not available
85 #endif
86 }
87
88 inline static int system_getpagesize(void)
89 {
90 #if defined(HAVE_GETPAGESIZE)
91         return getpagesize();
92 #else
93 # error getpagesize not available
94 #endif
95 }
96
97 inline static void *system_malloc(size_t size)
98 {
99 #if defined(HAVE_MALLOC)
100         return malloc(size);
101 #else
102 # error malloc not available
103 #endif
104 }
105
106 inline static void *system_memcpy(void *dest, const void *src, size_t n)
107 {
108 #if defined(HAVE_MEMCPY)
109         return memcpy(dest, src, n);
110 #else
111 # error memcpy not available
112 #endif
113 }
114
115 inline static void *system_memset(void *s, int c, size_t n)
116 {
117 #if defined(HAVE_MEMSET)
118         return memset(s, c, n);
119 #else
120 # error memset not available
121 #endif
122 }
123
124 inline static int system_mprotect(void *addr, size_t len, int prot)
125 {
126 #if defined(HAVE_MPROTECT)
127         return mprotect(addr, len, prot);
128 #else
129 # error mprotect not available
130 #endif
131 }
132
133 inline static int system_open(const char *pathname, int flags, mode_t mode)
134 {
135 #if defined(HAVE_OPEN)
136         return open(pathname, flags, mode);
137 #else
138 # error open not available
139 #endif
140 }
141
142 inline static ssize_t system_read(int fd, void *buf, size_t count)
143 {
144 #if defined(HAVE_READ)
145         return read(fd, buf, count);
146 #else
147 # error read not available
148 #endif
149 }
150
151 inline static void *system_realloc(void *ptr, size_t size)
152 {
153 #if defined(HAVE_REALLOC)
154         return realloc(ptr, size);
155 #else
156 # error realloc not available
157 #endif
158 }
159
160 inline static ssize_t system_write(int fd, const void *buf, size_t count)
161 {
162 #if defined(HAVE_WRITE)
163         return write(fd, buf, count);
164 #else
165 # error write not available
166 #endif
167 }
168
169
170 /* function prototypes ********************************************************/
171
172 void *system_mmap_anonymous(void *addr, size_t len, int prot, int flags);
173 int   system_processors_online(void);
174
175 #endif /* _VMCORE_SYSTEM_H */
176
177
178 /*
179  * These are local overrides for various environment variables in Emacs.
180  * Please do not remove this and leave it at the end of the file, where
181  * Emacs will automagically detect them.
182  * ---------------------------------------------------------------------
183  * Local variables:
184  * mode: c
185  * indent-tabs-mode: t
186  * c-basic-offset: 4
187  * tab-width: 4
188  * End:
189  * vim:noexpandtab:sw=4:ts=4:
190  */