ReactOS 0.4.15-dev-8219-ge8b88cf
port.h
Go to the documentation of this file.
1/*
2 * Wine porting definitions
3 *
4 * Copyright 1996 Alexandre Julliard
5 *
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.
10 *
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.
15 *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#ifndef __WINE_WINE_PORT_H
22#define __WINE_WINE_PORT_H
23
24#ifndef __WINE_CONFIG_H
25# error You must include config.h to use this header
26#endif
27
28#ifndef _GNU_SOURCE
29# define _GNU_SOURCE /* for pread/pwrite, isfinite */
30#endif
31#include <fcntl.h>
32#include <math.h>
33#include <sys/types.h>
34#include <sys/stat.h>
35#ifdef HAVE_DIRECT_H
36# include <direct.h>
37#endif
38#ifdef HAVE_IO_H
39# include <io.h>
40#endif
41#ifdef HAVE_PROCESS_H
42# include <process.h>
43#endif
44#include <string.h>
45#ifdef HAVE_UNISTD_H
46# include <unistd.h>
47#endif
48
49
50/****************************************************************
51 * Type definitions
52 */
53
54#if !defined(_MSC_VER) && !defined(__int64)
55# if defined(__x86_64__) || defined(_WIN64)
56# define __int64 long
57# else
58# define __int64 long long
59# endif
60#endif
61
62#if !defined(HAVE_MODE_T) && !defined(_MODE_T)
63typedef int mode_t;
64#endif
65#if !defined(HAVE_OFF_T) && !defined(_OFF_T)
66typedef long off_t;
67#endif
68#if !defined(HAVE_PID_T) && !defined(_PID_T)
69typedef int pid_t;
70#endif
71#if !defined(HAVE_SIZE_T) && !defined(_SIZE_T)
72typedef unsigned int size_t;
73#endif
74#if !defined(HAVE_SSIZE_T) && !defined(_SSIZE_T)
75typedef int ssize_t;
76#endif
77//#ifndef HAVE_SOCKLEN_T
78//typedef unsigned int socklen_t;
79//#endif
80
81#ifndef HAVE_STATFS
82# ifdef __BEOS__
83# define HAVE_STRUCT_STATFS_F_BFREE
84struct statfs {
85 long f_bsize; /* block_size */
86 long f_blocks; /* total_blocks */
87 long f_bfree; /* free_blocks */
88};
89# else /* defined(__BEOS__) */
90struct statfs;
91# endif /* defined(__BEOS__) */
92#endif /* !defined(HAVE_STATFS) */
93
94
95/****************************************************************
96 * Macro definitions
97 */
98
99#ifdef HAVE_DLFCN_H
100#include <dlfcn.h>
101#else
102#define RTLD_LAZY 0x001
103#define RTLD_NOW 0x002
104#define RTLD_GLOBAL 0x100
105#endif
106
107#if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
108#define ftruncate chsize
109#endif
110
111#if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
112#define popen _popen
113#endif
114
115#if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
116#define pclose _pclose
117#endif
118
119#if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
120#define snprintf _snprintf
121#endif
122
123#if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
124#define vsnprintf _vsnprintf
125#endif
126
127#ifndef S_ISLNK
128# define S_ISLNK(mod) (0)
129#endif /* S_ISLNK */
130
131/* So we open files in 64 bit access mode on Linux */
132#ifndef O_LARGEFILE
133# define O_LARGEFILE 0
134#endif
135
136#ifndef O_BINARY
137# define O_BINARY 0
138#endif
139
140/****************************************************************
141 * Constants
142 */
143
144#ifndef M_PI
145#define M_PI 3.14159265358979323846
146#endif
147
148#ifndef M_PI_2
149#define M_PI_2 1.570796326794896619
150#endif
151
152#ifndef M_PI_4
153#define M_PI_4 0.785398163397448309616
154#endif
155
156#ifndef INFINITY
157static inline float __port_infinity(void)
158{
159 static const unsigned __inf_bytes = 0x7f800000;
160 return *(const float *)&__inf_bytes;
161}
162#define INFINITY __port_infinity()
163#endif
164
165#ifndef NAN
166static inline float __port_nan(void)
167{
168 static const unsigned __nan_bytes = 0x7fc00000;
169 return *(const float *)&__nan_bytes;
170}
171#define NAN __port_nan()
172#endif
173
174/* Constructor functions */
175
176#ifdef _MSC_VER
177# define DECL_GLOBAL_CONSTRUCTOR(func) /* nothing */
178#elif defined(__GNUC__)
179# define DECL_GLOBAL_CONSTRUCTOR(func) \
180 static void func(void) __attribute__((constructor)); \
181 static void func(void)
182#elif defined(__i386__)
183# define DECL_GLOBAL_CONSTRUCTOR(func) \
184 static void __dummy_init_##func(void) { \
185 asm(".section .init,\"ax\"\n\t" \
186 "call " #func "\n\t" \
187 ".previous"); } \
188 static void func(void)
189#elif defined(__sparc__)
190# define DECL_GLOBAL_CONSTRUCTOR(func) \
191 static void __dummy_init_##func(void) { \
192 asm("\t.section \".init\",#alloc,#execinstr\n" \
193 "\tcall " #func "\n" \
194 "\tnop\n" \
195 "\t.section \".text\",#alloc,#execinstr\n" ); } \
196 static void func(void)
197#elif defined(_M_AMD64)
198#pragma message("You must define the DECL_GLOBAL_CONSTRUCTOR macro for amd64")
199#else
200# error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform
201#endif
202
203
204/* Register functions */
205
206#ifdef __i386__
207#define DEFINE_REGS_ENTRYPOINT( name, fn, args, pop_args ) \
208 __ASM_GLOBAL_FUNC( name, \
209 "call " __ASM_NAME("__wine_call_from_32_regs") "\n\t" \
210 ".long " __ASM_NAME(#fn) "\n\t" \
211 ".byte " #args "," #pop_args )
212/* FIXME: add support for other CPUs */
213#endif /* __i386__ */
214
215
216/****************************************************************
217 * Function definitions (only when using libwine_port)
218 */
219
220#ifndef NO_LIBWINE_PORT
221
222#ifndef HAVE_GETOPT_LONG
223extern char *optarg;
224extern int optind;
225extern int opterr;
226extern int optopt;
227struct option;
228
229#ifndef HAVE_STRUCT_OPTION_NAME
230struct option
231{
232 const char *name;
233 int has_arg;
234 int *flag;
235 int val;
236};
237#endif
238
239extern int getopt_long (int ___argc, char *const *___argv,
240 const char *__shortopts,
241 const struct option *__longopts, int *__longind);
242extern int getopt_long_only (int ___argc, char *const *___argv,
243 const char *__shortopts,
244 const struct option *__longopts, int *__longind);
245#endif /* HAVE_GETOPT_LONG */
246
247#ifndef HAVE_GETPAGESIZE
248size_t getpagesize(void);
249#endif /* HAVE_GETPAGESIZE */
250
251#if !defined(HAVE_ISFINITE) && !defined(isfinite)
252int isfinite(double x);
253#endif
254
255#if !defined(HAVE_ISINF) && !defined(isinf)
256int isinf(double x);
257#endif
258
259#if !defined(HAVE_ISNAN) && !defined(isnan)
260int isnan(double x);
261#endif
262
263#ifndef HAVE_LSTAT
264int lstat(const char *file_name, struct stat *buf);
265#endif /* HAVE_LSTAT */
266
267#ifndef HAVE_MEMMOVE
268void *memmove(void *dest, const void *src, size_t len);
269#endif /* !defined(HAVE_MEMMOVE) */
270
271#ifndef __REACTOS__
272#ifndef HAVE_PREAD
273ssize_t pread( int fd, void *buf, size_t count, off_t offset );
274#endif /* HAVE_PREAD */
275
276#ifndef HAVE_PWRITE
277ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
278#endif /* HAVE_PWRITE */
279#endif /* __REACTOS__ */
280
281#ifdef _WIN32
282#ifndef HAVE_SIGSETJMP
283# include <setjmp.h>
284typedef jmp_buf sigjmp_buf;
285int sigsetjmp( sigjmp_buf buf, int savesigs );
286void siglongjmp( sigjmp_buf buf, int val );
287#endif /* HAVE_SIGSETJMP */
288#endif
289
290#ifndef HAVE_STATFS
291int statfs(const char *name, struct statfs *info);
292#endif /* !defined(HAVE_STATFS) */
293
294#ifndef HAVE_STRNCASECMP
295# ifndef HAVE__STRNICMP
296int strncasecmp(const char *str1, const char *str2, size_t n);
297# else
298# define strncasecmp _strnicmp
299# endif
300#endif /* !defined(HAVE_STRNCASECMP) */
301
302#ifndef HAVE_STRERROR
303const char *strerror(int err);
304#endif /* !defined(HAVE_STRERROR) */
305
306#ifndef HAVE_STRCASECMP
307# ifndef HAVE__STRICMP
308int strcasecmp(const char *str1, const char *str2);
309# else
310# define strcasecmp _stricmp
311# endif
312#endif /* !defined(HAVE_STRCASECMP) */
313
314#if !defined(HAVE_USLEEP) && !defined(__CYGWIN__)
315int usleep (unsigned int useconds);
316#endif /* !defined(HAVE_USLEEP) */
317
318#ifdef __i386__
319static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
320{
321 return memcpy( dst, src, size );
322}
323#else
324extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
325#endif /* __i386__ */
326
327extern int mkstemps(char *template, int suffix_len);
328
329/* Process creation flags */
330#ifndef _P_WAIT
331# define _P_WAIT 0
332# define _P_NOWAIT 1
333# define _P_OVERLAY 2
334# define _P_NOWAITO 3
335# define _P_DETACH 4
336#endif
337#ifndef HAVE_SPAWNVP
338extern int spawnvp(int mode, const char *cmdname, const char * const argv[]);
339#endif
340
341/* Interlocked functions */
342
343#define interlocked_cmpxchg InterlockedCompareExchange
344#define interlocked_cmpxchg_ptr InterlockedCompareExchangePointer
345#define interlocked_xchg InterlockedExchange
346#define interlocked_xchg_ptr InterlockedExchangePointer
347#define interlocked_xchg_add InterlockedExchangeAdd
348
349#if defined(_MSC_VER) && !defined(__clang__)
350__forceinline
351int
352ffs(int mask)
353{
354 long index;
355 if (_BitScanForward(&index, mask) == 0) return 0;
356 return index;
357}
358#else
359#define ffs __builtin_ffs
360#endif
361
362#else /* NO_LIBWINE_PORT */
363
364#define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
365
366#define getopt_long __WINE_NOT_PORTABLE(getopt_long)
367#define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only)
368#define getpagesize __WINE_NOT_PORTABLE(getpagesize)
369#define lstat __WINE_NOT_PORTABLE(lstat)
370#define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned)
371#define memmove __WINE_NOT_PORTABLE(memmove)
372#define pread __WINE_NOT_PORTABLE(pread)
373#define pwrite __WINE_NOT_PORTABLE(pwrite)
374#define spawnvp __WINE_NOT_PORTABLE(spawnvp)
375#define statfs __WINE_NOT_PORTABLE(statfs)
376#define strcasecmp __WINE_NOT_PORTABLE(strcasecmp)
377#define strerror __WINE_NOT_PORTABLE(strerror)
378#define strncasecmp __WINE_NOT_PORTABLE(strncasecmp)
379#define usleep __WINE_NOT_PORTABLE(usleep)
380
381#endif /* NO_LIBWINE_PORT */
382
383#endif /* !defined(__WINE_WINE_PORT_H) */
#define index(s, c)
Definition: various.h:29
_JBTYPE jmp_buf[_JBLEN]
Definition: setjmp.h:186
__kernel_off_t off_t
Definition: linux.h:201
#define strncasecmp
Definition: fake.h:10
#define strcasecmp
Definition: fake.h:9
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLdouble n
Definition: glext.h:7729
GLenum src
Definition: glext.h:6340
GLuint index
Definition: glext.h:6031
GLenum GLint GLuint mask
Definition: glext.h:6028
GLenum mode
Definition: glext.h:6217
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLenum dst
Definition: glext.h:6340
GLuint GLfloat * val
Definition: glext.h:7180
GLenum GLsizei len
Definition: glext.h:6722
GLintptr offset
Definition: glext.h:5920
unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask)
Definition: intrin_arm.h:57
#define lstat
Definition: syshdrs.h:49
#define isfinite(x)
Definition: mingw_math.h:91
#define isinf(x)
Definition: mingw_math.h:94
#define isnan(x)
Definition: mingw_math.h:133
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
static char * dest
Definition: rtl.c:135
static LPCWSTR file_name
Definition: protocol.c:147
int pid_t
Definition: port.h:59
int usleep(unsigned int useconds)
int optopt
Definition: getopt.c:48
int sigsetjmp(sigjmp_buf buf, int savesigs)
int mkstemps(char *template, int suffix_len)
Definition: mkstemps.c:73
ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset)
ssize_t pread(int fd, void *buf, size_t count, off_t offset)
const char * strerror(int err)
Definition: compat_str.c:23
unsigned int size_t
Definition: port.h:62
int mode_t
Definition: port.h:53
int getopt_long(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind)
Definition: getopt.c:283
void siglongjmp(sigjmp_buf buf, int val)
size_t getpagesize(void)
int spawnvp(int mode, const char *cmdname, const char *const argv[])
jmp_buf sigjmp_buf
Definition: port.h:324
int optind
Definition: getopt.c:47
char * optarg
Definition: getopt.c:49
void * memcpy_unaligned(void *dst, const void *src, size_t size)
int opterr
Definition: getopt.c:46
int ssize_t
Definition: port.h:65
int getopt_long_only(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind)
long off_t
Definition: port.h:56
#define argv
Definition: mplay32.c:18
#define err(...)
int ssize_t
Definition: rosdhcp.h:48
int statfs(const char *name, struct statfs *info)
static float __port_infinity(void)
Definition: port.h:157
#define ffs
Definition: port.h:359
static float __port_nan(void)
Definition: port.h:166
static int fd
Definition: io.c:51
Definition: name.c:39
Definition: getopt.h:109
int val
Definition: getopt.h:115
int * flag
Definition: getopt.h:114
int has_arg
Definition: getopt.h:113
WCHAR * name
Definition: getopt.h:110
Definition: stat.h:55