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>
48 /****************************************************************
62 typedef unsigned int size_t;
67 //#ifndef HAVE_SOCKLEN_T
68 //typedef unsigned int socklen_t;
73 # define HAVE_STRUCT_STATFS_F_BFREE
75 long f_bsize
; /* block_size */
76 long f_blocks
; /* total_blocks */
77 long f_bfree
; /* free_blocks */
79 # else /* defined(__BEOS__) */
81 # endif /* defined(__BEOS__) */
82 #endif /* !defined(HAVE_STATFS) */
85 /****************************************************************
92 #define RTLD_LAZY 0x001
93 #define RTLD_NOW 0x002
94 #define RTLD_GLOBAL 0x100
97 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
98 #define ftruncate chsize
101 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
105 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
106 #define pclose _pclose
109 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
110 #define snprintf _snprintf
113 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
114 #define vsnprintf _vsnprintf
118 # define S_ISLNK(mod) (0)
121 /* So we open files in 64 bit access mode on Linux */
123 # define O_LARGEFILE 0
127 /****************************************************************
132 #define M_PI 3.14159265358979323846
136 #define M_PI_2 1.570796326794896619
140 /* Macros to define assembler functions somewhat portably */
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 /* Constructor functions */
164 # define DECL_GLOBAL_CONSTRUCTOR(func) \
165 static void func(void) __attribute__((constructor)); \
166 static void func(void)
167 #elif defined(__i386__)
168 # define DECL_GLOBAL_CONSTRUCTOR(func) \
169 static void __dummy_init_##func(void) { \
170 asm(".section .init,\"ax\"\n\t" \
171 "call " #func "\n\t" \
173 static void func(void)
174 #elif defined(__sparc__)
175 # define DECL_GLOBAL_CONSTRUCTOR(func) \
176 static void __dummy_init_##func(void) { \
177 asm("\t.section \".init\",#alloc,#execinstr\n" \
178 "\tcall " #func "\n" \
180 "\t.section \".text\",#alloc,#execinstr\n" ); } \
181 static void func(void)
183 # error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
187 /* Register functions */
190 #define DEFINE_REGS_ENTRYPOINT( name, fn, args, pop_args ) \
191 __ASM_GLOBAL_FUNC( name, \
192 "call " __ASM_NAME("__wine_call_from_32_regs") "\n\t" \
193 ".long " __ASM_NAME(#fn) "\n\t" \
194 ".byte " #args "," #pop_args )
195 /* FIXME: add support for other CPUs */
196 #endif /* __i386__ */
199 /****************************************************************
200 * Function definitions (only when using libwine_port)
203 #ifndef NO_LIBWINE_PORT
205 #ifndef HAVE_GETOPT_LONG
212 #ifndef HAVE_STRUCT_OPTION_NAME
222 extern int getopt_long (int ___argc
, char *const *___argv
,
223 const char *__shortopts
,
224 const struct option
*__longopts
, int *__longind
);
225 extern int getopt_long_only (int ___argc
, char *const *___argv
,
226 const char *__shortopts
,
227 const struct option
*__longopts
, int *__longind
);
228 #endif /* HAVE_GETOPT_LONG */
230 #ifndef HAVE_GETPAGESIZE
231 size_t getpagesize(void);
232 #endif /* HAVE_GETPAGESIZE */
236 #endif /* HAVE_GETTID */
239 int lstat(const char *file_name
, struct stat
*buf
);
240 #endif /* HAVE_LSTAT */
243 void *memmove(void *dest
, const void *src
, size_t len
);
244 #endif /* !defined(HAVE_MEMMOVE) */
248 ssize_t
pread( int fd
, void *buf
, size_t count
, off_t offset
);
249 #endif /* HAVE_PREAD */
252 ssize_t
pwrite( int fd
, const void *buf
, size_t count
, off_t offset
);
253 #endif /* HAVE_PWRITE */
254 #endif /* __REACTOS__ */
257 #ifndef HAVE_SIGSETJMP
259 typedef jmp_buf sigjmp_buf
;
260 int sigsetjmp( sigjmp_buf buf
, int savesigs
);
261 void siglongjmp( sigjmp_buf buf
, int val
);
262 #endif /* HAVE_SIGSETJMP */
266 int statfs(const char *name
, struct statfs
*info
);
267 #endif /* !defined(HAVE_STATFS) */
269 #ifndef HAVE_STRNCASECMP
270 # ifndef HAVE__STRNICMP
271 int strncasecmp(const char *str1
, const char *str2
, size_t n
);
273 # define strncasecmp _strnicmp
275 #endif /* !defined(HAVE_STRNCASECMP) */
277 #ifndef HAVE_STRERROR
278 const char *strerror(int err
);
279 #endif /* !defined(HAVE_STRERROR) */
281 #ifndef HAVE_STRCASECMP
282 # ifndef HAVE__STRICMP
283 int strcasecmp(const char *str1
, const char *str2
);
285 # define strcasecmp _stricmp
287 #endif /* !defined(HAVE_STRCASECMP) */
290 int usleep (unsigned int useconds
);
291 #endif /* !defined(HAVE_USLEEP) */
294 static inline void *memcpy_unaligned( void *dst
, const void *src
, size_t size
)
296 return memcpy( dst
, src
, size
);
299 extern void *memcpy_unaligned( void *dst
, const void *src
, size_t size
);
300 #endif /* __i386__ */
302 extern int mkstemps(char *template, int suffix_len
);
304 /* Process creation flags */
308 # define _P_OVERLAY 2
309 # define _P_NOWAITO 3
313 extern int spawnvp(int mode
, const char *cmdname
, const char * const argv
[]);
316 /* Interlocked functions */
318 #if defined(__i386__) && defined(__GNUC__)
320 extern inline long interlocked_cmpxchg( long *dest
, long xchg
, long compare
)
323 __asm__
__volatile__( "lock; cmpxchgl %2,(%1)"
324 : "=a" (ret
) : "r" (dest
), "r" (xchg
), "0" (compare
) : "memory" );
328 extern inline void *interlocked_cmpxchg_ptr( void **dest
, void *xchg
, void *compare
)
331 __asm__
__volatile__( "lock; cmpxchgl %2,(%1)"
332 : "=a" (ret
) : "r" (dest
), "r" (xchg
), "0" (compare
) : "memory" );
336 extern inline long interlocked_xchg( long *dest
, long val
)
339 __asm__
__volatile__( "lock; xchgl %0,(%1)"
340 : "=r" (ret
) : "r" (dest
), "0" (val
) : "memory" );
344 extern inline void *interlocked_xchg_ptr( void **dest
, void *val
)
347 __asm__
__volatile__( "lock; xchgl %0,(%1)"
348 : "=r" (ret
) : "r" (dest
), "0" (val
) : "memory" );
352 extern inline long interlocked_xchg_add( long *dest
, long incr
)
355 __asm__
__volatile__( "lock; xaddl %0,(%1)"
356 : "=r" (ret
) : "r" (dest
), "0" (incr
) : "memory" );
360 #else /* __i386___ && __GNUC__ */
362 extern long interlocked_cmpxchg( long *dest
, long xchg
, long compare
);
363 extern void *interlocked_cmpxchg_ptr( void **dest
, void *xchg
, void *compare
);
364 extern long interlocked_xchg( long *dest
, long val
);
365 extern void *interlocked_xchg_ptr( void **dest
, void *val
);
366 extern long interlocked_xchg_add( long *dest
, long incr
);
368 #endif /* __i386___ && __GNUC__ */
370 #else /* NO_LIBWINE_PORT */
372 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
374 #define getopt_long __WINE_NOT_PORTABLE(getopt_long)
375 #define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
376 #define getpagesize __WINE_NOT_PORTABLE(getpagesize)
377 #define interlocked_cmpxchg __WINE_NOT_PORTABLE(interlocked_cmpxchg)
378 #define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
379 #define interlocked_xchg __WINE_NOT_PORTABLE(interlocked_xchg)
380 #define interlocked_xchg_ptr __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
381 #define interlocked_xchg_add __WINE_NOT_PORTABLE(interlocked_xchg_add)
382 #define lstat __WINE_NOT_PORTABLE(lstat)
383 #define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
384 #define memmove __WINE_NOT_PORTABLE(memmove)
385 #define pread __WINE_NOT_PORTABLE(pread)
386 #define pwrite __WINE_NOT_PORTABLE(pwrite)
387 #define spawnvp __WINE_NOT_PORTABLE(spawnvp)
388 #define statfs __WINE_NOT_PORTABLE(statfs)
389 #define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
390 #define strerror __WINE_NOT_PORTABLE(strerror)
391 #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
392 #define usleep __WINE_NOT_PORTABLE(usleep)
394 #endif /* NO_LIBWINE_PORT */
396 #endif /* !defined(__WINE_WINE_PORT_H) */