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