00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef COMPAT_H
00021 #define COMPAT_H
00022
00023
00024
00025
00026
00027 #include <locale.h>
00028 #include <libintl.h>
00029 #define _(STRING) gettext(STRING)
00030
00031 #ifdef WIN32
00032 #define WIN32_LEAN_AND_MEAN
00033 #include <winsock2.h>
00034 #include <windows.h>
00035 #include <intrin.h>
00036 #undef min
00037 #undef max
00038 #undef RGB
00039 #undef exception_info // Let's hope MS functions always use _exception_info
00040 #define snprintf _snprintf
00041 #define isnan _isnan
00042
00043
00044 typedef int pid_t;
00045
00046
00047
00048 #ifdef _MSC_VER
00049 #define ATOMIC_INT32(x) __declspec(align(4)) long x
00050 #define ATOMIC_INCREMENT(x) InterlockedIncrement(&x)
00051 #define ATOMIC_DECREMENT(x) InterlockedDecrement(&x)
00052
00053 #define TLSDATA __declspec( thread )
00054
00055
00056 #define be64toh(x) _byteswap_uint64(x)
00057
00058 #include <malloc.h>
00059 inline int aligned_malloc(void **memptr, size_t alignment, size_t size)
00060 {
00061 *memptr = _aligned_malloc(size, alignment);
00062 return (*memptr != NULL) ? 0: -1;
00063 }
00064 inline void aligned_free(void *mem)
00065 {
00066 _aligned_free(mem);
00067 }
00068
00069
00070 int round(double f);
00071 long lrint(double f);
00072
00073
00074
00075 #define PATH_MAX 260
00076 #define DATADIR "."
00077 #define GNASH_PATH "NONEXISTENT_PATH_GNASH_SUPPORT_DISABLED"
00078
00079 #else
00080 #error At the moment, only Visual C++ is supported on Windows
00081 #endif
00082
00083
00084 #else //GCC
00085 #ifndef __STDC_LIMIT_MACROS
00086 #define __STDC_LIMIT_MACROS
00087 #endif
00088
00089 #ifndef __STDC_CONSTANT_MACROS
00090 #define __STDC_CONSTANT_MACROS
00091 #endif
00092
00093 #define TLSDATA __thread
00094 #define CALLBACK
00095
00096 #include <stdatomic.h>
00097 #define ATOMIC_INT32(x) std::atomic<int32_t> x
00098 #define ATOMIC_INCREMENT(x) x.fetch_add(1)
00099 #define ATOMIC_DECREMENT(x) x.fetch_sub(1)
00100
00101 int aligned_malloc(void **memptr, size_t alignment, size_t size);
00102 void aligned_free(void *mem);
00103 #endif
00104
00105
00106 #if defined(__FreeBSD__)
00107 #include <sys/endian.h>
00108 #elif defined(__APPLE__)
00109 #define _BSD_SOURCE
00110 #include <architecture/byte_order.h>
00111 #elif !defined(WIN32)
00112 #include <endian.h>
00113 #endif
00114
00115 #if defined _WIN32 || defined __CYGWIN__
00116
00117 # define DLL_PUBLIC
00118 # define DLL_LOCAL
00119 #else
00120 #if __GNUC__ >= 4
00121 #define DLL_PUBLIC __attribute__ ((visibility("default")))
00122 #define DLL_LOCAL __attribute__ ((visibility("hidden")))
00123 #else
00124 #error GCC version less than 4
00125 #endif
00126 #endif
00127
00128 inline int imin(int a, int b)
00129 {
00130 return (a<b)?a:b;
00131 }
00132
00133 inline int imax(int a, int b)
00134 {
00135 return (a>b)?a:b;
00136 }
00137
00138 inline double dmin(double a,double b)
00139 {
00140 return (a<b)?a:b;
00141 }
00142
00143 inline double dmax(double a,double b)
00144 {
00145 return (a>b)?a:b;
00146 }
00147
00148 #include <cstdint>
00149 #include <sys/types.h>
00150 std::uint64_t compat_msectiming();
00151 void compat_msleep(unsigned int time);
00152 std::uint64_t compat_get_current_time_ms();
00153 std::uint64_t compat_get_current_time_us();
00154 std::uint64_t compat_get_thread_cputime_us();
00155
00156 int kill_child(pid_t p);
00157
00158 #endif