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;
64 #if !defined(HAVE_GETNETBYADDR) && !defined(HAVE_GETNETBYNAME)
71 #endif /* !defined(HAVE_GETNETBYADDR) && !defined(HAVE_GETNETBYNAME) */
73 #if !defined(HAVE_GETPROTOBYNAME) && !defined(HAVE_GETPROTOBYNUMBER)
79 #endif /* !defined(HAVE_GETPROTOBYNAME) && !defined(HAVE_GETPROTOBYNUMBER) */
83 # define STATFS_HAS_BFREE
85 long f_bsize; /* block_size */
86 long f_blocks; /* total_blocks */
87 long f_bfree; /* free_blocks */
89 # else /* defined(__BEOS__) */
91 # endif /* defined(__BEOS__) */
92 #endif /* !defined(HAVE_STATFS) */
95 /****************************************************************
102 #define RTLD_LAZY 0x001
103 #define RTLD_NOW 0x002
104 #define RTLD_GLOBAL 0x100
107 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
108 #define ftruncate chsize
111 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
115 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
116 #define pclose _pclose
120 # define S_ISLNK(mod) (0)
123 /* So we open files in 64 bit access mode on Linux */
125 # define O_LARGEFILE 0
128 /* Macros to define assembler functions somewhat portably */
130 #ifdef NEED_UNDERSCORE_PREFIX
131 # define __ASM_NAME(name) "_" name
133 # define __ASM_NAME(name) name
136 #ifdef NEED_TYPE_IN_DEF
137 # define __ASM_FUNC(name) ".def " __ASM_NAME(name) "; .scl 2; .type 32; .endef"
139 # define __ASM_FUNC(name) ".type " __ASM_NAME(name) ",@function"
143 # define __ASM_GLOBAL_FUNC(name,code) \
144 __asm__( ".align 4\n\t" \
145 ".globl " __ASM_NAME(#name) "\n\t" \
146 __ASM_FUNC(#name) "\n" \
147 __ASM_NAME(#name) ":\n\t" \
150 # define __ASM_GLOBAL_FUNC(name,code) \
151 void __asm_dummy_##name(void) { \
152 asm( ".align 4\n\t" \
153 ".globl " __ASM_NAME(#name) "\n\t" \
154 __ASM_FUNC(#name) "\n" \
155 __ASM_NAME(#name) ":\n\t" \
158 #endif /* __GNUC__ */
161 /* Macros to access unaligned or wrong-endian WORDs and DWORDs. */
163 #define PUT_WORD(ptr, w) (*(WORD *)(ptr) = (w))
164 #define GET_WORD(ptr) (*(WORD *)(ptr))
165 #define PUT_DWORD(ptr, d) (*(DWORD *)(ptr) = (d))
166 #define GET_DWORD(ptr) (*(DWORD *)(ptr))
168 #define PUT_LE_WORD(ptr, w) \
169 do { ((BYTE *)(ptr))[0] = LOBYTE(w); \
170 ((BYTE *)(ptr))[1] = HIBYTE(w); } while (0)
171 #define GET_LE_WORD(ptr) \
172 MAKEWORD( ((BYTE *)(ptr))[0], \
174 #define PUT_LE_DWORD(ptr, d) \
175 do { PUT_LE_WORD(&((WORD *)(ptr))[0], LOWORD(d)); \
176 PUT_LE_WORD(&((WORD *)(ptr))[1], HIWORD(d)); } while (0)
177 #define GET_LE_DWORD(ptr) \
178 ((DWORD)MAKELONG( GET_LE_WORD(&((WORD *)(ptr))[0]), \
179 GET_LE_WORD(&((WORD *)(ptr))[1]) ))
181 #define PUT_BE_WORD(ptr, w) \
182 do { ((BYTE *)(ptr))[1] = LOBYTE(w); \
183 ((BYTE *)(ptr))[0] = HIBYTE(w); } while (0)
184 #define GET_BE_WORD(ptr) \
185 MAKEWORD( ((BYTE *)(ptr))[1], \
187 #define PUT_BE_DWORD(ptr, d) \
188 do { PUT_BE_WORD(&((WORD *)(ptr))[1], LOWORD(d)); \
189 PUT_BE_WORD(&((WORD *)(ptr))[0], HIWORD(d)); } while (0)
190 #define GET_BE_DWORD(ptr) \
191 ((DWORD)MAKELONG( GET_BE_WORD(&((WORD *)(ptr))[1]), \
192 GET_BE_WORD(&((WORD *)(ptr))[0]) ))
194 #if defined(ALLOW_UNALIGNED_ACCESS)
195 #define PUT_UA_WORD(ptr, w) PUT_WORD(ptr, w)
196 #define GET_UA_WORD(ptr) GET_WORD(ptr)
197 #define PUT_UA_DWORD(ptr, d) PUT_DWORD(ptr, d)
198 #define GET_UA_DWORD(ptr) GET_DWORD(ptr)
199 #elif defined(WORDS_BIGENDIAN)
200 #define PUT_UA_WORD(ptr, w) PUT_BE_WORD(ptr, w)
201 #define GET_UA_WORD(ptr) GET_BE_WORD(ptr)
202 #define PUT_UA_DWORD(ptr, d) PUT_BE_DWORD(ptr, d)
203 #define GET_UA_DWORD(ptr) GET_BE_DWORD(ptr)
205 #define PUT_UA_WORD(ptr, w) PUT_LE_WORD(ptr, w)
206 #define GET_UA_WORD(ptr) GET_LE_WORD(ptr)
207 #define PUT_UA_DWORD(ptr, d) PUT_LE_DWORD(ptr, d)
208 #define GET_UA_DWORD(ptr) GET_LE_DWORD(ptr)
212 /****************************************************************
213 * Function definitions (only when using libwine)
218 #if !defined(HAVE_CLONE) && defined(linux)
219 int clone(int (*fn)(void *arg), void *stack, int flags, void *arg);
220 #endif /* !defined(HAVE_CLONE) && defined(linux) */
222 #ifndef HAVE_GETNETBYADDR
223 struct netent *getnetbyaddr(unsigned long net, int type);
224 #endif /* defined(HAVE_GETNETBYNAME) */
226 #ifndef HAVE_GETNETBYNAME
227 struct netent *getnetbyname(const char *name);
228 #endif /* defined(HAVE_GETNETBYNAME) */
230 #ifndef HAVE_GETPAGESIZE
231 size_t getpagesize(void);
232 #endif /* HAVE_GETPAGESIZE */
234 #ifndef HAVE_GETPROTOBYNAME
235 struct protoent *getprotobyname(const char *name);
236 #endif /* !defined(HAVE_GETPROTOBYNAME) */
238 #ifndef HAVE_GETPROTOBYNUMBER
239 struct protoent *getprotobynumber(int proto);
240 #endif /* !defined(HAVE_GETPROTOBYNUMBER) */
242 #ifndef HAVE_GETSERVBYPORT
243 struct servent *getservbyport(int port, const char *proto);
244 #endif /* !defined(HAVE_GETSERVBYPORT) */
246 #ifndef HAVE_GETSOCKOPT
247 int getsockopt(int socket, int level, int option_name, void *option_value, size_t *option_len);
248 #endif /* !defined(HAVE_GETSOCKOPT) */
250 #ifndef HAVE_INET_NETWORK
251 unsigned long inet_network(const char *cp);
252 #endif /* !defined(HAVE_INET_NETWORK) */
255 int lstat(const char *file_name, struct stat *buf);
256 #endif /* HAVE_LSTAT */
259 void *memmove(void *dest, const void *src, unsigned int len);
260 #endif /* !defined(HAVE_MEMMOVE) */
263 ssize_t pread( int fd, void *buf, size_t count, off_t offset );
264 #endif /* HAVE_PREAD */
267 ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
268 #endif /* HAVE_PWRITE */
271 int statfs(const char *name, struct statfs *info);
272 #endif /* !defined(HAVE_STATFS) */
274 #ifndef HAVE_STRNCASECMP
275 # ifndef HAVE__STRNICMP
276 int strncasecmp(const char *str1, const char *str2, size_t n);
278 # define strncasecmp _strnicmp
280 #endif /* !defined(HAVE_STRNCASECMP) */
282 #ifndef HAVE_STRERROR
283 const char *strerror(int err);
284 #endif /* !defined(HAVE_STRERROR) */
286 #ifndef HAVE_STRCASECMP
287 # ifndef HAVE__STRICMP
288 int strcasecmp(const char *str1, const char *str2);
290 # define strcasecmp _stricmp
292 #endif /* !defined(HAVE_STRCASECMP) */
295 int usleep (unsigned int useconds);
296 #endif /* !defined(HAVE_USLEEP) */
298 /* Interlocked functions */
300 #if defined(__i386__) && defined(__GNUC__)
302 inline static long interlocked_cmpxchg( long *dest, long xchg, long compare )
305 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
306 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
310 inline static void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
313 __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
314 : "=a" (ret) : "r" (dest), "r" (xchg), "0" (compare) : "memory" );
318 inline static long interlocked_xchg( long *dest, long val )
321 __asm__ __volatile__( "lock; xchgl %0,(%1)"
322 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
326 inline static void *interlocked_xchg_ptr( void **dest, void *val )
329 __asm__ __volatile__( "lock; xchgl %0,(%1)"
330 : "=r" (ret) : "r" (dest), "0" (val) : "memory" );
334 inline static long interlocked_xchg_add( long *dest, long incr )
337 __asm__ __volatile__( "lock; xaddl %0,(%1)"
338 : "=r" (ret) : "r" (dest), "0" (incr) : "memory" );
342 #else /* __i386___ && __GNUC__ */
344 extern long interlocked_cmpxchg( long *dest, long xchg, long compare );
345 extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
346 extern long interlocked_xchg( long *dest, long val );
347 extern void *interlocked_xchg_ptr( void **dest, void *val );
348 extern long interlocked_xchg_add( long *dest, long incr );
350 #endif /* __i386___ && __GNUC__ */
352 #else /* NO_LIBWINE */
354 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
356 #define clone __WINE_NOT_PORTABLE(clone)
357 #define getnetbyaddr __WINE_NOT_PORTABLE(getnetbyaddr)
358 #define getnetbyname __WINE_NOT_PORTABLE(getnetbyname)
359 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
360 #define getprotobyname __WINE_NOT_PORTABLE(getprotobyname)
361 #define getprotobynumber __WINE_NOT_PORTABLE(getprotobynumber)
362 #define getservbyport __WINE_NOT_PORTABLE(getservbyport)
363 #define getsockopt __WINE_NOT_PORTABLE(getsockopt)
364 #define inet_network __WINE_NOT_PORTABLE(inet_network)
365 #define lstat __WINE_NOT_PORTABLE(lstat)
366 #define memmove __WINE_NOT_PORTABLE(memmove)
367 #define pread __WINE_NOT_PORTABLE(pread)
368 #define pwrite __WINE_NOT_PORTABLE(pwrite)
369 #define statfs __WINE_NOT_PORTABLE(statfs)
370 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
371 #define strerror __WINE_NOT_PORTABLE(strerror)
372 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
373 #define usleep __WINE_NOT_PORTABLE(usleep)
375 #endif /* NO_LIBWINE */
377 #endif /* !defined(__WINE_WINE_PORT_H) */