Reactos
at master 384 lines 9.9 kB view raw
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 94struct stat; 95 96/**************************************************************** 97 * Macro definitions 98 */ 99 100#ifdef HAVE_DLFCN_H 101#include <dlfcn.h> 102#else 103#define RTLD_LAZY 0x001 104#define RTLD_NOW 0x002 105#define RTLD_GLOBAL 0x100 106#endif 107 108#if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE) 109#define ftruncate chsize 110#endif 111 112#if !defined(HAVE_POPEN) && defined(HAVE__POPEN) 113#define popen _popen 114#endif 115 116#if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE) 117#define pclose _pclose 118#endif 119 120#if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF) 121#define snprintf _snprintf 122#endif 123 124#if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF) 125#define vsnprintf _vsnprintf 126#endif 127 128#ifndef S_ISLNK 129# define S_ISLNK(mod) (0) 130#endif /* S_ISLNK */ 131 132/* So we open files in 64 bit access mode on Linux */ 133#ifndef O_LARGEFILE 134# define O_LARGEFILE 0 135#endif 136 137#ifndef O_BINARY 138# define O_BINARY 0 139#endif 140 141/**************************************************************** 142 * Constants 143 */ 144 145#ifndef M_PI 146#define M_PI 3.14159265358979323846 147#endif 148 149#ifndef M_PI_2 150#define M_PI_2 1.570796326794896619 151#endif 152 153#ifndef M_PI_4 154#define M_PI_4 0.785398163397448309616 155#endif 156 157#ifndef INFINITY 158static inline float __port_infinity(void) 159{ 160 static const unsigned __inf_bytes = 0x7f800000; 161 return *(const float *)&__inf_bytes; 162} 163#define INFINITY __port_infinity() 164#endif 165 166#ifndef NAN 167static inline float __port_nan(void) 168{ 169 static const unsigned __nan_bytes = 0x7fc00000; 170 return *(const float *)&__nan_bytes; 171} 172#define NAN __port_nan() 173#endif 174 175/* Constructor functions */ 176 177#ifdef _MSC_VER 178# define DECL_GLOBAL_CONSTRUCTOR(func) /* nothing */ 179#elif defined(__GNUC__) 180# define DECL_GLOBAL_CONSTRUCTOR(func) \ 181 static void func(void) __attribute__((constructor)); \ 182 static void func(void) 183#elif defined(__i386__) 184# define DECL_GLOBAL_CONSTRUCTOR(func) \ 185 static void __dummy_init_##func(void) { \ 186 asm(".section .init,\"ax\"\n\t" \ 187 "call " #func "\n\t" \ 188 ".previous"); } \ 189 static void func(void) 190#elif defined(__sparc__) 191# define DECL_GLOBAL_CONSTRUCTOR(func) \ 192 static void __dummy_init_##func(void) { \ 193 asm("\t.section \".init\",#alloc,#execinstr\n" \ 194 "\tcall " #func "\n" \ 195 "\tnop\n" \ 196 "\t.section \".text\",#alloc,#execinstr\n" ); } \ 197 static void func(void) 198#elif defined(_M_AMD64) 199#pragma message("You must define the DECL_GLOBAL_CONSTRUCTOR macro for amd64") 200#else 201# error You must define the DECL_GLOBAL_CONSTRUCTOR macro for your platform 202#endif 203 204 205/* Register functions */ 206 207#ifdef __i386__ 208#define DEFINE_REGS_ENTRYPOINT( name, fn, args, pop_args ) \ 209 __ASM_GLOBAL_FUNC( name, \ 210 "call " __ASM_NAME("__wine_call_from_32_regs") "\n\t" \ 211 ".long " __ASM_NAME(#fn) "\n\t" \ 212 ".byte " #args "," #pop_args ) 213/* FIXME: add support for other CPUs */ 214#endif /* __i386__ */ 215 216 217/**************************************************************** 218 * Function definitions (only when using libwine_port) 219 */ 220 221#ifndef NO_LIBWINE_PORT 222 223#ifndef HAVE_GETOPT_LONG 224extern char *optarg; 225extern int optind; 226extern int opterr; 227extern int optopt; 228struct option; 229 230#ifndef HAVE_STRUCT_OPTION_NAME 231struct option 232{ 233 const char *name; 234 int has_arg; 235 int *flag; 236 int val; 237}; 238#endif 239 240extern int getopt_long (int ___argc, char *const *___argv, 241 const char *__shortopts, 242 const struct option *__longopts, int *__longind); 243extern int getopt_long_only (int ___argc, char *const *___argv, 244 const char *__shortopts, 245 const struct option *__longopts, int *__longind); 246#endif /* HAVE_GETOPT_LONG */ 247 248#ifndef HAVE_GETPAGESIZE 249size_t getpagesize(void); 250#endif /* HAVE_GETPAGESIZE */ 251 252#if !defined(HAVE_ISFINITE) && !defined(isfinite) 253int isfinite(double x); 254#endif 255 256#if !defined(HAVE_ISINF) && !defined(isinf) 257int isinf(double x); 258#endif 259 260#if !defined(HAVE_ISNAN) && !defined(isnan) 261int isnan(double x); 262#endif 263 264#ifndef HAVE_LSTAT 265int lstat(const char *file_name, struct stat *buf); 266#endif /* HAVE_LSTAT */ 267 268#ifndef HAVE_MEMMOVE 269void *memmove(void *dest, const void *src, size_t len); 270#endif /* !defined(HAVE_MEMMOVE) */ 271 272#ifndef __REACTOS__ 273#ifndef HAVE_PREAD 274ssize_t pread( int fd, void *buf, size_t count, off_t offset ); 275#endif /* HAVE_PREAD */ 276 277#ifndef HAVE_PWRITE 278ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset ); 279#endif /* HAVE_PWRITE */ 280#endif /* __REACTOS__ */ 281 282#ifdef _WIN32 283#ifndef HAVE_SIGSETJMP 284# include <setjmp.h> 285typedef jmp_buf sigjmp_buf; 286int sigsetjmp( sigjmp_buf buf, int savesigs ); 287void siglongjmp( sigjmp_buf buf, int val ); 288#endif /* HAVE_SIGSETJMP */ 289#endif 290 291#ifndef HAVE_STATFS 292int statfs(const char *name, struct statfs *info); 293#endif /* !defined(HAVE_STATFS) */ 294 295#ifndef HAVE_STRNCASECMP 296# ifndef HAVE__STRNICMP 297int strncasecmp(const char *str1, const char *str2, size_t n); 298# else 299# define strncasecmp _strnicmp 300# endif 301#endif /* !defined(HAVE_STRNCASECMP) */ 302 303#ifndef HAVE_STRERROR 304const char *strerror(int err); 305#endif /* !defined(HAVE_STRERROR) */ 306 307#ifndef HAVE_STRCASECMP 308# ifndef HAVE__STRICMP 309int strcasecmp(const char *str1, const char *str2); 310# else 311# define strcasecmp _stricmp 312# endif 313#endif /* !defined(HAVE_STRCASECMP) */ 314 315#if !defined(HAVE_USLEEP) && !defined(__CYGWIN__) 316int usleep (unsigned int useconds); 317#endif /* !defined(HAVE_USLEEP) */ 318 319#ifdef __i386__ 320static inline void *memcpy_unaligned( void *dst, const void *src, size_t size ) 321{ 322 return memcpy( dst, src, size ); 323} 324#else 325extern void *memcpy_unaligned( void *dst, const void *src, size_t size ); 326#endif /* __i386__ */ 327 328extern int mkstemps(char *template, int suffix_len); 329 330/* Process creation flags */ 331#ifndef _P_WAIT 332# define _P_WAIT 0 333# define _P_NOWAIT 1 334# define _P_OVERLAY 2 335# define _P_NOWAITO 3 336# define _P_DETACH 4 337#endif 338#ifndef HAVE_SPAWNVP 339extern int spawnvp(int mode, const char *cmdname, const char * const argv[]); 340#endif 341 342/* Interlocked functions */ 343 344#define interlocked_cmpxchg InterlockedCompareExchange 345#define interlocked_cmpxchg_ptr InterlockedCompareExchangePointer 346#define interlocked_xchg InterlockedExchange 347#define interlocked_xchg_ptr InterlockedExchangePointer 348#define interlocked_xchg_add InterlockedExchangeAdd 349 350#if defined(_MSC_VER) && !defined(__clang__) 351__forceinline 352int 353ffs(int mask) 354{ 355 long index; 356 if (_BitScanForward(&index, mask) == 0) return 0; 357 return index + 1; 358} 359#else 360#define ffs __builtin_ffs 361#endif 362 363#else /* NO_LIBWINE_PORT */ 364 365#define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable 366 367#define getopt_long __WINE_NOT_PORTABLE(getopt_long) 368#define getopt_long_only __WINE_NOT_PORTABLE(getopt_long_only) 369#define getpagesize __WINE_NOT_PORTABLE(getpagesize) 370#define lstat __WINE_NOT_PORTABLE(lstat) 371#define memcpy_unaligned __WINE_NOT_PORTABLE(memcpy_unaligned) 372#define memmove __WINE_NOT_PORTABLE(memmove) 373#define pread __WINE_NOT_PORTABLE(pread) 374#define pwrite __WINE_NOT_PORTABLE(pwrite) 375#define spawnvp __WINE_NOT_PORTABLE(spawnvp) 376#define statfs __WINE_NOT_PORTABLE(statfs) 377#define strcasecmp __WINE_NOT_PORTABLE(strcasecmp) 378#define strerror __WINE_NOT_PORTABLE(strerror) 379#define strncasecmp __WINE_NOT_PORTABLE(strncasecmp) 380#define usleep __WINE_NOT_PORTABLE(usleep) 381 382#endif /* NO_LIBWINE_PORT */ 383 384#endif /* !defined(__WINE_WINE_PORT_H) */