~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/include/wine/port.h

Version: ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  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 #ifdef __WINE_BASETSD_H
 29 # error You must include port.h before all other headers
 30 #endif
 31 
 32 #define _GNU_SOURCE  /* for pread/pwrite */
 33 #include <fcntl.h>
 34 #include <math.h>
 35 #include <sys/types.h>
 36 #include <sys/stat.h>
 37 #ifdef HAVE_DIRECT_H
 38 # include <direct.h>
 39 #endif
 40 #ifdef HAVE_IO_H
 41 # include <io.h>
 42 #endif
 43 #ifdef HAVE_PROCESS_H
 44 # include <process.h>
 45 #endif
 46 #include <string.h>
 47 #ifdef HAVE_UNISTD_H
 48 # include <unistd.h>
 49 #endif
 50 
 51 
 52 /****************************************************************
 53  * Type definitions
 54  */
 55 
 56 #if !defined(_MSC_VER) && !defined(__int64)
 57 #  if defined(__x86_64__) || defined(_WIN64)
 58 #    define __int64 long
 59 #  else
 60 #    define __int64 long long
 61 #  endif
 62 #endif
 63 
 64 #ifndef HAVE_MODE_T
 65 typedef int mode_t;
 66 #endif
 67 #ifndef HAVE_OFF_T
 68 typedef long off_t;
 69 #endif
 70 #ifndef HAVE_PID_T
 71 typedef int pid_t;
 72 #endif
 73 #ifndef HAVE_SIZE_T
 74 typedef unsigned int size_t;
 75 #endif
 76 #ifndef HAVE_SSIZE_T
 77 typedef int ssize_t;
 78 #endif
 79 #ifndef HAVE_FSBLKCNT_T
 80 typedef unsigned long fsblkcnt_t;
 81 #endif
 82 #ifndef HAVE_FSFILCNT_T
 83 typedef unsigned long fsfilcnt_t;
 84 #endif
 85 
 86 #ifndef HAVE_STRUCT_STATVFS_F_BLOCKS
 87 struct statvfs
 88 {
 89     unsigned long f_bsize;
 90     unsigned long f_frsize;
 91     fsblkcnt_t    f_blocks;
 92     fsblkcnt_t    f_bfree;
 93     fsblkcnt_t    f_bavail;
 94     fsfilcnt_t    f_files;
 95     fsfilcnt_t    f_ffree;
 96     fsfilcnt_t    f_favail;
 97     unsigned long f_fsid;
 98     unsigned long f_flag;
 99     unsigned long f_namemax;
100 };
101 #endif /* HAVE_STRUCT_STATVFS_F_BLOCKS */
102 
103 
104 /****************************************************************
105  * Macro definitions
106  */
107 
108 #ifdef HAVE_DLFCN_H
109 #include <dlfcn.h>
110 #else
111 #define RTLD_LAZY    0x001
112 #define RTLD_NOW     0x002
113 #define RTLD_GLOBAL  0x100
114 #endif
115 
116 #ifdef HAVE_ONE_ARG_MKDIR
117 #define mkdir(path,mode) mkdir(path)
118 #endif
119 
120 #if !defined(HAVE_FTRUNCATE) && defined(HAVE_CHSIZE)
121 #define ftruncate chsize
122 #endif
123 
124 #if !defined(HAVE_POPEN) && defined(HAVE__POPEN)
125 #define popen _popen
126 #endif
127 
128 #if !defined(HAVE_PCLOSE) && defined(HAVE__PCLOSE)
129 #define pclose _pclose
130 #endif
131 
132 #if !defined(HAVE_STRDUP) && defined(HAVE__STRDUP)
133 #define strdup _strdup
134 #endif
135 
136 #if !defined(HAVE_SNPRINTF) && defined(HAVE__SNPRINTF)
137 #define snprintf _snprintf
138 #endif
139 
140 #if !defined(HAVE_VSNPRINTF) && defined(HAVE__VSNPRINTF)
141 #define vsnprintf _vsnprintf
142 #endif
143 
144 #if !defined(HAVE_STRTOLL) && defined(HAVE__STRTOI64)
145 #define strtoll _strtoi64
146 #endif
147 
148 #if !defined(HAVE_STRTOULL) && defined(HAVE__STRTOUI64)
149 #define strtoull _strtoui64
150 #endif
151 
152 #ifndef S_ISLNK
153 # define S_ISLNK(mod) (0)
154 #endif
155 
156 #ifndef S_ISSOCK
157 # define S_ISSOCK(mod) (0)
158 #endif
159 
160 #ifndef S_ISDIR
161 # define S_ISDIR(mod) (((mod) & _S_IFMT) == _S_IFDIR)
162 #endif
163 
164 #ifndef S_ISCHR
165 # define S_ISCHR(mod) (((mod) & _S_IFMT) == _S_IFCHR)
166 #endif
167 
168 #ifndef S_ISFIFO
169 # define S_ISFIFO(mod) (((mod) & _S_IFMT) == _S_IFIFO)
170 #endif
171 
172 #ifndef S_ISREG
173 # define S_ISREG(mod) (((mod) & _S_IFMT) == _S_IFREG)
174 #endif
175 
176 /* So we open files in 64 bit access mode on Linux */
177 #ifndef O_LARGEFILE
178 # define O_LARGEFILE 0
179 #endif
180 
181 #ifndef O_NONBLOCK
182 # define O_NONBLOCK 0
183 #endif
184 
185 #ifndef O_BINARY
186 # define O_BINARY 0
187 #endif
188 
189 
190 /****************************************************************
191  * Constants
192  */
193 
194 #ifndef M_PI
195 #define M_PI 3.14159265358979323846
196 #endif
197 
198 #ifndef M_PI_2
199 #define M_PI_2 1.570796326794896619
200 #endif
201 
202 
203 /****************************************************************
204  * Function definitions (only when using libwine_port)
205  */
206 
207 #ifndef NO_LIBWINE_PORT
208 
209 #ifndef HAVE_FSTATVFS
210 int fstatvfs( int fd, struct statvfs *buf );
211 #endif
212 
213 #ifndef HAVE_GETOPT_LONG
214 extern char *optarg;
215 extern int optind;
216 extern int opterr;
217 extern int optopt;
218 struct option;
219 
220 #ifndef HAVE_STRUCT_OPTION_NAME
221 struct option
222 {
223     const char *name;
224     int has_arg;
225     int *flag;
226     int val;
227 };
228 #endif
229 
230 extern int getopt_long (int ___argc, char *const *___argv,
231                         const char *__shortopts,
232                         const struct option *__longopts, int *__longind);
233 extern int getopt_long_only (int ___argc, char *const *___argv,
234                              const char *__shortopts,
235                              const struct option *__longopts, int *__longind);
236 #endif  /* HAVE_GETOPT_LONG */
237 
238 #ifndef HAVE_FFS
239 int ffs( int x );
240 #endif
241 
242 #ifndef HAVE_FUTIMES
243 struct timeval;
244 int futimes(int fd, const struct timeval *tv);
245 #endif
246 
247 #ifndef HAVE_GETPAGESIZE
248 size_t getpagesize(void);
249 #endif  /* HAVE_GETPAGESIZE */
250 
251 #ifndef HAVE_GETTID
252 pid_t gettid(void);
253 #endif /* HAVE_GETTID */
254 
255 #ifndef HAVE_ISINF
256 int isinf(double x);
257 #endif
258 
259 #ifndef HAVE_ISNAN
260 int isnan(double x);
261 #endif
262 
263 #ifndef HAVE_LSTAT
264 int lstat(const char *file_name, struct stat *buf);
265 #endif /* HAVE_LSTAT */
266 
267 #ifndef HAVE_MEMMOVE
268 void *memmove(void *dest, const void *src, size_t len);
269 #endif /* !defined(HAVE_MEMMOVE) */
270 
271 #ifndef HAVE_POLL
272 struct pollfd
273 {
274     int fd;
275     short events;
276     short revents;
277 };
278 #define POLLIN   0x01
279 #define POLLPRI  0x02
280 #define POLLOUT  0x04
281 #define POLLERR  0x08
282 #define POLLHUP  0x10
283 #define POLLNVAL 0x20
284 int poll( struct pollfd *fds, unsigned int count, int timeout );
285 #endif /* HAVE_POLL */
286 
287 #ifndef HAVE_PREAD
288 ssize_t pread( int fd, void *buf, size_t count, off_t offset );
289 #endif /* HAVE_PREAD */
290 
291 #ifndef HAVE_PWRITE
292 ssize_t pwrite( int fd, const void *buf, size_t count, off_t offset );
293 #endif /* HAVE_PWRITE */
294 
295 #ifndef HAVE_READLINK
296 int readlink( const char *path, char *buf, size_t size );
297 #endif /* HAVE_READLINK */
298 
299 #ifndef HAVE_STATVFS
300 int statvfs( const char *path, struct statvfs *buf );
301 #endif
302 
303 #ifndef HAVE_STRNCASECMP
304 # ifndef HAVE__STRNICMP
305 int strncasecmp(const char *str1, const char *str2, size_t n);
306 # else
307 # define strncasecmp _strnicmp
308 # endif
309 #endif /* !defined(HAVE_STRNCASECMP) */
310 
311 #ifndef HAVE_STRERROR
312 const char *strerror(int err);
313 #endif /* !defined(HAVE_STRERROR) */
314 
315 #ifndef HAVE_STRCASECMP
316 # ifndef HAVE__STRICMP
317 int strcasecmp(const char *str1, const char *str2);
318 # else
319 # define strcasecmp _stricmp
320 # endif
321 #endif /* !defined(HAVE_STRCASECMP) */
322 
323 #ifndef HAVE_SYMLINK
324 int symlink(const char *from, const char *to);
325 #endif
326 
327 #ifndef HAVE_USLEEP
328 int usleep (unsigned int useconds);
329 #endif /* !defined(HAVE_USLEEP) */
330 
331 #ifdef __i386__
332 static inline void *memcpy_unaligned( void *dst, const void *src, size_t size )
333 {
334     return memcpy( dst, src, size );
335 }
336 #else
337 extern void *memcpy_unaligned( void *dst, const void *src, size_t size );
338 #endif /* __i386__ */
339 
340 extern int mkstemps(char *template, int suffix_len);
341 
342 /* Process creation flags */
343 #ifndef _P_WAIT
344 # define _P_WAIT    0
345 # define _P_NOWAIT  1
346 # define _P_OVERLAY 2
347 # define _P_NOWAITO 3
348 # define _P_DETACH  4
349 #endif
350 #ifndef HAVE_SPAWNVP
351 extern int spawnvp(int mode, const char *cmdname, const char * const argv[]);
352 #endif
353 
354 /* Interlocked functions */
355 
356 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
357 
358 extern inline int interlocked_cmpxchg( int *dest, int xchg, int compare );
359 extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
360 extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
361 extern inline int interlocked_xchg( int *dest, int val );
362 extern inline void *interlocked_xchg_ptr( void **dest, void *val );
363 extern inline int interlocked_xchg_add( int *dest, int incr );
364 
365 extern inline int interlocked_cmpxchg( int *dest, int xchg, int compare )
366 {
367     int ret;
368     __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
369                           : "=a" (ret) : "r" (dest), "r" (xchg), "" (compare) : "memory" );
370     return ret;
371 }
372 
373 extern inline void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare )
374 {
375     void *ret;
376 #ifdef __x86_64__
377     __asm__ __volatile__( "lock; cmpxchgq %2,(%1)"
378                           : "=a" (ret) : "r" (dest), "r" (xchg), "" (compare) : "memory" );
379 #else
380     __asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
381                           : "=a" (ret) : "r" (dest), "r" (xchg), "" (compare) : "memory" );
382 #endif
383     return ret;
384 }
385 
386 extern inline int interlocked_xchg( int *dest, int val )
387 {
388     int ret;
389     __asm__ __volatile__( "lock; xchgl %0,(%1)"
390                           : "=r" (ret) : "r" (dest), "" (val) : "memory" );
391     return ret;
392 }
393 
394 extern inline void *interlocked_xchg_ptr( void **dest, void *val )
395 {
396     void *ret;
397 #ifdef __x86_64__
398     __asm__ __volatile__( "lock; xchgq %0,(%1)"
399                           : "=r" (ret) :"r" (dest), "" (val) : "memory" );
400 #else
401     __asm__ __volatile__( "lock; xchgl %0,(%1)"
402                           : "=r" (ret) : "r" (dest), "" (val) : "memory" );
403 #endif
404     return ret;
405 }
406 
407 extern inline int interlocked_xchg_add( int *dest, int incr )
408 {
409     int ret;
410     __asm__ __volatile__( "lock; xaddl %0,(%1)"
411                           : "=r" (ret) : "r" (dest), "" (incr) : "memory" );
412     return ret;
413 }
414 
415 #ifdef __x86_64__
416 extern inline unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
417                                                     __int64 xchg_low, __int64 *compare );
418 extern inline unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
419                                                     __int64 xchg_low, __int64 *compare )
420 {
421     unsigned char ret;
422     __asm__ __volatile__( "lock cmpxchg16b %0; setz %b2"
423                           : "=m" (dest[0]), "=m" (dest[1]), "=r" (ret),
424                             "=a" (compare[0]), "=d" (compare[1])
425                           : "m" (dest[0]), "m" (dest[1]), "3" (compare[0]), "4" (compare[1]),
426                             "c" (xchg_high), "b" (xchg_low) );
427     return ret;
428 }
429 #endif
430 
431 #else  /* __GNUC__ */
432 
433 extern int interlocked_cmpxchg( int *dest, int xchg, int compare );
434 extern void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare );
435 extern __int64 interlocked_cmpxchg64( __int64 *dest, __int64 xchg, __int64 compare );
436 extern int interlocked_xchg( int *dest, int val );
437 extern void *interlocked_xchg_ptr( void **dest, void *val );
438 extern int interlocked_xchg_add( int *dest, int incr );
439 #ifdef _WIN64
440 extern unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
441                                              __int64 xchg_low, __int64 *compare );
442 #endif
443 
444 #endif  /* __GNUC__ */
445 
446 #else /* NO_LIBWINE_PORT */
447 
448 #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable
449 
450 #define ffs                     __WINE_NOT_PORTABLE(ffs)
451 #define fstatvfs                __WINE_NOT_PORTABLE(fstatvfs)
452 #define futimes                 __WINE_NOT_PORTABLE(futimes)
453 #define getopt_long             __WINE_NOT_PORTABLE(getopt_long)
454 #define getopt_long_only        __WINE_NOT_PORTABLE(getopt_long_only)
455 #define getpagesize             __WINE_NOT_PORTABLE(getpagesize)
456 #define interlocked_cmpxchg     __WINE_NOT_PORTABLE(interlocked_cmpxchg)
457 #define interlocked_cmpxchg_ptr __WINE_NOT_PORTABLE(interlocked_cmpxchg_ptr)
458 #define interlocked_xchg        __WINE_NOT_PORTABLE(interlocked_xchg)
459 #define interlocked_xchg_ptr    __WINE_NOT_PORTABLE(interlocked_xchg_ptr)
460 #define interlocked_xchg_add    __WINE_NOT_PORTABLE(interlocked_xchg_add)
461 #define lstat                   __WINE_NOT_PORTABLE(lstat)
462 #define memcpy_unaligned        __WINE_NOT_PORTABLE(memcpy_unaligned)
463 #undef memmove
464 #define memmove                 __WINE_NOT_PORTABLE(memmove)
465 #define pread                   __WINE_NOT_PORTABLE(pread)
466 #define pwrite                  __WINE_NOT_PORTABLE(pwrite)
467 #define spawnvp                 __WINE_NOT_PORTABLE(spawnvp)
468 #define statvfs                 __WINE_NOT_PORTABLE(statvfs)
469 #define strcasecmp              __WINE_NOT_PORTABLE(strcasecmp)
470 #define strerror                __WINE_NOT_PORTABLE(strerror)
471 #define strncasecmp             __WINE_NOT_PORTABLE(strncasecmp)
472 #define usleep                  __WINE_NOT_PORTABLE(usleep)
473 
474 #endif /* NO_LIBWINE_PORT */
475 
476 #endif /* !defined(__WINE_WINE_PORT_H) */
477 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.