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 */
30 #include <sys/types.h>
44 /****************************************************************
58 typedef unsigned int size_t;
66 # define HAVE_STRUCT_STATFS_F_BFREE
68 long f_bsize
; /* block_size */
69 long f_blocks
; /* total_blocks */
70 long f_bfree
; /* free_blocks */
72 # else /* defined(__BEOS__) */
74 # endif /* defined(__BEOS__) */
75 #endif /* !defined(HAVE_STATFS) */
78 /****************************************************************
85 #define RTLD_LAZY 0x001
86 #define RTLD_NOW 0x002
87 #define RTLD_GLOBAL 0x100
90 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
91 #define ftruncate chsize
94 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
98 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
99 #define pclose _pclose
102 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
103 #define snprintf _snprintf
106 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
107 #define vsnprintf _vsnprintf
111 # define S_ISLNK(mod) (0)
114 /* So we open files in 64 bit access mode on Linux */
116 # define O_LARGEFILE 0
119 /* Macros to define assembler functions somewhat portably */
122 # define __ASM_GLOBAL_FUNC(name,code) \
123 __asm__( ".align 4\n\t" \
124 ".globl " __ASM_NAME(#name) "\n\t" \
125 __ASM_FUNC(#name) "\n" \
126 __ASM_NAME(#name) ":\n\t" \
129 # define __ASM_GLOBAL_FUNC(name,code) \
130 void __asm_dummy_##name(void) { \
131 asm( ".align 4\n\t" \
132 ".globl " __ASM_NAME(#name) "\n\t" \
133 __ASM_FUNC(#name) "\n" \
134 __ASM_NAME(#name) ":\n\t" \
137 #endif /* __GNUC__ */
140 /* Constructor functions */
143 # define DECL_GLOBAL_CONSTRUCTOR(func) \
144 static void func(void) __attribute__((constructor)); \
145 static void func(void)
146 #elif defined(__i386__)
147 # define DECL_GLOBAL_CONSTRUCTOR(func) \
148 static void __dummy_init_##func(void) { \
149 asm(".section .init,\"ax\"\n\t" \
150 "call " #func "\n\t" \
152 static void func(void)
153 #elif defined(__sparc__)
154 # define DECL_GLOBAL_CONSTRUCTOR(func) \
155 static void __dummy_init_##func(void) { \
156 asm("\t.section \".init\",#alloc,#execinstr\n" \
157 "\tcall " #func "\n" \
159 "\t.section \".text\",#alloc,#execinstr\n" ); } \
160 static void func(void)
162 # error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
166 /****************************************************************
167 * Function definitions (only when using libwine_port)
170 #ifndef NO_LIBWINE_PORT
172 #ifndef HAVE_GETOPT_LONG
179 #ifndef HAVE_STRUCT_OPTION_NAME
189 extern int getopt_long (int ___argc
, char *const *___argv
,
190 const char *__shortopts
,
191 const struct option
*__longopts
, int *__longind
);
192 extern int getopt_long_only (int ___argc
, char *const *___argv
,
193 const char *__shortopts
,
194 const struct option
*__longopts
, int *__longind
);
195 #endif /* HAVE_GETOPT_LONG */
197 #ifndef HAVE_GETPAGESIZE
198 size_t getpagesize(void);
199 #endif /* HAVE_GETPAGESIZE */
202 int lstat(const char *file_name
, struct stat
*buf
);
203 #endif /* HAVE_LSTAT */
206 void *memmove(void *dest
, const void *src
, size_t len
);
207 #endif /* !defined(HAVE_MEMMOVE) */
210 ssize_t
pread( int fd
, void *buf
, size_t count
, off_t offset
);
211 #endif /* HAVE_PREAD */
214 ssize_t
pwrite( int fd
, const void *buf
, size_t count
, off_t offset
);
215 #endif /* HAVE_PWRITE */
218 int statfs(const char *name
, struct statfs
*info
);
219 #endif /* !defined(HAVE_STATFS) */
221 #ifndef HAVE_STRNCASECMP
222 # ifndef HAVE__STRNICMP
223 int strncasecmp(const char *str1
, const char *str2
, size_t n
);
225 # define strncasecmp _strnicmp
227 #endif /* !defined(HAVE_STRNCASECMP) */
229 #ifndef HAVE_STRERROR
230 const char *strerror(int err
);
231 #endif /* !defined(HAVE_STRERROR) */
233 #ifndef HAVE_STRCASECMP
234 # ifndef HAVE__STRICMP
235 int strcasecmp(const char *str1
, const char *str2
);
237 # define strcasecmp _stricmp
239 #endif /* !defined(HAVE_STRCASECMP) */
242 int usleep (unsigned int useconds
);
243 #endif /* !defined(HAVE_USLEEP) */
246 extern inline void *memcpy_unaligned( void *dst
, const void *src
, size_t size
)
248 return memcpy( dst
, src
, size
);
251 extern void *memcpy_unaligned( void *dst
, const void *src
, size_t size
);
252 #endif /* __i386__ */
254 extern int mkstemps(char *template, int suffix_len
);
256 /* Process creation flags */
260 # define _P_OVERLAY 2
261 # define _P_NOWAITO 3
264 extern int spawnvp(int mode
, const char *cmdname
, char *const argv
[]);
266 /* Interlocked functions */
268 #if defined(__i386__) && defined(__GNUC__)
270 extern inline long interlocked_cmpxchg( long *dest
, long xchg
, long compare
)
273 __asm__
__volatile__( "lock; cmpxchgl %2,(%1)"
274 : "=a" (ret
) : "r" (dest
), "r" (xchg
), "0" (compare
) : "memory" );
278 extern inline void *interlocked_cmpxchg_ptr( void **dest
, void *xchg
, void *compare
)
281 __asm__
__volatile__( "lock; cmpxchgl %2,(%1)"
282 : "=a" (ret
) : "r" (dest
), "r" (xchg
), "0" (compare
) : "memory" );
286 extern inline long interlocked_xchg( long *dest
, long val
)
289 __asm__
__volatile__( "lock; xchgl %0,(%1)"
290 : "=r" (ret
) : "r" (dest
), "0" (val
) : "memory" );
294 extern inline void *interlocked_xchg_ptr( void **dest
, void *val
)
297 __asm__
__volatile__( "lock; xchgl %0,(%1)"
298 : "=r" (ret
) : "r" (dest
), "0" (val
) : "memory" );
302 extern inline long interlocked_xchg_add( long *dest
, long incr
)
305 __asm__
__volatile__( "lock; xaddl %0,(%1)"
306 : "=r" (ret
) : "r" (dest
), "0" (incr
) : "memory" );
310 #else /* __i386___ && __GNUC__ */
312 extern long interlocked_cmpxchg( long *dest
, long xchg
, long compare
);
313 extern void *interlocked_cmpxchg_ptr( void **dest
, void *xchg
, void *compare
);
314 extern long interlocked_xchg( long *dest
, long val
);
315 extern void *interlocked_xchg_ptr( void **dest
, void *val
);
316 extern long interlocked_xchg_add( long *dest
, long incr
);
318 #endif /* __i386___ && __GNUC__ */
320 #else /* NO_LIBWINE_PORT */
322 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
324 #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
325 #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
326 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
327 #define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
328 #define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
329 #define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
330 #define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
331 #define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
332 #define lstat __WINE_NOT_PORTABLE(lstat)
333 #define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
334 #define memmove __WINE_NOT_PORTABLE(memmove)
335 #define pread __WINE_NOT_PORTABLE(pread)
336 #define pwrite __WINE_NOT_PORTABLE(pwrite)
337 #define spawnvp __WINE_NOT_PORTABLE(spawnvp)
338 #define statfs __WINE_NOT_PORTABLE(statfs)
339 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
340 #define strerror __WINE_NOT_PORTABLE(strerror)
341 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
342 #define usleep __WINE_NOT_PORTABLE(usleep)
344 #endif /* NO_LIBWINE_PORT */
346 #endif /* !defined(__WINE_WINE_PORT_H) */