2 * Wine porting definitions
4 * Copyright 1996 Alexandre Julliard
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.
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.
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 St, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifndef __WINE_WINE_PORT_H
22 #define __WINE_WINE_PORT_H
24 #ifndef __WINE_CONFIG_H
25 # error You must include config.h to use this header
29 # define _GNU_SOURCE /* for pread/pwrite, isfinite */
33 #include <sys/types.h>
50 /****************************************************************
54 #if !defined(_MSC_VER) && !defined(__int64)
55 # if defined(__x86_64__) || defined(_WIN64)
58 # define __int64 long long
62 #if !defined(HAVE_MODE_T) && !defined(_MODE_T)
65 #if !defined(HAVE_OFF_T) && !defined(_OFF_T)
68 #if !defined(HAVE_PID_T) && !defined(_PID_T)
71 #if !defined(HAVE_SIZE_T) && !defined(_SIZE_T)
72 typedef unsigned int size_t;
74 #if !defined(HAVE_SSIZE_T) && !defined(_SSIZE_T)
77 //#ifndef HAVE_SOCKLEN_T
78 //typedef unsigned int socklen_t;
83 # define HAVE_STRUCT_STATFS_F_BFREE
85 long f_bsize
; /* block_size */
86 long f_blocks
; /* total_blocks */
87 long f_bfree
; /* free_blocks */
89 # else /* defined(__BEOS__) */
91 # endif /* defined(__BEOS__) */
92 #endif /* !defined(HAVE_STATFS) */
95 /****************************************************************
102 #define RTLD_LAZY 0x001
103 #define RTLD_NOW 0x002
104 #define RTLD_GLOBAL 0x100
107 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
108 #define ftruncate chsize
111 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
115 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
116 #define pclose _pclose
119 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
120 #define snprintf _snprintf
123 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
124 #define vsnprintf _vsnprintf
128 # define S_ISLNK(mod) (0)
131 /* So we open files in 64 bit access mode on Linux */
133 # define O_LARGEFILE 0
140 /****************************************************************
145 #define M_PI 3.14159265358979323846
149 #define M_PI_2 1.570796326794896619
153 #define M_PI_4 0.785398163397448309616
157 static inline float __port_infinity(void)
159 static const unsigned __inf_bytes
= 0x7f800000;
160 return *(const float *)&__inf_bytes
;
162 #define INFINITY __port_infinity()
166 static inline float __port_nan(void)
168 static const unsigned __nan_bytes
= 0x7fc00000;
169 return *(const float *)&__nan_bytes
;
171 #define NAN __port_nan()
174 /* Constructor functions */
177 # define DECL_GLOBAL_CONSTRUCTOR(func) /* nothing */
178 #elif defined(__GNUC__)
179 # define DECL_GLOBAL_CONSTRUCTOR(func) \
180 static void func(void) __attribute__((constructor)); \
181 static void func(void)
182 #elif defined(__i386__)
183 # define DECL_GLOBAL_CONSTRUCTOR(func) \
184 static void __dummy_init_##func(void) { \
185 asm(".section .init,\"ax\"\n\t" \
186 "call " #func "\n\t" \
188 static void func(void)
189 #elif defined(__sparc__)
190 # define DECL_GLOBAL_CONSTRUCTOR(func) \
191 static void __dummy_init_##func(void) { \
192 asm("\t.section \".init\",#alloc,#execinstr\n" \
193 "\tcall " #func "\n" \
195 "\t.section \".text\",#alloc,#execinstr\n" ); } \
196 static void func(void)
197 #elif defined(_M_AMD64)
198 #pragma message("You must define the DECL_GLOBAL_CONSTRUCTOR macro for amd64")
200 # error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
204 /* Register functions */
207 #define DEFINE_REGS_ENTRYPOINT( name, fn, args, pop_args ) \
208 __ASM_GLOBAL_FUNC( name, \
209 "call " __ASM_NAME("__wine_call_from_32_regs") "\n\t" \
210 ".long " __ASM_NAME(#fn) "\n\t" \
211 ".byte " #args "," #pop_args )
212 /* FIXME: add support for other CPUs */
213 #endif /* __i386__ */
216 /****************************************************************
217 * Function definitions (only when using libwine_port)
220 #ifndef NO_LIBWINE_PORT
222 #ifndef HAVE_GETOPT_LONG
229 #ifndef HAVE_STRUCT_OPTION_NAME
239 extern int getopt_long (int ___argc
, char *const *___argv
,
240 const char *__shortopts
,
241 const struct option
*__longopts
, int *__longind
);
242 extern int getopt_long_only (int ___argc
, char *const *___argv
,
243 const char *__shortopts
,
244 const struct option
*__longopts
, int *__longind
);
245 #endif /* HAVE_GETOPT_LONG */
247 #ifndef HAVE_GETPAGESIZE
248 size_t getpagesize(void);
249 #endif /* HAVE_GETPAGESIZE */
251 #if !defined(HAVE_ISFINITE) && !defined(isfinite)
252 int isfinite(double x
);
255 #if !defined(HAVE_ISINF) && !defined(isinf)
259 #if !defined(HAVE_ISNAN) && !defined(isnan)
264 int lstat(const char *file_name
, struct stat
*buf
);
265 #endif /* HAVE_LSTAT */
268 void *memmove(void *dest
, const void *src
, size_t len
);
269 #endif /* !defined(HAVE_MEMMOVE) */
273 ssize_t
pread( int fd
, void *buf
, size_t count
, off_t offset
);
274 #endif /* HAVE_PREAD */
277 ssize_t
pwrite( int fd
, const void *buf
, size_t count
, off_t offset
);
278 #endif /* HAVE_PWRITE */
279 #endif /* __REACTOS__ */
282 #ifndef HAVE_SIGSETJMP
284 typedef jmp_buf sigjmp_buf
;
285 int sigsetjmp( sigjmp_buf buf
, int savesigs
);
286 void siglongjmp( sigjmp_buf buf
, int val
);
287 #endif /* HAVE_SIGSETJMP */
291 int statfs(const char *name
, struct statfs
*info
);
292 #endif /* !defined(HAVE_STATFS) */
294 #ifndef HAVE_STRNCASECMP
295 # ifndef HAVE__STRNICMP
296 int strncasecmp(const char *str1
, const char *str2
, size_t n
);
298 # define strncasecmp _strnicmp
300 #endif /* !defined(HAVE_STRNCASECMP) */
302 #ifndef HAVE_STRERROR
303 const char *strerror(int err
);
304 #endif /* !defined(HAVE_STRERROR) */
306 #ifndef HAVE_STRCASECMP
307 # ifndef HAVE__STRICMP
308 int strcasecmp(const char *str1
, const char *str2
);
310 # define strcasecmp _stricmp
312 #endif /* !defined(HAVE_STRCASECMP) */
314 #if !defined(HAVE_USLEEP) && !defined(__CYGWIN__)
315 int usleep (unsigned int useconds
);
316 #endif /* !defined(HAVE_USLEEP) */
319 static inline void *memcpy_unaligned( void *dst
, const void *src
, size_t size
)
321 return memcpy( dst
, src
, size
);
324 extern void *memcpy_unaligned( void *dst
, const void *src
, size_t size
);
325 #endif /* __i386__ */
327 extern int mkstemps(char *template, int suffix_len
);
329 /* Process creation flags */
333 # define _P_OVERLAY 2
334 # define _P_NOWAITO 3
338 extern int spawnvp(int mode
, const char *cmdname
, const char * const argv
[]);
341 /* Interlocked functions */
343 #if defined(_MSC_VER) || (defined(__i386__) && defined(__GNUC__) && !defined(WINE_PORT_NO_INTERLOCKED))
345 #define interlocked_cmpxchg InterlockedCompareExchange
346 #define interlocked_cmpxchg_ptr InterlockedCompareExchangePtr
347 #define interlocked_xchg InterlockedExchange
348 #define interlocked_xchg_ptr InterlockedExchangePtr
349 #define interlocked_xchg_add InterlockedExchangeAdd
352 #endif /* __i386___ && __GNUC__ */
354 #if defined(_MSC_VER)
360 if (_BitScanForward(&index
, mask
) == 0) return 0;
364 #define ffs __builtin_ffs
367 #else /* NO_LIBWINE_PORT */
369 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
371 #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
372 #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
373 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
374 #define lstat __WINE_NOT_PORTABLE(lstat)
375 #define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
376 #define memmove __WINE_NOT_PORTABLE(memmove)
377 #define pread __WINE_NOT_PORTABLE(pread)
378 #define pwrite __WINE_NOT_PORTABLE(pwrite)
379 #define spawnvp __WINE_NOT_PORTABLE(spawnvp)
380 #define statfs __WINE_NOT_PORTABLE(statfs)
381 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
382 #define strerror __WINE_NOT_PORTABLE(strerror)
383 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
384 #define usleep __WINE_NOT_PORTABLE(usleep)
386 #endif /* NO_LIBWINE_PORT */
388 #endif /* !defined(__WINE_WINE_PORT_H) */