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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 _GNU_SOURCE /* for pread/pwrite */
31 #include <sys/types.h>
48 /****************************************************************
62 typedef unsigned int size_t;
67 #ifndef HAVE_FSBLKCNT_T
68 typedef unsigned long fsblkcnt_t
;
70 #ifndef HAVE_FSFILCNT_T
71 typedef unsigned long fsfilcnt_t
;
74 #ifndef HAVE_STRUCT_STATVFS_F_BLOCKS
77 unsigned long f_bsize
;
78 unsigned long f_frsize
;
87 unsigned long f_namemax
;
89 #endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */
92 /****************************************************************
99 #define RTLD_LAZY 0x001
100 #define RTLD_NOW 0x002
101 #define RTLD_GLOBAL 0x100
104 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
105 #define ftruncate chsize
108 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
112 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
113 #define pclose _pclose
116 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
117 #define snprintf _snprintf
120 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
121 #define vsnprintf _vsnprintf
125 # define S_ISLNK(mod) (0)
129 # define S_ISSOCK(mod) (0)
133 # define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)
137 # define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)
141 # define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)
145 # define S_ISREG(mod) (((mod) & _S_IFMT) == _S_IFREG)
152 /* So we open files in 64 bit access mode on Linux */
154 # define O_LARGEFILE 0
158 # define O_NONBLOCK 0
165 #if !defined(S_IXUSR) && defined(S_IEXEC)
166 # define S_IXUSR S_IEXEC
168 #if !defined(S_IXGRP) && defined(S_IEXEC)
169 # define S_IXGRP S_IEXEC
171 #if !defined(S_IXOTH) && defined(S_IEXEC)
172 # define S_IXOTH S_IEXEC
175 /****************************************************************
180 #define M_PI 3.14159265358979323846
184 #define M_PI_2 1.570796326794896619
188 /* Macros to define assembler functions somewhat portably */
191 # define __ASM_GLOBAL_FUNC(name,code) \
192 __asm__( ".align 4\n\t" \
193 ".globl " __ASM_NAME(#name) "\n\t" \
194 __ASM_FUNC(#name) "\n" \
195 __ASM_NAME(#name) ":\n\t" \
198 # define __ASM_GLOBAL_FUNC(name,code) \
199 void __asm_dummy_##name(void) { \
200 asm( ".align 4\n\t" \
201 ".globl " __ASM_NAME(#name) "\n\t" \
202 __ASM_FUNC(#name) "\n" \
203 __ASM_NAME(#name) ":\n\t" \
206 #endif /* __GNUC__ */
209 /* Constructor functions */
212 # define DECL_GLOBAL_CONSTRUCTOR(func) \
213 static void func(void) __attribute__((constructor)); \
214 static void func(void)
215 #elif defined(__i386__)
216 # define DECL_GLOBAL_CONSTRUCTOR(func) \
217 static void __dummy_init_##func(void) { \
218 asm(".section .init,\"ax\"\n\t" \
219 "call " #func "\n\t" \
221 static void func(void)
222 #elif defined(__sparc__)
223 # define DECL_GLOBAL_CONSTRUCTOR(func) \
224 static void __dummy_init_##func(void) { \
225 asm("\t.section \".init\",#alloc,#execinstr\n" \
226 "\tcall " #func "\n" \
228 "\t.section \".text\",#alloc,#execinstr\n" ); } \
229 static void func(void)
231 # error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
235 /* Register functions */
238 #define DEFINE_REGS_ENTRYPOINT( name, fn, args, pop_args ) \
239 __ASM_GLOBAL_FUNC( name, \
240 "call " __ASM_NAME("__wine_call_from_32_regs") "\n\t" \
241 ".long " __ASM_NAME(#fn) "\n\t" \
242 ".byte " #args "," #pop_args )
243 /* FIXME: add support for other CPUs */
244 #endif /* __i386__ */
247 /****************************************************************
248 * Function definitions (only when using libwine_port)
251 #ifndef NO_LIBWINE_PORT
253 #ifndef HAVE_FSTATVFS
254 int fstatvfs( int fd
, struct statvfs
*buf
);
257 #ifndef HAVE_GETOPT_LONG
264 #ifndef HAVE_STRUCT_OPTION_NAME
274 extern int getopt_long (int ___argc
, char *const *___argv
,
275 const char *__shortopts
,
276 const struct option
*__longopts
, int *__longind
);
277 extern int getopt_long_only (int ___argc
, char *const *___argv
,
278 const char *__shortopts
,
279 const struct option
*__longopts
, int *__longind
);
280 #endif /* HAVE_GETOPT_LONG */
282 #ifndef HAVE_GETPAGESIZE
283 size_t getpagesize(void);
284 #endif /* HAVE_GETPAGESIZE */
288 #endif /* HAVE_GETTID */
291 int lstat(const char *file_name
, struct stat
*buf
);
292 #endif /* HAVE_LSTAT */
295 void *memmove(void *dest
, const void *src
, size_t len
);
296 #endif /* !defined(HAVE_MEMMOVE) */
299 ssize_t
pread( int fd
, void *buf
, size_t count
, off_t offset
);
300 #endif /* HAVE_PREAD */
303 ssize_t
pwrite( int fd
, const void *buf
, size_t count
, off_t offset
);
304 #endif /* HAVE_PWRITE */
306 #ifndef HAVE_READLINK
307 int readlink( const char *path
, char *buf
, size_t size
);
308 #endif /* HAVE_READLINK */
310 #ifndef HAVE_SIGSETJMP
312 typedef jmp_buf sigjmp_buf
;
313 int sigsetjmp( sigjmp_buf buf
, int savesigs
);
314 void siglongjmp( sigjmp_buf buf
, int val
);
315 #endif /* HAVE_SIGSETJMP */
318 int statvfs( const char *path
, struct statvfs
*buf
);
321 #ifndef HAVE_STRNCASECMP
322 # ifndef HAVE__STRNICMP
323 int strncasecmp(const char *str1
, const char *str2
, size_t n
);
325 # define strncasecmp _strnicmp
327 #endif /* !defined(HAVE_STRNCASECMP) */
329 #ifndef HAVE_STRERROR
330 const char *strerror(int err
);
331 #endif /* !defined(HAVE_STRERROR) */
333 #ifndef HAVE_STRCASECMP
334 # ifndef HAVE__STRICMP
335 int strcasecmp(const char *str1
, const char *str2
);
337 # define strcasecmp _stricmp
339 #endif /* !defined(HAVE_STRCASECMP) */
342 int usleep (unsigned int useconds
);
343 #endif /* !defined(HAVE_USLEEP) */
346 static inline void *memcpy_unaligned( void *dst
, const void *src
, size_t size
)
348 return memcpy( dst
, src
, size
);
351 extern void *memcpy_unaligned( void *dst
, const void *src
, size_t size
);
352 #endif /* __i386__ */
354 extern int mkstemps(char *template, int suffix_len
);
356 /* Process creation flags */
360 # define _P_OVERLAY 2
361 # define _P_NOWAITO 3
365 extern int spawnvp(int mode
, const char *cmdname
, const char * const argv
[]);
368 /* Interlocked functions */
370 #if defined(__i386__) && defined(__GNUC__)
372 extern inline long interlocked_cmpxchg( long *dest
, long xchg
, long compare
)
375 __asm__
__volatile__( "lock; cmpxchgl %2,(%1)"
376 : "=a" (ret
) : "r" (dest
), "r" (xchg
), "0" (compare
) : "memory" );
380 extern inline void *interlocked_cmpxchg_ptr( void **dest
, void *xchg
, void *compare
)
383 __asm__
__volatile__( "lock; cmpxchgl %2,(%1)"
384 : "=a" (ret
) : "r" (dest
), "r" (xchg
), "0" (compare
) : "memory" );
388 extern inline long interlocked_xchg( long *dest
, long val
)
391 __asm__
__volatile__( "lock; xchgl %0,(%1)"
392 : "=r" (ret
) : "r" (dest
), "0" (val
) : "memory" );
396 extern inline void *interlocked_xchg_ptr( void **dest
, void *val
)
399 __asm__
__volatile__( "lock; xchgl %0,(%1)"
400 : "=r" (ret
) : "r" (dest
), "0" (val
) : "memory" );
404 extern inline long interlocked_xchg_add( long *dest
, long incr
)
407 __asm__
__volatile__( "lock; xaddl %0,(%1)"
408 : "=r" (ret
) : "r" (dest
), "0" (incr
) : "memory" );
412 #else /* __i386___ && __GNUC__ */
414 extern long interlocked_cmpxchg( long *dest
, long xchg
, long compare
);
415 extern void *interlocked_cmpxchg_ptr( void **dest
, void *xchg
, void *compare
);
416 extern long interlocked_xchg( long *dest
, long val
);
417 extern void *interlocked_xchg_ptr( void **dest
, void *val
);
418 extern long interlocked_xchg_add( long *dest
, long incr
);
420 #endif /* __i386___ && __GNUC__ */
422 #else /* NO_LIBWINE_PORT */
424 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
426 #define fstatvfs __WINE_NOT_PORTABLE(fstatvfs)
427 #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
428 #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
429 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
430 #define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
431 #define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
432 #define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
433 #define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
434 #define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
435 #define lstat __WINE_NOT_PORTABLE(lstat)
436 #define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
437 #define memmove __WINE_NOT_PORTABLE(memmove)
438 #define pread __WINE_NOT_PORTABLE(pread)
439 #define pwrite __WINE_NOT_PORTABLE(pwrite)
440 #define spawnvp __WINE_NOT_PORTABLE(spawnvp)
441 #define statvfs __WINE_NOT_PORTABLE(statvfs)
442 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
443 #define strerror __WINE_NOT_PORTABLE(strerror)
444 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
445 #define usleep __WINE_NOT_PORTABLE(usleep)
447 #endif /* NO_LIBWINE_PORT */
449 #endif /* !defined(__WINE_WINE_PORT_H) */