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
28 #ifdef __WINE_BASETSD_H
29 # error You must include port.h before all other headers
32 #define _GNU_SOURCE /* for pread/pwrite */
35 #include <sys/types.h>
52 /****************************************************************
56 #if !defined(_MSC_VER) && !defined(__int64)
57 # if defined(__x86_64__) || defined(_WIN64)
60 # define __int64 long long
74 typedef unsigned int size_t;
79 #ifndef HAVE_FSBLKCNT_T
80 typedef unsigned long fsblkcnt_t;
82 #ifndef HAVE_FSFILCNT_T
83 typedef unsigned long fsfilcnt_t;
86 #ifndef HAVE_STRUCT_STATVFS_F_BLOCKS
89 unsigned long f_bsize;
90 unsigned long f_frsize;
99 unsigned long f_namemax;
101 #endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */
104 /****************************************************************
111 #define RTLD_LAZY 0x001
112 #define RTLD_NOW 0x002
113 #define RTLD_GLOBAL 0x100
116 #ifdef HAVE_ONE_ARG_MKDIR
117 #define mkdir(path,mode) mkdir(path)
120 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
121 #define ftruncate chsize
124 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
128 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
129 #define pclose _pclose
132 #if !defined(HAVE_STRDUP) && defined(HAVE__STRDUP)
133 #define strdup _strdup
136 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
137 #define snprintf _snprintf
140 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
141 #define vsnprintf _vsnprintf
144 #if !defined(HAVE_STRTOLL) && defined(HAVE__STRTOI64)
145 #define strtoll _strtoi64
148 #if !defined(HAVE_STRTOULL) && defined(HAVE__STRTOUI64)
149 #define strtoull _strtoui64
153 # define S_ISLNK(mod) (0)
157 # define S_ISSOCK(mod) (0)
161 # define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)
165 # define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)
169 # define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)
173 # define S_ISREG(mod) (((mod) & _S_IFMT) == _S_IFREG)
176 /* So we open files in 64 bit access mode on Linux */
178 # define O_LARGEFILE 0
182 # define O_NONBLOCK 0
190 /****************************************************************
195 #define M_PI 3.14159265358979323846
199 #define M_PI_2 1.570796326794896619
203 static inline float __port_infinity(void)
205 static const unsigned __inf_bytes = 0x7f800000;
206 return *(const float *)&__inf_bytes;
208 #define INFINITY __port_infinity()
212 static inline float __port_nan(void)
214 static const unsigned __nan_bytes = 0x7fc00000;
215 return *(const float *)&__nan_bytes;
217 #define NAN __port_nan()
221 /****************************************************************
222 * Function definitions (only when using libwine_port)
225 #ifndef NO_LIBWINE_PORT
227 #ifndef HAVE_FSTATVFS
228 int fstatvfs( int fd, struct statvfs *buf );
231 #ifndef HAVE_GETOPT_LONG
238 #ifndef HAVE_STRUCT_OPTION_NAME
248 extern int getopt_long (int ___argc, char *const *___argv,
249 const char *__shortopts,
250 const struct option *__longopts, int *__longind);
251 extern int getopt_long_only (int ___argc, char *const *___argv,
252 const char *__shortopts,
253 const struct option *__longopts, int *__longind);
254 #endif /* HAVE_GETOPT_LONG */
260 #ifndef HAVE_GETPAGESIZE
261 size_t getpagesize(void);
262 #endif /* HAVE_GETPAGESIZE */
273 int lstat(const char *file_name, struct stat *buf);
274 #endif /* HAVE_LSTAT */
277 void *memmove(void *dest, const void *src, size_t len);
278 #endif /* !defined(HAVE_MEMMOVE) */
292 #define POLLNVAL 0x20
293 int poll( struct pollfd *fds, unsigned int count, int timeout );
294 #endif /* HAVE_POLL */
297 ssize_t pread( int fd, void *buf, size_t count, off_t offset );
298 #endif /* HAVE_PREAD */
301 ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
302 #endif /* HAVE_PWRITE */
304 #ifndef HAVE_READLINK
305 int readlink( const char *path, char *buf, size_t size );
306 #endif /* HAVE_READLINK */
309 int statvfs( const char *path, struct statvfs *buf );
312 #ifndef HAVE_STRNCASECMP
313 # ifndef HAVE__STRNICMP
314 int strncasecmp(const char *str1, const char *str2, size_t n);
316 # define strncasecmp _strnicmp
318 #endif /* !defined(HAVE_STRNCASECMP) */
320 #ifndef HAVE_STRERROR
321 const char *strerror(int err);
322 #endif /* !defined(HAVE_STRERROR) */
324 #ifndef HAVE_STRCASECMP
325 # ifndef HAVE__STRICMP
326 int strcasecmp(const char *str1, const char *str2);
328 # define strcasecmp _stricmp
330 #endif /* !defined(HAVE_STRCASECMP) */
333 int symlink(const char *from, const char *to);
337 int usleep (unsigned int useconds);
338 #endif /* !defined(HAVE_USLEEP) */
341 static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
343 return memcpy( dst, src, size );
346 extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
347 #endif /* __i386__ */
349 extern int mkstemps(char *template, int suffix_len);
351 /* Process creation flags */
355 # define _P_OVERLAY 2
356 # define _P_NOWAITO 3
360 extern int spawnvp(int mode, const char *cmdname, const char * const argv[]);
363 /* Interlocked functions */
365 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
367 extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
369 static inline int interlocked_cmpxchg( int *dest, int xchg, int compare )
372 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
373 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
377 static inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
381 __asm__ __volatile__( "lock; cmpxchgq %2,(%1)"
382 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
384 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
385 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
390 static inline int interlocked_xchg( int *dest, int val )
393 __asm__ __volatile__( "lock; xchgl %0,(%1)"
394 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
398 static inline void *interlocked_xchg_ptr( void **dest, void *val )
402 __asm__ __volatile__( "lock; xchgq %0,(%1)"
403 : "=r" (ret) :"r" (dest), "0" (val) : "memory" );
405 __asm__ __volatile__( "lock; xchgl %0,(%1)"
406 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
411 static inline int interlocked_xchg_add( int *dest, int incr )
414 __asm__ __volatile__( "lock; xaddl %0,(%1)"
415 : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
420 static inline unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
421 __int64 xchg_low, __int64 *compare )
424 __asm__ __volatile__( "lock cmpxchg16b %0; setz %b2"
425 : "=m" (dest[0]), "=m" (dest[1]), "=r" (ret),
426 "=a" (compare[0]), "=d" (compare[1])
427 : "m" (dest[0]), "m" (dest[1]), "3" (compare[0]), "4" (compare[1]),
428 "c" (xchg_high), "b" (xchg_low) );
435 extern int interlocked_cmpxchg( int *dest, int xchg, int compare );
436 extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
437 extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
438 extern int interlocked_xchg( int *dest, int val );
439 extern void *interlocked_xchg_ptr( void **dest, void *val );
440 extern int interlocked_xchg_add( int *dest, int incr );
442 extern unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
443 __int64 xchg_low, __int64 *compare );
446 #endif /* __GNUC__ */
448 #else /* NO_LIBWINE_PORT */
450 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
452 #define ffs __WINE_NOT_PORTABLE(ffs)
453 #define fstatvfs __WINE_NOT_PORTABLE(fstatvfs)
454 #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
455 #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
456 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
457 #define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
458 #define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
459 #define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
460 #define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
461 #define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
462 #define lstat __WINE_NOT_PORTABLE(lstat)
463 #define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
465 #define memmove __WINE_NOT_PORTABLE(memmove)
466 #define pread __WINE_NOT_PORTABLE(pread)
467 #define pwrite __WINE_NOT_PORTABLE(pwrite)
468 #define spawnvp __WINE_NOT_PORTABLE(spawnvp)
469 #define statvfs __WINE_NOT_PORTABLE(statvfs)
470 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
471 #define strerror __WINE_NOT_PORTABLE(strerror)
472 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
473 #define usleep __WINE_NOT_PORTABLE(usleep)
475 #endif /* NO_LIBWINE_PORT */
477 #endif /* !defined(__WINE_WINE_PORT_H) */