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 STATFS_HAS_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
107 # define S_ISLNK(mod) (0)
110 /* So we open files in 64 bit access mode on Linux */
112 # define O_LARGEFILE 0
115 /* Macros to define assembler functions somewhat portably */
118 # define __ASM_GLOBAL_FUNC(name,code) \
119 __asm__( ".align 4\n\t" \
120 ".globl " __ASM_NAME(#name) "\n\t" \
121 __ASM_FUNC(#name) "\n" \
122 __ASM_NAME(#name) ":\n\t" \
125 # define __ASM_GLOBAL_FUNC(name,code) \
126 void __asm_dummy_##name(void) { \
127 asm( ".align 4\n\t" \
128 ".globl " __ASM_NAME(#name) "\n\t" \
129 __ASM_FUNC(#name) "\n" \
130 __ASM_NAME(#name) ":\n\t" \
133 #endif /* __GNUC__ */
136 /* Constructor functions */
139 # define DECL_GLOBAL_CONSTRUCTOR(func) \
140 static void func(void) __attribute__((constructor)); \
141 static void func(void)
142 #elif defined(__i386__)
143 # define DECL_GLOBAL_CONSTRUCTOR(func) \
144 static void __dummy_init_##func(void) { \
145 asm(".section .init,\"ax\"\n\t" \
146 "call " #func "\n\t" \
148 static void func(void)
149 #elif defined(__sparc__)
150 # define DECL_GLOBAL_CONSTRUCTOR(func) \
151 static void __dummy_init_##func(void) { \
152 asm("\t.section \".init\",#alloc,#execinstr\n" \
153 "\tcall " #func "\n" \
155 "\t.section \".text\",#alloc,#execinstr\n" ); } \
156 static void func(void)
158 # error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
162 /****************************************************************
163 * Function definitions (only when using libwine)
168 #if !defined(HAVE_CLONE) && defined(linux)
169 int clone(int (*fn)(void *arg), void *stack, int flags, void *arg);
170 #endif /* !defined(HAVE_CLONE) && defined(linux) */
172 #ifndef HAVE_GETPAGESIZE
173 size_t getpagesize(void);
174 #endif /* HAVE_GETPAGESIZE */
176 #ifndef HAVE_GETSOCKOPT
177 int getsockopt(int socket, int level, int option_name, void *option_value, size_t *option_len);
178 #endif /* !defined(HAVE_GETSOCKOPT) */
180 #ifndef HAVE_INET_NETWORK
181 unsigned long inet_network(const char *cp);
182 #endif /* !defined(HAVE_INET_NETWORK) */
185 int lstat(const char *file_name, struct stat *buf);
186 #endif /* HAVE_LSTAT */
189 int mkstemp(char *tmpfn);
190 #endif /* HAVE_MKSTEMP */
193 void *memmove(void *dest, const void *src, size_t len);
194 #endif /* !defined(HAVE_MEMMOVE) */
197 ssize_t pread( int fd, void *buf, size_t count, off_t offset );
198 #endif /* HAVE_PREAD */
201 ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
202 #endif /* HAVE_PWRITE */
205 int statfs(const char *name, struct statfs *info);
206 #endif /* !defined(HAVE_STATFS) */
208 #ifndef HAVE_STRNCASECMP
209 # ifndef HAVE__STRNICMP
210 int strncasecmp(const char *str1, const char *str2, size_t n);
212 # define strncasecmp _strnicmp
214 #endif /* !defined(HAVE_STRNCASECMP) */
216 #ifndef HAVE_STRERROR
217 const char *strerror(int err);
218 #endif /* !defined(HAVE_STRERROR) */
220 #ifndef HAVE_STRCASECMP
221 # ifndef HAVE__STRICMP
222 int strcasecmp(const char *str1, const char *str2);
224 # define strcasecmp _stricmp
226 #endif /* !defined(HAVE_STRCASECMP) */
229 int usleep (unsigned int useconds);
230 #endif /* !defined(HAVE_USLEEP) */
233 #define wine_memcpy_unaligned memcpy
235 extern void *wine_memcpy_unaligned( void *dst, const void *src, size_t size );
236 #endif /* __i386__ */
238 /* Interlocked functions */
240 #if defined(__i386__) && defined(__GNUC__)
242 inline static long interlocked_cmpxchg( long *dest, long xchg, long compare )
245 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
246 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
250 inline static void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
253 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
254 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
258 inline static long interlocked_xchg( long *dest, long val )
261 __asm__ __volatile__( "lock; xchgl %0,(%1)"
262 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
266 inline static void *interlocked_xchg_ptr( void **dest, void *val )
269 __asm__ __volatile__( "lock; xchgl %0,(%1)"
270 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
274 inline static long interlocked_xchg_add( long *dest, long incr )
277 __asm__ __volatile__( "lock; xaddl %0,(%1)"
278 : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
282 #else /* __i386___ && __GNUC__ */
284 extern long interlocked_cmpxchg( long *dest, long xchg, long compare );
285 extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
286 extern long interlocked_xchg( long *dest, long val );
287 extern void *interlocked_xchg_ptr( void **dest, void *val );
288 extern long interlocked_xchg_add( long *dest, long incr );
290 #endif /* __i386___ && __GNUC__ */
292 #else /* NO_LIBWINE */
294 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
296 #define clone __WINE_NOT_PORTABLE(clone)
297 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
298 #define getsockopt __WINE_NOT_PORTABLE(getsockopt)
299 #define inet_network __WINE_NOT_PORTABLE(inet_network)
300 #define lstat __WINE_NOT_PORTABLE(lstat)
301 #define memmove __WINE_NOT_PORTABLE(memmove)
302 #define pread __WINE_NOT_PORTABLE(pread)
303 #define pwrite __WINE_NOT_PORTABLE(pwrite)
304 #define statfs __WINE_NOT_PORTABLE(statfs)
305 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
306 #define strerror __WINE_NOT_PORTABLE(strerror)
307 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
308 #define usleep __WINE_NOT_PORTABLE(usleep)
310 #endif /* NO_LIBWINE */
312 #endif /* !defined(__WINE_WINE_PORT_H) */