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>
53 /****************************************************************
57 #if !defined(_MSC_VER) && !defined(__int64)
58 # if defined(__x86_64__) || defined(__aarch64__) || defined(_WIN64)
61 # define __int64 long long
75 typedef unsigned int size_t;
80 #ifndef HAVE_FSBLKCNT_T
81 typedef unsigned long fsblkcnt_t;
83 #ifndef HAVE_FSFILCNT_T
84 typedef unsigned long fsfilcnt_t;
87 #ifndef HAVE_STRUCT_STATVFS_F_BLOCKS
90 unsigned long f_bsize;
91 unsigned long f_frsize;
100 unsigned long f_namemax;
102 #endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */
105 /****************************************************************
112 #define RTLD_LAZY 0x001
113 #define RTLD_NOW 0x002
114 #define RTLD_GLOBAL 0x100
117 #ifdef HAVE_ONE_ARG_MKDIR
118 #define mkdir(path,mode) mkdir(path)
121 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
122 #define ftruncate chsize
125 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
129 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
130 #define pclose _pclose
133 #if !defined(HAVE_STRDUP) && defined(HAVE__STRDUP)
134 #define strdup _strdup
137 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
138 #define snprintf _snprintf
141 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
142 #define vsnprintf _vsnprintf
145 #if !defined(HAVE_STRTOLL) && defined(HAVE__STRTOI64)
146 #define strtoll _strtoi64
149 #if !defined(HAVE_STRTOULL) && defined(HAVE__STRTOUI64)
150 #define strtoull _strtoui64
154 # define S_ISLNK(mod) (0)
158 # define S_ISSOCK(mod) (0)
162 # define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)
166 # define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)
170 # define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)
174 # define S_ISREG(mod) (((mod) & _S_IFMT) == _S_IFREG)
177 /* So we open files in 64 bit access mode on Linux */
179 # define O_LARGEFILE 0
183 # define O_NONBLOCK 0
191 /****************************************************************
196 #define M_PI 3.14159265358979323846
200 #define M_PI_2 1.570796326794896619
204 static inline float __port_infinity(void)
206 static const unsigned __inf_bytes = 0x7f800000;
207 return *(const float *)&__inf_bytes;
209 #define INFINITY __port_infinity()
213 static inline float __port_nan(void)
215 static const unsigned __nan_bytes = 0x7fc00000;
216 return *(const float *)&__nan_bytes;
218 #define NAN __port_nan()
222 /****************************************************************
223 * Function definitions (only when using libwine_port)
226 #ifndef NO_LIBWINE_PORT
228 #ifndef HAVE_FSTATVFS
229 int fstatvfs( int fd, struct statvfs *buf );
232 #ifndef HAVE_GETOPT_LONG
239 #ifndef HAVE_STRUCT_OPTION_NAME
249 extern int getopt_long (int ___argc, char *const *___argv,
250 const char *__shortopts,
251 const struct option *__longopts, int *__longind);
252 extern int getopt_long_only (int ___argc, char *const *___argv,
253 const char *__shortopts,
254 const struct option *__longopts, int *__longind);
255 #endif /* HAVE_GETOPT_LONG */
270 int lstat(const char *file_name, struct stat *buf);
271 #endif /* HAVE_LSTAT */
274 void *memmove(void *dest, const void *src, size_t len);
275 #endif /* !defined(HAVE_MEMMOVE) */
289 #define POLLNVAL 0x20
290 int poll( struct pollfd *fds, unsigned int count, int timeout );
291 #endif /* HAVE_POLL */
294 ssize_t pread( int fd, void *buf, size_t count, off_t offset );
295 #endif /* HAVE_PREAD */
298 ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
299 #endif /* HAVE_PWRITE */
301 #ifndef HAVE_READLINK
302 int readlink( const char *path, char *buf, size_t size );
303 #endif /* HAVE_READLINK */
306 int statvfs( const char *path, struct statvfs *buf );
309 #ifndef HAVE_STRNCASECMP
310 # ifndef HAVE__STRNICMP
311 int strncasecmp(const char *str1, const char *str2, size_t n);
313 # define strncasecmp _strnicmp
315 #endif /* !defined(HAVE_STRNCASECMP) */
317 #ifndef HAVE_STRERROR
318 const char *strerror(int err);
319 #endif /* !defined(HAVE_STRERROR) */
321 #ifndef HAVE_STRCASECMP
322 # ifndef HAVE__STRICMP
323 int strcasecmp(const char *str1, const char *str2);
325 # define strcasecmp _stricmp
327 #endif /* !defined(HAVE_STRCASECMP) */
330 int symlink(const char *from, const char *to);
334 int usleep (unsigned int useconds);
335 #endif /* !defined(HAVE_USLEEP) */
338 static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
340 return memcpy( dst, src, size );
343 extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
344 #endif /* __i386__ */
346 extern int mkstemps(char *template, int suffix_len);
348 /* Process creation flags */
352 # define _P_OVERLAY 2
353 # define _P_NOWAITO 3
356 #ifndef HAVE__SPAWNVP
357 extern int _spawnvp(int mode, const char *cmdname, const char * const argv[]);
360 /* Interlocked functions */
362 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
364 extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
366 static inline int interlocked_cmpxchg( int *dest, int xchg, int compare )
369 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
370 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
374 static inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
378 __asm__ __volatile__( "lock; cmpxchgq %2,(%1)"
379 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
381 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
382 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
387 static inline int interlocked_xchg( int *dest, int val )
390 __asm__ __volatile__( "lock; xchgl %0,(%1)"
391 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
395 static inline void *interlocked_xchg_ptr( void **dest, void *val )
399 __asm__ __volatile__( "lock; xchgq %0,(%1)"
400 : "=r" (ret) :"r" (dest), "0" (val) : "memory" );
402 __asm__ __volatile__( "lock; xchgl %0,(%1)"
403 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
408 static inline int interlocked_xchg_add( int *dest, int incr )
411 __asm__ __volatile__( "lock; xaddl %0,(%1)"
412 : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
417 static inline unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
418 __int64 xchg_low, __int64 *compare )
421 __asm__ __volatile__( "lock cmpxchg16b %0; setz %b2"
422 : "=m" (dest[0]), "=m" (dest[1]), "=r" (ret),
423 "=a" (compare[0]), "=d" (compare[1])
424 : "m" (dest[0]), "m" (dest[1]), "3" (compare[0]), "4" (compare[1]),
425 "c" (xchg_high), "b" (xchg_low) );
432 extern int interlocked_cmpxchg( int *dest, int xchg, int compare );
433 extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
434 extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
435 extern int interlocked_xchg( int *dest, int val );
436 extern void *interlocked_xchg_ptr( void **dest, void *val );
437 extern int interlocked_xchg_add( int *dest, int incr );
438 #if defined(__x86_64__) || defined(__aarch64__) || defined(_WIN64)
439 extern unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
440 __int64 xchg_low, __int64 *compare );
443 #endif /* __GNUC__ */
445 #else /* NO_LIBWINE_PORT */
447 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
449 #define ffs __WINE_NOT_PORTABLE(ffs)
450 #define fstatvfs __WINE_NOT_PORTABLE(fstatvfs)
451 #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
452 #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
453 #define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
454 #define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
455 #define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
456 #define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
457 #define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
458 #define lstat __WINE_NOT_PORTABLE(lstat)
459 #define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
461 #define memmove __WINE_NOT_PORTABLE(memmove)
462 #define pread __WINE_NOT_PORTABLE(pread)
463 #define pwrite __WINE_NOT_PORTABLE(pwrite)
464 #define spawnvp __WINE_NOT_PORTABLE(spawnvp)
465 #define statvfs __WINE_NOT_PORTABLE(statvfs)
466 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
467 #define strerror __WINE_NOT_PORTABLE(strerror)
468 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
469 #define usleep __WINE_NOT_PORTABLE(usleep)
471 #endif /* NO_LIBWINE_PORT */
473 #endif /* !defined(__WINE_WINE_PORT_H) */