The real, definitive, Visual C++ support branch. Accept no substitutes
[reactos.git] / include / reactos / wine / port.h
1 /*
2 * Wine porting definitions
3 *
4 * Copyright 1996 Alexandre Julliard
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifndef __WINE_WINE_PORT_H
22 #define __WINE_WINE_PORT_H
23
24 #ifndef __WINE_CONFIG_H
25 # error You must include config.h to use this header
26 #endif
27
28 #define _GNU_SOURCE /* for pread/pwrite */
29 #include <fcntl.h>
30 #include <math.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #ifdef HAVE_DIRECT_H
34 # include <direct.h>
35 #endif
36 #ifdef HAVE_IO_H
37 # include <io.h>
38 #endif
39 #ifdef HAVE_PROCESS_H
40 # include <process.h>
41 #endif
42 #include <string.h>
43 #ifdef HAVE_UNISTD_H
44 # include <unistd.h>
45 #endif
46
47
48 /****************************************************************
49 * Type definitions
50 */
51
52 #if !defined(_MSC_VER) && !defined(__int64)
53 # if defined(__x86_64__) || defined(_WIN64)
54 # define __int64 long
55 # else
56 # define __int64 long long
57 # endif
58 #endif
59
60 #ifndef HAVE_MODE_T
61 typedef int mode_t;
62 #endif
63 #ifndef HAVE_OFF_T
64 typedef long off_t;
65 #endif
66 #ifndef HAVE_PID_T
67 typedef int pid_t;
68 #endif
69 #ifndef HAVE_SIZE_T
70 typedef unsigned int size_t;
71 #endif
72 #ifndef HAVE_SSIZE_T
73 typedef int ssize_t;
74 #endif
75 //#ifndef HAVE_SOCKLEN_T
76 //typedef unsigned int socklen_t;
77 //#endif
78
79 #ifndef HAVE_STATFS
80 # ifdef __BEOS__
81 # define HAVE_STRUCT_STATFS_F_BFREE
82 struct statfs {
83 long f_bsize; /* block_size */
84 long f_blocks; /* total_blocks */
85 long f_bfree; /* free_blocks */
86 };
87 # else /* defined(__BEOS__) */
88 struct statfs;
89 # endif /* defined(__BEOS__) */
90 #endif /* !defined(HAVE_STATFS) */
91
92
93 /****************************************************************
94 * Macro definitions
95 */
96
97 #ifdef HAVE_DLFCN_H
98 #include <dlfcn.h>
99 #else
100 #define RTLD_LAZY 0x001
101 #define RTLD_NOW 0x002
102 #define RTLD_GLOBAL 0x100
103 #endif
104
105 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
106 #define ftruncate chsize
107 #endif
108
109 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
110 #define popen _popen
111 #endif
112
113 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
114 #define pclose _pclose
115 #endif
116
117 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
118 #define snprintf _snprintf
119 #endif
120
121 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
122 #define vsnprintf _vsnprintf
123 #endif
124
125 #ifndef S_ISLNK
126 # define S_ISLNK(mod) (0)
127 #endif /* S_ISLNK */
128
129 /* So we open files in 64 bit access mode on Linux */
130 #ifndef O_LARGEFILE
131 # define O_LARGEFILE 0
132 #endif
133
134 #ifndef O_BINARY
135 # define O_BINARY 0
136 #endif
137
138 /****************************************************************
139 * Constants
140 */
141
142 #ifndef M_PI
143 #define M_PI 3.14159265358979323846
144 #endif
145
146 #ifndef M_PI_2
147 #define M_PI_2 1.570796326794896619
148 #endif
149
150
151 /* Macros to define assembler functions somewhat portably */
152
153 #ifdef __GNUC__
154 # define __ASM_GLOBAL_FUNC(name,code) \
155 __asm__( ".align 4\n\t" \
156 ".globl " __ASM_NAME(#name) "\n\t" \
157 __ASM_FUNC(#name) "\n" \
158 __ASM_NAME(#name) ":\n\t" \
159 code );
160 #else /* __GNUC__ */
161 # define __ASM_GLOBAL_FUNC(name,code) \
162 void __asm_dummy_##name(void) { \
163 asm( ".align 4\n\t" \
164 ".globl " __ASM_NAME(#name) "\n\t" \
165 __ASM_FUNC(#name) "\n" \
166 __ASM_NAME(#name) ":\n\t" \
167 code ); \
168 }
169 #endif /* __GNUC__ */
170
171
172 /* Constructor functions */
173
174 #ifdef __GNUC__
175 # define DECL_GLOBAL_CONSTRUCTOR(func) \
176 static void func(void) __attribute__((constructor)); \
177 static void func(void)
178 #elif defined(__i386__)
179 # define DECL_GLOBAL_CONSTRUCTOR(func) \
180 static void __dummy_init_##func(void) { \
181 asm(".section .init,\"ax\"\n\t" \
182 "call " #func "\n\t" \
183 ".previous"); } \
184 static void func(void)
185 #elif defined(__sparc__)
186 # define DECL_GLOBAL_CONSTRUCTOR(func) \
187 static void __dummy_init_##func(void) { \
188 asm("\t.section \".init\",#alloc,#execinstr\n" \
189 "\tcall " #func "\n" \
190 "\tnop\n" \
191 "\t.section \".text\",#alloc,#execinstr\n" ); } \
192 static void func(void)
193 #else
194 # error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
195 #endif
196
197
198 /* Register functions */
199
200 #ifdef __i386__
201 #define DEFINE_REGS_ENTRYPOINT( name, fn, args, pop_args ) \
202 __ASM_GLOBAL_FUNC( name, \
203 "call " __ASM_NAME("__wine_call_from_32_regs") "\n\t" \
204 ".long " __ASM_NAME(#fn) "\n\t" \
205 ".byte " #args "," #pop_args )
206 /* FIXME: add support for other CPUs */
207 #endif /* __i386__ */
208
209
210 /****************************************************************
211 * Function definitions (only when using libwine_port)
212 */
213
214 #ifndef NO_LIBWINE_PORT
215
216 #ifndef HAVE_GETOPT_LONG
217 extern char *optarg;
218 extern int optind;
219 extern int opterr;
220 extern int optopt;
221 struct option;
222
223 #ifndef HAVE_STRUCT_OPTION_NAME
224 struct option
225 {
226 const char *name;
227 int has_arg;
228 int *flag;
229 int val;
230 };
231 #endif
232
233 extern int getopt_long (int ___argc, char *const *___argv,
234 const char *__shortopts,
235 const struct option *__longopts, int *__longind);
236 extern int getopt_long_only (int ___argc, char *const *___argv,
237 const char *__shortopts,
238 const struct option *__longopts, int *__longind);
239 #endif /* HAVE_GETOPT_LONG */
240
241 #ifndef HAVE_GETPAGESIZE
242 size_t getpagesize(void);
243 #endif /* HAVE_GETPAGESIZE */
244
245 #ifndef HAVE_GETTID
246 pid_t gettid(void);
247 #endif /* HAVE_GETTID */
248
249 #ifndef HAVE_LSTAT
250 int lstat(const char *file_name, struct stat *buf);
251 #endif /* HAVE_LSTAT */
252
253 #ifndef HAVE_MEMMOVE
254 void *memmove(void *dest, const void *src, size_t len);
255 #endif /* !defined(HAVE_MEMMOVE) */
256
257 #ifndef __REACTOS__
258 #ifndef HAVE_PREAD
259 ssize_t pread( int fd, void *buf, size_t count, off_t offset );
260 #endif /* HAVE_PREAD */
261
262 #ifndef HAVE_PWRITE
263 ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
264 #endif /* HAVE_PWRITE */
265 #endif /* __REACTOS__ */
266
267 #ifdef WIN32
268 #ifndef HAVE_SIGSETJMP
269 # include <setjmp.h>
270 typedef jmp_buf sigjmp_buf;
271 int sigsetjmp( sigjmp_buf buf, int savesigs );
272 void siglongjmp( sigjmp_buf buf, int val );
273 #endif /* HAVE_SIGSETJMP */
274 #endif
275
276 #ifndef HAVE_STATFS
277 int statfs(const char *name, struct statfs *info);
278 #endif /* !defined(HAVE_STATFS) */
279
280 #ifndef HAVE_STRNCASECMP
281 # ifndef HAVE__STRNICMP
282 int strncasecmp(const char *str1, const char *str2, size_t n);
283 # else
284 # define strncasecmp _strnicmp
285 # endif
286 #endif /* !defined(HAVE_STRNCASECMP) */
287
288 #ifndef HAVE_STRERROR
289 const char *strerror(int err);
290 #endif /* !defined(HAVE_STRERROR) */
291
292 #ifndef HAVE_STRCASECMP
293 # ifndef HAVE__STRICMP
294 int strcasecmp(const char *str1, const char *str2);
295 # else
296 # define strcasecmp _stricmp
297 # endif
298 #endif /* !defined(HAVE_STRCASECMP) */
299
300 #if !defined(HAVE_USLEEP) && !defined(__CYGWIN__)
301 int usleep (unsigned int useconds);
302 #endif /* !defined(HAVE_USLEEP) */
303
304 #ifdef __i386__
305 static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
306 {
307 return memcpy( dst, src, size );
308 }
309 #else
310 extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
311 #endif /* __i386__ */
312
313 extern int mkstemps(char *template, int suffix_len);
314
315 /* Process creation flags */
316 #ifndef _P_WAIT
317 # define _P_WAIT 0
318 # define _P_NOWAIT 1
319 # define _P_OVERLAY 2
320 # define _P_NOWAITO 3
321 # define _P_DETACH 4
322 #endif
323 #ifndef HAVE_SPAWNVP
324 extern int spawnvp(int mode, const char *cmdname, const char * const argv[]);
325 #endif
326
327 /* Interlocked functions */
328
329 #if defined(__i386__) && defined(__GNUC__) && !defined(WINE_PORT_NO_INTERLOCKED)
330
331 #define interlocked_cmpxchg InterlockedCompareExchange
332 #define interlocked_cmpxchg_ptr InterlockedCompareExchangePtr
333 #define interlocked_xchg InterlockedExchange
334 #define interlocked_xchg_ptr InterlockedExchangePtr
335 #define interlocked_xchg_add InterlockedExchangeAdd
336
337
338 #endif /* __i386___ && __GNUC__ */
339
340 #else /* NO_LIBWINE_PORT */
341
342 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
343
344 #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
345 #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
346 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
347 #define lstat __WINE_NOT_PORTABLE(lstat)
348 #define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
349 #define memmove __WINE_NOT_PORTABLE(memmove)
350 #define pread __WINE_NOT_PORTABLE(pread)
351 #define pwrite __WINE_NOT_PORTABLE(pwrite)
352 #define spawnvp __WINE_NOT_PORTABLE(spawnvp)
353 #define statfs __WINE_NOT_PORTABLE(statfs)
354 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
355 #define strerror __WINE_NOT_PORTABLE(strerror)
356 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
357 #define usleep __WINE_NOT_PORTABLE(usleep)
358
359 #endif /* NO_LIBWINE_PORT */
360
361 #endif /* !defined(__WINE_WINE_PORT_H) */