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 #define _FILE_OFFSET_BITS 64
29 #define _GNU_SOURCE /* for pread/pwrite */
32 #include <sys/types.h>
49 /****************************************************************
63 typedef unsigned int size_t;
68 #ifndef HAVE_FSBLKCNT_T
69 typedef unsigned long fsblkcnt_t;
71 #ifndef HAVE_FSFILCNT_T
72 typedef unsigned long fsfilcnt_t;
75 #ifndef HAVE_STRUCT_STATVFS_F_BLOCKS
78 unsigned long f_bsize;
79 unsigned long f_frsize;
88 unsigned long f_namemax;
90 #endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */
93 /****************************************************************
100 #define RTLD_LAZY 0x001
101 #define RTLD_NOW 0x002
102 #define RTLD_GLOBAL 0x100
105 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
106 #define ftruncate chsize
109 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
113 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
114 #define pclose _pclose
117 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
118 #define snprintf _snprintf
121 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
122 #define vsnprintf _vsnprintf
126 # define S_ISLNK(mod) (0)
130 # define S_ISSOCK(mod) (0)
134 # define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)
138 # define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)
142 # define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)
146 # define S_ISREG(mod) (((mod) & _S_IFMT) == _S_IFREG)
153 /* So we open files in 64 bit access mode on Linux */
155 # define O_LARGEFILE 0
159 # define O_NONBLOCK 0
166 #if !defined(S_IXUSR) && defined(S_IEXEC)
167 # define S_IXUSR S_IEXEC
169 #if !defined(S_IXGRP) && defined(S_IEXEC)
170 # define S_IXGRP S_IEXEC
172 #if !defined(S_IXOTH) && defined(S_IEXEC)
173 # define S_IXOTH S_IEXEC
177 /****************************************************************
182 #define M_PI 3.14159265358979323846
186 #define M_PI_2 1.570796326794896619
190 /* Macros to define assembler functions somewhat portably */
192 #if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__APPLE__)
193 # define __ASM_GLOBAL_FUNC(name,code) \
194 __asm__( ".text\n\t" \
196 ".globl " __ASM_NAME(#name) "\n\t" \
197 __ASM_FUNC(#name) "\n" \
198 __ASM_NAME(#name) ":\n\t" \
201 #else /* defined(__GNUC__) && !defined(__MINGW32__) && !defined(__APPLE__) */
202 # define __ASM_GLOBAL_FUNC(name,code) \
203 void __asm_dummy_##name(void) { \
204 asm( ".align 4\n\t" \
205 ".globl " __ASM_NAME(#name) "\n\t" \
206 __ASM_FUNC(#name) "\n" \
207 __ASM_NAME(#name) ":\n\t" \
210 #endif /* __GNUC__ */
213 /* Register functions */
216 #define DEFINE_REGS_ENTRYPOINT( name, args, pop_args ) \
217 __ASM_GLOBAL_FUNC( name, \
219 "call " __ASM_NAME("__wine_call_from_32_regs") "\n\t" \
220 ".long " __ASM_NAME("__regs_") #name "-.\n\t" \
221 ".byte " #args "," #pop_args )
222 /* FIXME: add support for other CPUs */
223 #endif /* __i386__ */
226 /****************************************************************
227 * Function definitions (only when using libwine_port)
230 #ifndef NO_LIBWINE_PORT
232 #ifndef HAVE_FSTATVFS
233 int fstatvfs( int fd, struct statvfs *buf );
236 #ifndef HAVE_GETOPT_LONG
243 #ifndef HAVE_STRUCT_OPTION_NAME
253 extern int getopt_long (int ___argc, char *const *___argv,
254 const char *__shortopts,
255 const struct option *__longopts, int *__longind);
256 extern int getopt_long_only (int ___argc, char *const *___argv,
257 const char *__shortopts,
258 const struct option *__longopts, int *__longind);
259 #endif /* HAVE_GETOPT_LONG */
267 int futimes(int fd, const struct timeval tv[2]);
270 #ifndef HAVE_GETPAGESIZE
271 size_t getpagesize(void);
272 #endif /* HAVE_GETPAGESIZE */
276 #endif /* HAVE_GETTID */
279 int lstat(const char *file_name, struct stat *buf);
280 #endif /* HAVE_LSTAT */
283 void *memmove(void *dest, const void *src, size_t len);
284 #endif /* !defined(HAVE_MEMMOVE) */
287 ssize_t pread( int fd, void *buf, size_t count, off_t offset );
288 #endif /* HAVE_PREAD */
291 ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
292 #endif /* HAVE_PWRITE */
294 #ifndef HAVE_READLINK
295 int readlink( const char *path, char *buf, size_t size );
296 #endif /* HAVE_READLINK */
298 #ifndef HAVE_SIGSETJMP
300 typedef jmp_buf sigjmp_buf;
301 int sigsetjmp( sigjmp_buf buf, int savesigs );
302 void siglongjmp( sigjmp_buf buf, int val );
303 #endif /* HAVE_SIGSETJMP */
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 usleep (unsigned int useconds);
331 #endif /* !defined(HAVE_USLEEP) */
334 static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
336 return memcpy( dst, src, size );
339 extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
340 #endif /* __i386__ */
342 extern int mkstemps(char *template, int suffix_len);
344 /* Process creation flags */
348 # define _P_OVERLAY 2
349 # define _P_NOWAITO 3
353 extern int spawnvp(int mode, const char *cmdname, const char * const argv[]);
356 /* Interlocked functions */
358 #if defined(__i386__) && defined(__GNUC__)
360 extern inline int interlocked_cmpxchg( int *dest, int xchg, int compare );
361 extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
362 extern inline int interlocked_xchg( int *dest, int val );
363 extern inline void *interlocked_xchg_ptr( void **dest, void *val );
364 extern inline int interlocked_xchg_add( int *dest, int incr );
366 extern 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 extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
377 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
378 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
382 extern inline int interlocked_xchg( int *dest, int val )
385 __asm__ __volatile__( "lock; xchgl %0,(%1)"
386 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
390 extern inline void *interlocked_xchg_ptr( void **dest, void *val )
393 __asm__ __volatile__( "lock; xchgl %0,(%1)"
394 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
398 extern inline int interlocked_xchg_add( int *dest, int incr )
401 __asm__ __volatile__( "lock; xaddl %0,(%1)"
402 : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
406 #else /* __i386___ && __GNUC__ */
408 extern int interlocked_cmpxchg( int *dest, int xchg, int compare );
409 extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
410 extern int interlocked_xchg( int *dest, int val );
411 extern void *interlocked_xchg_ptr( void **dest, void *val );
412 extern int interlocked_xchg_add( int *dest, int incr );
414 #endif /* __i386___ && __GNUC__ */
416 #else /* NO_LIBWINE_PORT */
418 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
420 #define ffs __WINE_NOT_PORTABLE(ffs)
421 #define fstatvfs __WINE_NOT_PORTABLE(fstatvfs)
422 #define futimes __WINE_NOT_PORTABLE(futimes)
423 #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
424 #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
425 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
426 #define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
427 #define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
428 #define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
429 #define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
430 #define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
431 #define lstat __WINE_NOT_PORTABLE(lstat)
432 #define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
434 #define memmove __WINE_NOT_PORTABLE(memmove)
435 #define pread __WINE_NOT_PORTABLE(pread)
436 #define pwrite __WINE_NOT_PORTABLE(pwrite)
437 #define spawnvp __WINE_NOT_PORTABLE(spawnvp)
438 #define statvfs __WINE_NOT_PORTABLE(statvfs)
439 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
440 #define strerror __WINE_NOT_PORTABLE(strerror)
441 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
442 #define usleep __WINE_NOT_PORTABLE(usleep)
444 #endif /* NO_LIBWINE_PORT */
446 #endif /* !defined(__WINE_WINE_PORT_H) */