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
119 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
120 #define snprintf _snprintf
124 # define S_ISLNK(mod) (0)
127 /* So we open files in 64 bit access mode on Linux */
129 # define O_LARGEFILE 0
132 /* Macros to define assembler functions somewhat portably */
134 #ifdef NEED_UNDERSCORE_PREFIX
135 # define __ASM_NAME(name) "_" name
137 # define __ASM_NAME(name) name
140 #ifdef NEED_TYPE_IN_DEF
141 # define __ASM_FUNC(name) ".def " __ASM_NAME(name) "; .scl 2; .type 32; .endef"
143 # define __ASM_FUNC(name) ".type " __ASM_NAME(name) ",@function"
147 # define __ASM_GLOBAL_FUNC(name,code) \
148 __asm__( ".align 4\n\t" \
149 ".globl " __ASM_NAME(#name) "\n\t" \
150 __ASM_FUNC(#name) "\n" \
151 __ASM_NAME(#name) ":\n\t" \
154 # define __ASM_GLOBAL_FUNC(name,code) \
155 void __asm_dummy_##name(void) { \
156 asm( ".align 4\n\t" \
157 ".globl " __ASM_NAME(#name) "\n\t" \
158 __ASM_FUNC(#name) "\n" \
159 __ASM_NAME(#name) ":\n\t" \
162 #endif /* __GNUC__ */
165 /* Macros to access unaligned or wrong-endian WORDs and DWORDs. */
167 #define PUT_WORD(ptr, w) (*(WORD *)(ptr) = (w))
168 #define GET_WORD(ptr) (*(WORD *)(ptr))
169 #define PUT_DWORD(ptr, d) (*(DWORD *)(ptr) = (d))
170 #define GET_DWORD(ptr) (*(DWORD *)(ptr))
172 #define PUT_LE_WORD(ptr, w) \
173 do { ((BYTE *)(ptr))[0] = LOBYTE(w); \
174 ((BYTE *)(ptr))[1] = HIBYTE(w); } while (0)
175 #define GET_LE_WORD(ptr) \
176 MAKEWORD( ((BYTE *)(ptr))[0], \
178 #define PUT_LE_DWORD(ptr, d) \
179 do { PUT_LE_WORD(&((WORD *)(ptr))[0], LOWORD(d)); \
180 PUT_LE_WORD(&((WORD *)(ptr))[1], HIWORD(d)); } while (0)
181 #define GET_LE_DWORD(ptr) \
182 ((DWORD)MAKELONG( GET_LE_WORD(&((WORD *)(ptr))[0]), \
183 GET_LE_WORD(&((WORD *)(ptr))[1]) ))
185 #define PUT_BE_WORD(ptr, w) \
186 do { ((BYTE *)(ptr))[1] = LOBYTE(w); \
187 ((BYTE *)(ptr))[0] = HIBYTE(w); } while (0)
188 #define GET_BE_WORD(ptr) \
189 MAKEWORD( ((BYTE *)(ptr))[1], \
191 #define PUT_BE_DWORD(ptr, d) \
192 do { PUT_BE_WORD(&((WORD *)(ptr))[1], LOWORD(d)); \
193 PUT_BE_WORD(&((WORD *)(ptr))[0], HIWORD(d)); } while (0)
194 #define GET_BE_DWORD(ptr) \
195 ((DWORD)MAKELONG( GET_BE_WORD(&((WORD *)(ptr))[1]), \
196 GET_BE_WORD(&((WORD *)(ptr))[0]) ))
198 #if defined(ALLOW_UNALIGNED_ACCESS)
199 #define PUT_UA_WORD(ptr, w) PUT_WORD(ptr, w)
200 #define GET_UA_WORD(ptr) GET_WORD(ptr)
201 #define PUT_UA_DWORD(ptr, d) PUT_DWORD(ptr, d)
202 #define GET_UA_DWORD(ptr) GET_DWORD(ptr)
203 #elif defined(WORDS_BIGENDIAN)
204 #define PUT_UA_WORD(ptr, w) PUT_BE_WORD(ptr, w)
205 #define GET_UA_WORD(ptr) GET_BE_WORD(ptr)
206 #define PUT_UA_DWORD(ptr, d) PUT_BE_DWORD(ptr, d)
207 #define GET_UA_DWORD(ptr) GET_BE_DWORD(ptr)
209 #define PUT_UA_WORD(ptr, w) PUT_LE_WORD(ptr, w)
210 #define GET_UA_WORD(ptr) GET_LE_WORD(ptr)
211 #define PUT_UA_DWORD(ptr, d) PUT_LE_DWORD(ptr, d)
212 #define GET_UA_DWORD(ptr) GET_LE_DWORD(ptr)
216 /****************************************************************
217 * Function definitions (only when using libwine)
222 #if !defined(HAVE_CLONE) && defined(linux)
223 int clone(int (*fn
)(void *arg
), void *stack
, int flags
, void *arg
);
224 #endif /* !defined(HAVE_CLONE) && defined(linux) */
226 #ifndef HAVE_GETNETBYADDR
227 struct netent
*getnetbyaddr(unsigned long net
, int type
);
228 #endif /* defined(HAVE_GETNETBYNAME) */
230 #ifndef HAVE_GETNETBYNAME
231 struct netent
*getnetbyname(const char *name
);
232 #endif /* defined(HAVE_GETNETBYNAME) */
234 #ifndef HAVE_GETPAGESIZE
235 size_t getpagesize(void);
236 #endif /* HAVE_GETPAGESIZE */
238 #ifndef HAVE_GETPROTOBYNAME
239 struct protoent
*getprotobyname(const char *name
);
240 #endif /* !defined(HAVE_GETPROTOBYNAME) */
242 #ifndef HAVE_GETPROTOBYNUMBER
243 struct protoent
*getprotobynumber(int proto
);
244 #endif /* !defined(HAVE_GETPROTOBYNUMBER) */
246 #ifndef HAVE_GETSERVBYPORT
247 struct servent
*getservbyport(int port
, const char *proto
);
248 #endif /* !defined(HAVE_GETSERVBYPORT) */
250 #ifndef HAVE_GETSOCKOPT
251 int getsockopt(int socket
, int level
, int option_name
, void *option_value
, size_t *option_len
);
252 #endif /* !defined(HAVE_GETSOCKOPT) */
254 #ifndef HAVE_INET_NETWORK
255 unsigned long inet_network(const char *cp
);
256 #endif /* !defined(HAVE_INET_NETWORK) */
259 int lstat(const char *file_name
, struct stat
*buf
);
260 #endif /* HAVE_LSTAT */
263 void *memmove(void *dest
, const void *src
, unsigned int len
);
264 #endif /* !defined(HAVE_MEMMOVE) */
267 ssize_t
pread( int fd
, void *buf
, size_t count
, off_t offset
);
268 #endif /* HAVE_PREAD */
271 ssize_t
pwrite( int fd
, const void *buf
, size_t count
, off_t offset
);
272 #endif /* HAVE_PWRITE */
275 int statfs(const char *name
, struct statfs
*info
);
276 #endif /* !defined(HAVE_STATFS) */
278 #ifndef HAVE_STRNCASECMP
279 # ifndef HAVE__STRNICMP
280 int strncasecmp(const char *str1
, const char *str2
, size_t n
);
282 # define strncasecmp _strnicmp
284 #endif /* !defined(HAVE_STRNCASECMP) */
286 #ifndef HAVE_STRERROR
287 const char *strerror(int err
);
288 #endif /* !defined(HAVE_STRERROR) */
290 #ifndef HAVE_STRCASECMP
291 # ifndef HAVE__STRICMP
292 int strcasecmp(const char *str1
, const char *str2
);
294 # define strcasecmp _stricmp
296 #endif /* !defined(HAVE_STRCASECMP) */
299 int usleep (unsigned int useconds
);
300 #endif /* !defined(HAVE_USLEEP) */
302 /* Interlocked functions */
304 #if defined(__i386__) && defined(__GNUC__)
306 inline static long interlocked_cmpxchg( long *dest
, long xchg
, long compare
)
309 __asm__
__volatile__( "lock; cmpxchgl %2,(%1)"
310 : "=a" (ret
) : "r" (dest
), "r" (xchg
), "0" (compare
) : "memory" );
314 inline static void *interlocked_cmpxchg_ptr( void **dest
, void *xchg
, void *compare
)
317 __asm__
__volatile__( "lock; cmpxchgl %2,(%1)"
318 : "=a" (ret
) : "r" (dest
), "r" (xchg
), "0" (compare
) : "memory" );
322 inline static long interlocked_xchg( long *dest
, long val
)
325 __asm__
__volatile__( "lock; xchgl %0,(%1)"
326 : "=r" (ret
) : "r" (dest
), "0" (val
) : "memory" );
330 inline static void *interlocked_xchg_ptr( void **dest
, void *val
)
333 __asm__
__volatile__( "lock; xchgl %0,(%1)"
334 : "=r" (ret
) : "r" (dest
), "0" (val
) : "memory" );
338 inline static long interlocked_xchg_add( long *dest
, long incr
)
341 __asm__
__volatile__( "lock; xaddl %0,(%1)"
342 : "=r" (ret
) : "r" (dest
), "0" (incr
) : "memory" );
346 #else /* __i386___ && __GNUC__ */
348 extern long interlocked_cmpxchg( long *dest
, long xchg
, long compare
);
349 extern void *interlocked_cmpxchg_ptr( void **dest
, void *xchg
, void *compare
);
350 extern long interlocked_xchg( long *dest
, long val
);
351 extern void *interlocked_xchg_ptr( void **dest
, void *val
);
352 extern long interlocked_xchg_add( long *dest
, long incr
);
354 #endif /* __i386___ && __GNUC__ */
356 #else /* NO_LIBWINE */
358 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
360 #define clone __WINE_NOT_PORTABLE(clone)
361 #define getnetbyaddr __WINE_NOT_PORTABLE(getnetbyaddr)
362 #define getnetbyname __WINE_NOT_PORTABLE(getnetbyname)
363 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
364 #define getprotobyname __WINE_NOT_PORTABLE(getprotobyname)
365 #define getprotobynumber __WINE_NOT_PORTABLE(getprotobynumber)
366 #define getservbyport __WINE_NOT_PORTABLE(getservbyport)
367 #define getsockopt __WINE_NOT_PORTABLE(getsockopt)
368 #define inet_network __WINE_NOT_PORTABLE(inet_network)
369 #define lstat __WINE_NOT_PORTABLE(lstat)
370 #define memmove __WINE_NOT_PORTABLE(memmove)
371 #define pread __WINE_NOT_PORTABLE(pread)
372 #define pwrite __WINE_NOT_PORTABLE(pwrite)
373 #define statfs __WINE_NOT_PORTABLE(statfs)
374 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
375 #define strerror __WINE_NOT_PORTABLE(strerror)
376 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
377 #define usleep __WINE_NOT_PORTABLE(usleep)
379 #endif /* NO_LIBWINE */
381 #endif /* !defined(__WINE_WINE_PORT_H) */