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 _FILE_OFFSET_BITS 64
33 #define _GNU_SOURCE /* for pread/pwrite */
36 #include <sys/types.h>
53 /****************************************************************
57 #if !defined(_MSC_VER) && !defined(__int64)
58 # if defined(__x86_64__) || 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 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
118 #define ftruncate chsize
121 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
125 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
126 #define pclose _pclose
129 #if !defined(HAVE_STRDUP) && defined(HAVE__STRDUP)
130 #define strdup _strdup
133 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
134 #define snprintf _snprintf
137 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
138 #define vsnprintf _vsnprintf
141 #if !defined(HAVE_STRTOLL) && defined(HAVE__STRTOI64)
142 #define strtoll _strtoi64
145 #if !defined(HAVE_STRTOULL) && defined(HAVE__STRTOUI64)
146 #define strtoull _strtoui64
150 # define S_ISLNK(mod) (0)
154 # define S_ISSOCK(mod) (0)
158 # define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)
162 # define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)
166 # define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)
170 # 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
190 #if !defined(S_IXUSR) && defined(S_IEXEC)
191 # define S_IXUSR S_IEXEC
193 #if !defined(S_IXGRP) && defined(S_IEXEC)
194 # define S_IXGRP S_IEXEC
196 #if !defined(S_IXOTH) && defined(S_IEXEC)
197 # define S_IXOTH S_IEXEC
201 /****************************************************************
206 #define M_PI 3.14159265358979323846
210 #define M_PI_2 1.570796326794896619
214 /* Macros to define assembler functions somewhat portably */
216 #if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__APPLE__)
217 # define __ASM_GLOBAL_FUNC(name,code) \
218 __asm__( ".text\n\t" \
220 ".globl " __ASM_NAME(#name) "\n\t" \
221 __ASM_FUNC(#name) "\n" \
222 __ASM_NAME(#name) ":\n\t" \
225 #else /* defined(__GNUC__) && !defined(__MINGW32__) && !defined(__APPLE__) */
226 # define __ASM_GLOBAL_FUNC(name,code) \
227 void __asm_dummy_##name(void) { \
228 asm( ".align 4\n\t" \
229 ".globl " __ASM_NAME(#name) "\n\t" \
230 __ASM_FUNC(#name) "\n" \
231 __ASM_NAME(#name) ":\n\t" \
234 #endif /* __GNUC__ */
237 /* Register functions */
240 #define DEFINE_REGS_ENTRYPOINT( name, args, pop_args ) \
241 __ASM_GLOBAL_FUNC( name, \
243 "call " __ASM_NAME("__wine_call_from_32_regs") "\n\t" \
244 ".long " __ASM_NAME("__regs_") #name "-.\n\t" \
245 ".byte " #args "," #pop_args )
246 /* FIXME: add support for other CPUs */
247 #endif /* __i386__ */
250 /****************************************************************
251 * Function definitions (only when using libwine_port)
254 #ifndef NO_LIBWINE_PORT
256 #ifndef HAVE_FSTATVFS
257 int fstatvfs( int fd, struct statvfs *buf );
260 #ifndef HAVE_GETOPT_LONG
267 #ifndef HAVE_STRUCT_OPTION_NAME
277 extern int getopt_long (int ___argc, char *const *___argv,
278 const char *__shortopts,
279 const struct option *__longopts, int *__longind);
280 extern int getopt_long_only (int ___argc, char *const *___argv,
281 const char *__shortopts,
282 const struct option *__longopts, int *__longind);
283 #endif /* HAVE_GETOPT_LONG */
291 int futimes(int fd, const struct timeval *tv);
294 #ifndef HAVE_GETPAGESIZE
295 size_t getpagesize(void);
296 #endif /* HAVE_GETPAGESIZE */
300 #endif /* HAVE_GETTID */
311 int lstat(const char *file_name, struct stat *buf);
312 #endif /* HAVE_LSTAT */
315 void *memmove(void *dest, const void *src, size_t len);
316 #endif /* !defined(HAVE_MEMMOVE) */
319 ssize_t pread( int fd, void *buf, size_t count, off_t offset );
320 #endif /* HAVE_PREAD */
323 ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
324 #endif /* HAVE_PWRITE */
326 #ifndef HAVE_READLINK
327 int readlink( const char *path, char *buf, size_t size );
328 #endif /* HAVE_READLINK */
331 int statvfs( const char *path, struct statvfs *buf );
334 #ifndef HAVE_STRNCASECMP
335 # ifndef HAVE__STRNICMP
336 int strncasecmp(const char *str1, const char *str2, size_t n);
338 # define strncasecmp _strnicmp
340 #endif /* !defined(HAVE_STRNCASECMP) */
342 #ifndef HAVE_STRERROR
343 const char *strerror(int err);
344 #endif /* !defined(HAVE_STRERROR) */
346 #ifndef HAVE_STRCASECMP
347 # ifndef HAVE__STRICMP
348 int strcasecmp(const char *str1, const char *str2);
350 # define strcasecmp _stricmp
352 #endif /* !defined(HAVE_STRCASECMP) */
355 int usleep (unsigned int useconds);
356 #endif /* !defined(HAVE_USLEEP) */
359 static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
361 return memcpy( dst, src, size );
364 extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
365 #endif /* __i386__ */
367 extern int mkstemps(char *template, int suffix_len);
369 /* Process creation flags */
373 # define _P_OVERLAY 2
374 # define _P_NOWAITO 3
378 extern int spawnvp(int mode, const char *cmdname, const char * const argv[]);
381 /* Interlocked functions */
383 #if defined(__i386__) && defined(__GNUC__)
385 extern inline int interlocked_cmpxchg( int *dest, int xchg, int compare );
386 extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
387 extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
388 extern inline int interlocked_xchg( int *dest, int val );
389 extern inline void *interlocked_xchg_ptr( void **dest, void *val );
390 extern inline int interlocked_xchg_add( int *dest, int incr );
392 extern inline int interlocked_cmpxchg( int *dest, int xchg, int compare )
395 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
396 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
400 extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
403 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
404 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
408 extern inline int interlocked_xchg( int *dest, int val )
411 __asm__ __volatile__( "lock; xchgl %0,(%1)"
412 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
416 extern inline void *interlocked_xchg_ptr( void **dest, void *val )
419 __asm__ __volatile__( "lock; xchgl %0,(%1)"
420 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
424 extern inline int interlocked_xchg_add( int *dest, int incr )
427 __asm__ __volatile__( "lock; xaddl %0,(%1)"
428 : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
432 #else /* __i386___ && __GNUC__ */
434 extern int interlocked_cmpxchg( int *dest, int xchg, int compare );
435 extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
436 extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
437 extern int interlocked_xchg( int *dest, int val );
438 extern void *interlocked_xchg_ptr( void **dest, void *val );
439 extern int interlocked_xchg_add( int *dest, int incr );
441 #endif /* __i386___ && __GNUC__ */
443 #else /* NO_LIBWINE_PORT */
445 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
447 #define ffs __WINE_NOT_PORTABLE(ffs)
448 #define fstatvfs __WINE_NOT_PORTABLE(fstatvfs)
449 #define futimes __WINE_NOT_PORTABLE(futimes)
450 #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
451 #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
452 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
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) */