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
33 # define _GNU_SOURCE /* for pread/pwrite, isfinite */
37 #include <sys/types.h>
55 /****************************************************************
59 #if !defined(_MSC_VER) && !defined(__int64)
60 # if defined(__x86_64__) || defined(__aarch64__) || defined(_WIN64)
63 # define __int64 long long
77 typedef unsigned int size_t;
82 #ifndef HAVE_FSBLKCNT_T
83 typedef unsigned long fsblkcnt_t
;
85 #ifndef HAVE_FSFILCNT_T
86 typedef unsigned long fsfilcnt_t
;
89 #ifndef HAVE_STRUCT_STATVFS_F_BLOCKS
92 unsigned long f_bsize
;
93 unsigned long f_frsize
;
100 unsigned long f_fsid
;
101 unsigned long f_flag
;
102 unsigned long f_namemax
;
104 #endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */
107 /****************************************************************
114 #define RTLD_LAZY 0x001
115 #define RTLD_NOW 0x002
116 #define RTLD_GLOBAL 0x100
119 #ifdef HAVE_ONE_ARG_MKDIR
120 #define mkdir(path,mode) mkdir(path)
123 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
124 #define ftruncate chsize
127 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
131 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
132 #define pclose _pclose
135 #if !defined(HAVE_STRDUP) && defined(HAVE__STRDUP)
136 #define strdup _strdup
139 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
140 #define snprintf _snprintf
143 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
144 #define vsnprintf _vsnprintf
147 #if !defined(HAVE_STRTOLL) && defined(HAVE__STRTOI64)
148 #define strtoll _strtoi64
151 #if !defined(HAVE_STRTOULL) && defined(HAVE__STRTOUI64)
152 #define strtoull _strtoui64
156 # define S_ISLNK(mod) (0)
160 # define S_ISSOCK(mod) (0)
164 # define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)
168 # define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)
172 # define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)
176 # define S_ISREG(mod) (((mod) & _S_IFMT) == _S_IFREG)
179 /* So we open files in 64 bit access mode on Linux */
181 # define O_LARGEFILE 0
185 # define O_NONBLOCK 0
193 /****************************************************************
198 #define M_PI 3.14159265358979323846
202 #define M_PI_2 1.570796326794896619
206 static inline float __port_infinity(void)
208 static const unsigned __inf_bytes
= 0x7f800000;
209 return *(const float *)&__inf_bytes
;
211 #define INFINITY __port_infinity()
215 static inline float __port_nan(void)
217 static const unsigned __nan_bytes
= 0x7fc00000;
218 return *(const float *)&__nan_bytes
;
220 #define NAN __port_nan()
224 /****************************************************************
225 * Function definitions (only when using libwine_port)
228 #ifndef NO_LIBWINE_PORT
230 #ifndef HAVE_FSTATVFS
231 int fstatvfs( int fd
, struct statvfs
*buf
);
234 #ifndef HAVE_GETOPT_LONG_ONLY
241 #ifndef HAVE_STRUCT_OPTION_NAME
251 extern int getopt_long (int ___argc
, char *const *___argv
,
252 const char *__shortopts
,
253 const struct option
*__longopts
, int *__longind
);
254 extern int getopt_long_only (int ___argc
, char *const *___argv
,
255 const char *__shortopts
,
256 const struct option
*__longopts
, int *__longind
);
257 #endif /* HAVE_GETOPT_LONG_ONLY */
263 #ifndef HAVE_ISFINITE
264 int isfinite(double x
);
276 __int64
llrint(double x
);
280 __int64
llrintf(float x
);
284 long lrint(double x
);
288 long lrintf(float x
);
292 int lstat(const char *file_name
, struct stat
*buf
);
293 #endif /* HAVE_LSTAT */
296 void *memmove(void *dest
, const void *src
, size_t len
);
297 #endif /* !defined(HAVE_MEMMOVE) */
311 #define POLLNVAL 0x20
312 int poll( struct pollfd
*fds
, unsigned int count
, int timeout
);
313 #endif /* HAVE_POLL */
316 ssize_t
pread( int fd
, void *buf
, size_t count
, off_t offset
);
317 #endif /* HAVE_PREAD */
320 ssize_t
pwrite( int fd
, const void *buf
, size_t count
, off_t offset
);
321 #endif /* HAVE_PWRITE */
323 #ifndef HAVE_READLINK
324 int readlink( const char *path
, char *buf
, size_t size
);
325 #endif /* HAVE_READLINK */
328 double rint(double x
);
332 float rintf(float x
);
336 int statvfs( const char *path
, struct statvfs
*buf
);
339 #ifndef HAVE_STRNCASECMP
340 # ifndef HAVE__STRNICMP
341 int strncasecmp(const char *str1
, const char *str2
, size_t n
);
343 # define strncasecmp _strnicmp
345 #endif /* !defined(HAVE_STRNCASECMP) */
347 #ifndef HAVE_STRERROR
348 const char *strerror(int err
);
349 #endif /* !defined(HAVE_STRERROR) */
351 #ifndef HAVE_STRCASECMP
352 # ifndef HAVE__STRICMP
353 int strcasecmp(const char *str1
, const char *str2
);
355 # define strcasecmp _stricmp
357 #endif /* !defined(HAVE_STRCASECMP) */
360 int symlink(const char *from
, const char *to
);
364 int usleep (unsigned int useconds
);
365 #endif /* !defined(HAVE_USLEEP) */
368 static inline void *memcpy_unaligned( void *dst
, const void *src
, size_t size
)
370 return memcpy( dst
, src
, size
);
373 extern void *memcpy_unaligned( void *dst
, const void *src
, size_t size
);
374 #endif /* __i386__ */
376 extern int mkstemps(char *template, int suffix_len
);
378 /* Process creation flags */
382 # define _P_OVERLAY 2
383 # define _P_NOWAITO 3
386 #ifndef HAVE__SPAWNVP
387 extern int _spawnvp(int mode
, const char *cmdname
, const char * const argv
[]);
390 /* Interlocked functions */
392 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
394 static inline int interlocked_cmpxchg( int *dest
, int xchg
, int compare
)
397 __asm__
__volatile__( "lock; cmpxchgl %2,(%1)"
398 : "=a" (ret
) : "r" (dest
), "r" (xchg
), "0" (compare
) : "memory" );
402 static inline void *interlocked_cmpxchg_ptr( void **dest
, void *xchg
, void *compare
)
406 __asm__
__volatile__( "lock; cmpxchgq %2,(%1)"
407 : "=a" (ret
) : "r" (dest
), "r" (xchg
), "0" (compare
) : "memory" );
409 __asm__
__volatile__( "lock; cmpxchgl %2,(%1)"
410 : "=a" (ret
) : "r" (dest
), "r" (xchg
), "0" (compare
) : "memory" );
415 static inline int interlocked_xchg( int *dest
, int val
)
418 __asm__
__volatile__( "lock; xchgl %0,(%1)"
419 : "=r" (ret
) : "r" (dest
), "0" (val
) : "memory" );
423 static inline void *interlocked_xchg_ptr( void **dest
, void *val
)
427 __asm__
__volatile__( "lock; xchgq %0,(%1)"
428 : "=r" (ret
) :"r" (dest
), "0" (val
) : "memory" );
430 __asm__
__volatile__( "lock; xchgl %0,(%1)"
431 : "=r" (ret
) : "r" (dest
), "0" (val
) : "memory" );
436 static inline int interlocked_xchg_add( int *dest
, int incr
)
439 __asm__
__volatile__( "lock; xaddl %0,(%1)"
440 : "=r" (ret
) : "r" (dest
), "0" (incr
) : "memory" );
445 static inline unsigned char interlocked_cmpxchg128( __int64
*dest
, __int64 xchg_high
,
446 __int64 xchg_low
, __int64
*compare
)
449 __asm__
__volatile__( "lock cmpxchg16b %0; setz %b2"
450 : "=m" (dest
[0]), "=m" (dest
[1]), "=r" (ret
),
451 "=a" (compare
[0]), "=d" (compare
[1])
452 : "m" (dest
[0]), "m" (dest
[1]), "3" (compare
[0]), "4" (compare
[1]),
453 "c" (xchg_high
), "b" (xchg_low
) );
460 #ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
461 static inline int interlocked_cmpxchg( int *dest
, int xchg
, int compare
)
463 return __sync_val_compare_and_swap( dest
, compare
, xchg
);
466 static inline int interlocked_xchg_add( int *dest
, int incr
)
468 return __sync_fetch_and_add( dest
, incr
);
471 static inline int interlocked_xchg( int *dest
, int val
)
474 do ret
= *dest
; while (!__sync_bool_compare_and_swap( dest
, ret
, val
));
478 extern int interlocked_cmpxchg( int *dest
, int xchg
, int compare
);
479 extern int interlocked_xchg_add( int *dest
, int incr
);
480 extern int interlocked_xchg( int *dest
, int val
);
483 #if (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) && __SIZEOF_POINTER__ == 4) \
484 || (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8) && __SIZEOF_POINTER__ == 8)
485 static inline void *interlocked_cmpxchg_ptr( void **dest
, void *xchg
, void *compare
)
487 return __sync_val_compare_and_swap( dest
, compare
, xchg
);
490 static inline void *interlocked_xchg_ptr( void **dest
, void *val
)
493 do ret
= *dest
; while (!__sync_bool_compare_and_swap( dest
, ret
, val
));
497 extern void *interlocked_cmpxchg_ptr( void **dest
, void *xchg
, void *compare
);
498 extern void *interlocked_xchg_ptr( void **dest
, void *val
);
501 #if defined(__x86_64__) || defined(__aarch64__) || defined(_WIN64)
502 extern unsigned char interlocked_cmpxchg128( __int64
*dest
, __int64 xchg_high
,
503 __int64 xchg_low
, __int64
*compare
);
506 #endif /* __GNUC__ */
508 #ifdef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
509 static inline __int64
interlocked_cmpxchg64( __int64
*dest
, __int64 xchg
, __int64 compare
)
511 return __sync_val_compare_and_swap( dest
, compare
, xchg
);
514 extern __int64
interlocked_cmpxchg64( __int64
*dest
, __int64 xchg
, __int64 compare
);
517 #else /* NO_LIBWINE_PORT */
519 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
521 #define ffs __WINE_NOT_PORTABLE(ffs)
522 #define fstatvfs __WINE_NOT_PORTABLE(fstatvfs)
523 #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
524 #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
525 #define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
526 #define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
527 #define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
528 #define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
529 #define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
530 #define lstat __WINE_NOT_PORTABLE(lstat)
531 #define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
533 #define memmove __WINE_NOT_PORTABLE(memmove)
534 #define pread __WINE_NOT_PORTABLE(pread)
535 #define pwrite __WINE_NOT_PORTABLE(pwrite)
536 #define spawnvp __WINE_NOT_PORTABLE(spawnvp)
537 #define statvfs __WINE_NOT_PORTABLE(statvfs)
538 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
539 #define strerror __WINE_NOT_PORTABLE(strerror)
540 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
541 #define usleep __WINE_NOT_PORTABLE(usleep)
543 #endif /* NO_LIBWINE_PORT */
545 #endif /* !defined(__WINE_WINE_PORT_H) */