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>
45 /****************************************************************
59 typedef unsigned int size_t;
67 # define HAVE_STRUCT_STATFS_F_BFREE
69 long f_bsize; /* block_size */
70 long f_blocks; /* total_blocks */
71 long f_bfree; /* free_blocks */
73 # else /* defined(__BEOS__) */
75 # endif /* defined(__BEOS__) */
76 #endif /* !defined(HAVE_STATFS) */
79 /****************************************************************
86 #define RTLD_LAZY 0x001
87 #define RTLD_NOW 0x002
88 #define RTLD_GLOBAL 0x100
91 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
92 #define ftruncate chsize
95 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
99 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
100 #define pclose _pclose
103 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
104 #define snprintf _snprintf
107 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
108 #define vsnprintf _vsnprintf
112 # define S_ISLNK(mod) (0)
115 /* So we open files in 64 bit access mode on Linux */
117 # define O_LARGEFILE 0
121 /****************************************************************
126 #define M_PI 3.14159265358979323846
130 #define M_PI_2 1.570796326794896619
134 /* Macros to define assembler functions somewhat portably */
137 # define __ASM_GLOBAL_FUNC(name,code) \
138 __asm__( ".align 4\n\t" \
139 ".globl " __ASM_NAME(#name) "\n\t" \
140 __ASM_FUNC(#name) "\n" \
141 __ASM_NAME(#name) ":\n\t" \
144 # define __ASM_GLOBAL_FUNC(name,code) \
145 void __asm_dummy_##name(void) { \
146 asm( ".align 4\n\t" \
147 ".globl " __ASM_NAME(#name) "\n\t" \
148 __ASM_FUNC(#name) "\n" \
149 __ASM_NAME(#name) ":\n\t" \
152 #endif /* __GNUC__ */
155 /* Constructor functions */
158 # define DECL_GLOBAL_CONSTRUCTOR(func) \
159 static void func(void) __attribute__((constructor)); \
160 static void func(void)
161 #elif defined(__i386__)
162 # define DECL_GLOBAL_CONSTRUCTOR(func) \
163 static void __dummy_init_##func(void) { \
164 asm(".section .init,\"ax\"\n\t" \
165 "call " #func "\n\t" \
167 static void func(void)
168 #elif defined(__sparc__)
169 # define DECL_GLOBAL_CONSTRUCTOR(func) \
170 static void __dummy_init_##func(void) { \
171 asm("\t.section \".init\",#alloc,#execinstr\n" \
172 "\tcall " #func "\n" \
174 "\t.section \".text\",#alloc,#execinstr\n" ); } \
175 static void func(void)
177 # error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
181 /****************************************************************
182 * Function definitions (only when using libwine_port)
185 #ifndef NO_LIBWINE_PORT
187 #ifndef HAVE_GETOPT_LONG
194 #ifndef HAVE_STRUCT_OPTION_NAME
204 extern int getopt_long (int ___argc, char *const *___argv,
205 const char *__shortopts,
206 const struct option *__longopts, int *__longind);
207 extern int getopt_long_only (int ___argc, char *const *___argv,
208 const char *__shortopts,
209 const struct option *__longopts, int *__longind);
210 #endif /* HAVE_GETOPT_LONG */
212 #ifndef HAVE_GETPAGESIZE
213 size_t getpagesize(void);
214 #endif /* HAVE_GETPAGESIZE */
217 int lstat(const char *file_name, struct stat *buf);
218 #endif /* HAVE_LSTAT */
221 void *memmove(void *dest, const void *src, size_t len);
222 #endif /* !defined(HAVE_MEMMOVE) */
225 ssize_t pread( int fd, void *buf, size_t count, off_t offset );
226 #endif /* HAVE_PREAD */
229 ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
230 #endif /* HAVE_PWRITE */
233 int statfs(const char *name, struct statfs *info);
234 #endif /* !defined(HAVE_STATFS) */
236 #ifndef HAVE_STRNCASECMP
237 # ifndef HAVE__STRNICMP
238 int strncasecmp(const char *str1, const char *str2, size_t n);
240 # define strncasecmp _strnicmp
242 #endif /* !defined(HAVE_STRNCASECMP) */
244 #ifndef HAVE_STRERROR
245 const char *strerror(int err);
246 #endif /* !defined(HAVE_STRERROR) */
248 #ifndef HAVE_STRCASECMP
249 # ifndef HAVE__STRICMP
250 int strcasecmp(const char *str1, const char *str2);
252 # define strcasecmp _stricmp
254 #endif /* !defined(HAVE_STRCASECMP) */
257 int usleep (unsigned int useconds);
258 #endif /* !defined(HAVE_USLEEP) */
261 static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
263 return memcpy( dst, src, size );
266 extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
267 #endif /* __i386__ */
269 extern int mkstemps(char *template, int suffix_len);
271 /* Process creation flags */
275 # define _P_OVERLAY 2
276 # define _P_NOWAITO 3
279 extern int spawnvp(int mode, const char *cmdname, char *const argv[]);
281 /* Interlocked functions */
283 #if defined(__i386__) && defined(__GNUC__)
285 extern inline long interlocked_cmpxchg( long *dest, long xchg, long compare )
288 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
289 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
293 extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
296 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
297 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
301 extern inline long interlocked_xchg( long *dest, long val )
304 __asm__ __volatile__( "lock; xchgl %0,(%1)"
305 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
309 extern inline void *interlocked_xchg_ptr( void **dest, void *val )
312 __asm__ __volatile__( "lock; xchgl %0,(%1)"
313 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
317 extern inline long interlocked_xchg_add( long *dest, long incr )
320 __asm__ __volatile__( "lock; xaddl %0,(%1)"
321 : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
325 #else /* __i386___ && __GNUC__ */
327 extern long interlocked_cmpxchg( long *dest, long xchg, long compare );
328 extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
329 extern long interlocked_xchg( long *dest, long val );
330 extern void *interlocked_xchg_ptr( void **dest, void *val );
331 extern long interlocked_xchg_add( long *dest, long incr );
333 #endif /* __i386___ && __GNUC__ */
335 #else /* NO_LIBWINE_PORT */
337 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
339 #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
340 #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
341 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
342 #define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
343 #define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
344 #define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
345 #define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
346 #define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
347 #define lstat __WINE_NOT_PORTABLE(lstat)
348 #define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
349 #define memmove __WINE_NOT_PORTABLE(memmove)
350 #define pread __WINE_NOT_PORTABLE(pread)
351 #define pwrite __WINE_NOT_PORTABLE(pwrite)
352 #define spawnvp __WINE_NOT_PORTABLE(spawnvp)
353 #define statfs __WINE_NOT_PORTABLE(statfs)
354 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
355 #define strerror __WINE_NOT_PORTABLE(strerror)
356 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
357 #define usleep __WINE_NOT_PORTABLE(usleep)
359 #endif /* NO_LIBWINE_PORT */
361 #endif /* !defined(__WINE_WINE_PORT_H) */