sync with trunk (r46275)
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 #if defined(__GNUC__) && !defined(__INTERIX) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__APPLE__)
154 # define __ASM_GLOBAL_FUNC(name,code) \
155 __asm__( ".text\n\t" \
156 ".align 4\n\t" \
157 ".globl " __ASM_NAME(#name) "\n\t" \
158 __ASM_FUNC(#name) "\n" \
159 __ASM_NAME(#name) ":\n\t" \
160 code \
161 "\n\t.previous" );
162 #else /* defined(__GNUC__) && !defined(__MINGW32__) && !defined(__APPLE__) */
163 # define __ASM_GLOBAL_FUNC(name,code) \
164 void __asm_dummy_##name(void) { \
165 asm( ".align 4\n\t" \
166 ".globl " __ASM_NAME(#name) "\n\t" \
167 __ASM_FUNC(#name) "\n" \
168 __ASM_NAME(#name) ":\n\t" \
169 code ); \
170 }
171 #endif /* __GNUC__ */
172
173
174 /* Constructor functions */
175
176 #ifdef __GNUC__
177 # define DECL_GLOBAL_CONSTRUCTOR(func) \
178 static void func(void) __attribute__((constructor)); \
179 static void func(void)
180 #elif defined(__i386__)
181 # define DECL_GLOBAL_CONSTRUCTOR(func) \
182 static void __dummy_init_##func(void) { \
183 asm(".section .init,\"ax\"\n\t" \
184 "call " #func "\n\t" \
185 ".previous"); } \
186 static void func(void)
187 #elif defined(__sparc__)
188 # define DECL_GLOBAL_CONSTRUCTOR(func) \
189 static void __dummy_init_##func(void) { \
190 asm("\t.section \".init\",#alloc,#execinstr\n" \
191 "\tcall " #func "\n" \
192 "\tnop\n" \
193 "\t.section \".text\",#alloc,#execinstr\n" ); } \
194 static void func(void)
195 #else
196 # error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
197 #endif
198
199
200 /* Register functions */
201
202 #ifdef __i386__
203 #define DEFINE_REGS_ENTRYPOINT( name, fn, args, pop_args ) \
204 __ASM_GLOBAL_FUNC( name, \
205 "call " __ASM_NAME("__wine_call_from_32_regs") "\n\t" \
206 ".long " __ASM_NAME(#fn) "\n\t" \
207 ".byte " #args "," #pop_args )
208 /* FIXME: add support for other CPUs */
209 #endif /* __i386__ */
210
211
212 /****************************************************************
213 * Function definitions (only when using libwine_port)
214 */
215
216 #ifndef NO_LIBWINE_PORT
217
218 #ifndef HAVE_GETOPT_LONG
219 extern char *optarg;
220 extern int optind;
221 extern int opterr;
222 extern int optopt;
223 struct option;
224
225 #ifndef HAVE_STRUCT_OPTION_NAME
226 struct option
227 {
228 const char *name;
229 int has_arg;
230 int *flag;
231 int val;
232 };
233 #endif
234
235 extern int getopt_long (int ___argc, char *const *___argv,
236 const char *__shortopts,
237 const struct option *__longopts, int *__longind);
238 extern int getopt_long_only (int ___argc, char *const *___argv,
239 const char *__shortopts,
240 const struct option *__longopts, int *__longind);
241 #endif /* HAVE_GETOPT_LONG */
242
243 #ifndef HAVE_GETPAGESIZE
244 size_t getpagesize(void);
245 #endif /* HAVE_GETPAGESIZE */
246
247 #ifndef HAVE_LSTAT
248 int lstat(const char *file_name, struct stat *buf);
249 #endif /* HAVE_LSTAT */
250
251 #ifndef HAVE_MEMMOVE
252 void *memmove(void *dest, const void *src, size_t len);
253 #endif /* !defined(HAVE_MEMMOVE) */
254
255 #ifndef __REACTOS__
256 #ifndef HAVE_PREAD
257 ssize_t pread( int fd, void *buf, size_t count, off_t offset );
258 #endif /* HAVE_PREAD */
259
260 #ifndef HAVE_PWRITE
261 ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
262 #endif /* HAVE_PWRITE */
263 #endif /* __REACTOS__ */
264
265 #ifdef WIN32
266 #ifndef HAVE_SIGSETJMP
267 # include <setjmp.h>
268 typedef jmp_buf sigjmp_buf;
269 int sigsetjmp( sigjmp_buf buf, int savesigs );
270 void siglongjmp( sigjmp_buf buf, int val );
271 #endif /* HAVE_SIGSETJMP */
272 #endif
273
274 #ifndef HAVE_STATFS
275 int statfs(const char *name, struct statfs *info);
276 #endif /* !defined(HAVE_STATFS) */
277
278 #ifndef HAVE_STRNCASECMP
279 # ifndef HAVE__STRNICMP
280 int strncasecmp(const char *str1, const char *str2, size_t n);
281 # else
282 # define strncasecmp _strnicmp
283 # endif
284 #endif /* !defined(HAVE_STRNCASECMP) */
285
286 #ifndef HAVE_STRERROR
287 const char *strerror(int err);
288 #endif /* !defined(HAVE_STRERROR) */
289
290 #ifndef HAVE_STRCASECMP
291 # ifndef HAVE__STRICMP
292 int strcasecmp(const char *str1, const char *str2);
293 # else
294 # define strcasecmp _stricmp
295 # endif
296 #endif /* !defined(HAVE_STRCASECMP) */
297
298 #if !defined(HAVE_USLEEP) && !defined(__CYGWIN__)
299 int usleep (unsigned int useconds);
300 #endif /* !defined(HAVE_USLEEP) */
301
302 #ifdef __i386__
303 static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
304 {
305 return memcpy( dst, src, size );
306 }
307 #else
308 extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
309 #endif /* __i386__ */
310
311 extern int mkstemps(char *template, int suffix_len);
312
313 /* Process creation flags */
314 #ifndef _P_WAIT
315 # define _P_WAIT 0
316 # define _P_NOWAIT 1
317 # define _P_OVERLAY 2
318 # define _P_NOWAITO 3
319 # define _P_DETACH 4
320 #endif
321 #ifndef HAVE_SPAWNVP
322 extern int spawnvp(int mode, const char *cmdname, const char * const argv[]);
323 #endif
324
325 /* Interlocked functions */
326
327 #if defined(_MSC_VER) || (defined(__i386__) && defined(__GNUC__) && !defined(WINE_PORT_NO_INTERLOCKED))
328
329 #define interlocked_cmpxchg InterlockedCompareExchange
330 #define interlocked_cmpxchg_ptr InterlockedCompareExchangePtr
331 #define interlocked_xchg InterlockedExchange
332 #define interlocked_xchg_ptr InterlockedExchangePtr
333 #define interlocked_xchg_add InterlockedExchangeAdd
334
335
336 #endif /* __i386___ && __GNUC__ */
337
338 #else /* NO_LIBWINE_PORT */
339
340 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
341
342 #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
343 #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
344 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
345 #define lstat __WINE_NOT_PORTABLE(lstat)
346 #define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
347 #define memmove __WINE_NOT_PORTABLE(memmove)
348 #define pread __WINE_NOT_PORTABLE(pread)
349 #define pwrite __WINE_NOT_PORTABLE(pwrite)
350 #define spawnvp __WINE_NOT_PORTABLE(spawnvp)
351 #define statfs __WINE_NOT_PORTABLE(statfs)
352 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
353 #define strerror __WINE_NOT_PORTABLE(strerror)
354 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
355 #define usleep __WINE_NOT_PORTABLE(usleep)
356
357 #endif /* NO_LIBWINE_PORT */
358
359 #endif /* !defined(__WINE_WINE_PORT_H) */