00001
00002
00003
00004
00005 #ifndef __COMPAT_H__
00006 #define __COMPAT_H__
00007
00008
00009 #ifdef _MSC_VER
00010 #pragma warning(disable:4786)
00011 #endif
00012
00013 #ifdef _WIN32
00014 #define close wsock_close
00015 #include <windows.h>
00016 #include <winsock2.h>
00017 #include <ws2tcpip.h>
00018 #define setsockopt(a, b, c, d, e) setsockopt(a, b, c, (const char*)(d), e)
00019 #undef close
00020 #include <stdio.h>
00021 #else
00022 #include <sys/time.h>
00023 #include <sys/resource.h>
00024 #include <sys/socket.h>
00025 #include <sys/wait.h>
00026 #endif
00027
00028 #ifdef _WIN32
00029 typedef unsigned int uint;
00030 #endif
00031
00032 #ifdef _WIN32
00033 #undef DialogBox
00034 #undef LoadImage
00035 #undef LoadIcon
00036 #undef GetObject
00037 #undef DrawText
00038 #undef CreateFont
00039 #endif
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #if defined(__cplusplus) && defined(_WIN32) && !defined(USING_MINGW)
00050 template<class _Ty> inline
00051 const _Ty& max(const _Ty& _X, const _Ty& _Y)
00052 {return (_X < _Y ? _Y : _X); }
00053 template<class _Ty, class _Pr> inline
00054 const _Ty& max(const _Ty& _X, const _Ty& _Y, _Pr _P)
00055 {return (_P(_X, _Y) ? _Y : _X); }
00056
00057 template<class _Ty> inline
00058 const _Ty& min(const _Ty& _X, const _Ty& _Y)
00059 {return (_Y < _X ? _Y : _X); }
00060 template<class _Ty, class _Pr> inline
00061 const _Ty& min(const _Ty& _X, const _Ty& _Y, _Pr _P)
00062 {return (_P(_Y, _X) ? _Y : _X); }
00063 #endif // defined(__cplusplus) && defined(_WIN32)
00064
00065 #ifdef _WIN32
00066 #undef M_PI
00067 #define M_PI 3.14159265358979323846
00068 #endif
00069
00070 #ifdef USING_MINGW
00071 #define fsync(FD) 0
00072
00073 #define minor(X) 0
00074 #endif
00075
00076 #if defined(__cplusplus) && defined(USING_MINGW)
00077 inline int random(void)
00078 {
00079 srand(GetTickCount());
00080 return rand() << 20 ^ rand() << 10 ^ rand();
00081 }
00082 #endif // USING_MINGW
00083
00084 #if defined(__cplusplus) && defined(USING_MINGW)
00085 #define setenv(x, y, z) ::SetEnvironmentVariableA(x, y)
00086 #define unsetenv(x) 0
00087 #endif
00088
00089 #if defined(__cplusplus) && defined(USING_MINGW)
00090
00091
00092
00093
00094
00095
00096
00097 inline int usleep(unsigned int timeout)
00098 {
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 Sleep(timeout < 1000 ? 1 : (timeout + 500) / 1000);
00116 return 0;
00117 }
00118 #endif // defined(__cplusplus) && defined(USING_MINGW)
00119
00120 #if defined(__cplusplus) && defined(USING_MINGW)
00121 inline unsigned sleep(unsigned int x)
00122 {
00123 Sleep(x * 1000);
00124 return 0;
00125 }
00126 #endif // defined(__cplusplus) && defined(USING_MINGW)
00127
00128 #if defined(__cplusplus) && defined(USING_MINGW)
00129 struct statfs {
00130
00131 long f_bsize;
00132 long f_blocks;
00133
00134 long f_bavail;
00135
00136
00137
00138
00139
00140 };
00141 inline int statfs(const char* path, struct statfs* buffer)
00142 {
00143 DWORD spc = 0, bps = 0, fc = 0, c = 0;
00144
00145 if (buffer && GetDiskFreeSpaceA(path, &spc, &bps, &fc, &c))
00146 {
00147 buffer->f_bsize = bps;
00148 buffer->f_blocks = spc * c;
00149 buffer->f_bavail = spc * fc;
00150 return 0;
00151 }
00152
00153 return -1;
00154 }
00155 #endif // USING_MINGW
00156
00157 #ifdef USING_MINGW
00158 #define lstat stat
00159 #define bzero(x, y) memset((x), 0, (y))
00160 #define nice(x) ((int)!::SetThreadPriority(\
00161 ::GetCurrentThread(), ((x) < -10) ? \
00162 2 : (((x) < 0) ? \
00163 1 : (((x) > 10) ? \
00164 2 : (((x) > 0) ? 1 : 0)))))
00165 #define PRIO_PROCESS 0
00166 #define setpriority(x, y, z) ((x) == PRIO_PROCESS && y == 0 ? nice(z) : -1)
00167 #endif // USING_MINGW
00168
00169 #ifdef USING_MINGW
00170
00171 #define SIGHUP 1
00172 #define SIGQUIT 1
00173 #define SIGPIPE 3 // not implemented in MINGW, will produce "unable to ignore sigpipe"
00174 #define SIGALRM 13
00175 #define SIGUSR1 16 // used to force UPnP mediamap rebuild in the backend
00176
00177 #define S_IRGRP 0
00178 #define S_IROTH 0
00179 #define O_SYNC 0
00180 #endif // USING_MINGW
00181
00182 #ifdef USING_MINGW
00183 #define mkfifo(path, mode) \
00184 (int)CreateNamedPipeA(path, PIPE_ACCESS_DUPLEX | WRITE_DAC, \
00185 PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, \
00186 1024, 1024, 10000, NULL)
00187 #endif // USING_MINGW
00188
00189 #ifdef USING_MINGW
00190 #define RTLD_LAZY 0
00191 #define dlopen(x, y) LoadLibraryA((x))
00192 #define dlclose(x) !FreeLibrary((HMODULE)(x))
00193 #define dlsym(x, y) GetProcAddress((HMODULE)(x), (y))
00194 #ifdef __cplusplus
00195 inline const char *dlerror(void)
00196 {
00197 #define DLERR_MAX 512
00198 static char errStr[DLERR_MAX];
00199 DWORD errCode = GetLastError();
00200
00201 if (!FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
00202 FORMAT_MESSAGE_IGNORE_INSERTS |
00203 FORMAT_MESSAGE_MAX_WIDTH_MASK,
00204 NULL, errCode,
00205 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00206 errStr, DLERR_MAX - 1, NULL))
00207 snprintf(errStr, DLERR_MAX - 1,
00208 "dlopen()/dlsym() caused error %d", (int)errCode);
00209
00210 return errStr;
00211 }
00212 #else // __cplusplus
00213 #define dlerror() "dlerror() is unimplemented."
00214 #endif // __cplusplus
00215 #endif // USING_MINGW
00216
00217 #ifdef USING_MINGW
00218
00219 #define getuid() 0
00220 #define geteuid() 0
00221 #define setuid(x)
00222 #endif // USING_MINGW
00223
00224 #ifdef USING_MINGW
00225 #define timeradd(a, b, result) \
00226 do { \
00227 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
00228 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
00229 if ((result)->tv_usec >= 1000000) \
00230 { \
00231 ++(result)->tv_sec; \
00232 (result)->tv_usec -= 1000000; \
00233 } \
00234 } while (0)
00235 #define timersub(a, b, result) \
00236 do { \
00237 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
00238 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
00239 if ((result)->tv_usec < 0) { \
00240 --(result)->tv_sec; \
00241 (result)->tv_usec += 1000000; \
00242 } \
00243 } while (0)
00244 #endif // USING_MINGW
00245
00246 #ifdef USING_MINGW
00247
00248 #define daemon(x, y) -1
00249 #define getloadavg(x, y) -1
00250 #endif // USING_MINGW
00251
00252 #ifdef USING_MINGW
00253
00254 #define WIFEXITED(w) (((w) & 0xff) == 0)
00255 #define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
00256 #define WIFSTOPPED(w) (((w) & 0xff) == 0x7f)
00257 #define WEXITSTATUS(w) (((w) >> 8) & 0xff)
00258 #define WTERMSIG(w) ((w) & 0x7f)
00259 #endif // USING_MINGW
00260
00261
00262 #include <sys/param.h>
00263 #include <sys/stat.h>
00264
00265
00266
00267 #include <sys/types.h>
00268
00269 #ifdef USING_MINGW
00270 typedef long suseconds_t;
00271 #endif
00272
00273 #include "mythconfig.h"
00274 #if defined(CONFIG_DARWIN) && ! defined (_SUSECONDS_T)
00275 typedef int32_t suseconds_t;
00276 #endif
00277
00278
00279
00280 #ifdef BSD
00281 typedef off_t off64_t;
00282 #define lseek64(f,o,w) lseek(f,o,w)
00283 #endif
00284
00285 #endif // __COMPAT_H__