16 # define close wsock_close 33 # undef GetCurrentTime 38 # include <winsock2.h> 39 # include <ws2tcpip.h> 46 # include <sys/time.h> 47 # include <sys/resource.h> 48 # include <sys/socket.h> 49 # include <sys/wait.h> 55 # include <sys/time.h> 56 # include <sys/types.h> 61 #pragma warning(disable:4786) 71 #define strtoll _strtoi64 72 #define strncasecmp _strnicmp 73 #define snprintf _snprintf 76 typedef __int64 ssize_t;
85 #define rint( x ) floor(x + 0.5) 86 #define round( x ) floor(x + 0.5) 88 #if ( _MSC_VER < 1700) 89 #define signbit( x ) ( x < 0 ) 93 #define M_PI 3.14159265358979323846 96 #define getpid() _getpid() 97 #define ftruncate( fd, fsize ) _chsize( fd, fsize ) 101 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) 103 # define S_ISCHR(m) 0 108 # define S_ISBLK(m) 0 112 # define S_ISREG(m) 1 117 # define S_ISDIR(m) (((m) & S_IFDIR) == S_IFDIR ) 119 # define S_ISDIR(m) 0 123 typedef uint32_t mode_t;
125 #if !defined(__cplusplus) && !defined( inline ) 126 # define inline __inline 129 #if !defined(__func__) // C99 & C++11 130 # define __func__ __FUNCTION__ 143 #if defined(__cplusplus) && defined(_WIN32) 146 static inline void srandom(
unsigned int seed) { qsrand(seed); }
147 static inline long int random(
void) {
return qrand(); }
149 # define setenv(x, y, z) ::SetEnvironmentVariableA(x, y) 150 # define unsetenv(x) 0 152 inline unsigned sleep(
unsigned int x)
172 DWORD spc = 0, bps = 0, fc = 0, c = 0;
174 if (buffer && GetDiskFreeSpaceA(path, &spc, &bps, &fc, &c))
188 #define nice(x) ((int)!::SetPriorityClass(\ 189 ::GetCurrentProcess(), ((x) < -10) ? \ 190 HIGH_PRIORITY_CLASS : (((x) < 0) ? \ 191 ABOVE_NORMAL_PRIORITY_CLASS : (((x) > 10) ? \ 192 IDLE_PRIORITY_CLASS : (((x) > 0) ? \ 193 BELOW_NORMAL_PRIORITY_CLASS : \ 194 NORMAL_PRIORITY_CLASS))))) 195 #define PRIO_PROCESS 0 196 #define setpriority(x, y, z) ((x) == PRIO_PROCESS && y == 0 ? nice(z) : -1) 200 # define SIGTRAP SIGBREAK 201 # define STDERR_FILENO (int)GetStdHandle( STD_ERROR_HANDLE ) 209 # define SIGUSR1 10 // used to force UPnP mediamap rebuild in the backend 210 # define SIGUSR2 12 // used to restart LIRC as required 211 # define SIGPIPE 13 // not implemented in MINGW, will produce "unable to ignore sigpipe" 220 #define mkfifo(path, mode) \ 221 (int)CreateNamedPipeA(path, PIPE_ACCESS_DUPLEX | WRITE_DAC, \ 222 PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, \ 223 1024, 1024, 10000, nullptr) 226 # define dlopen(x, y) LoadLibraryA((x)) 227 # define dlclose(x) !FreeLibrary((HMODULE)(x)) 228 # define dlsym(x, y) GetProcAddress((HMODULE)(x), (y)) 233 #define DLERR_MAX 512 235 DWORD errCode = GetLastError();
237 if (!FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
238 FORMAT_MESSAGE_IGNORE_INSERTS |
239 FORMAT_MESSAGE_MAX_WIDTH_MASK,
241 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
244 "dlopen()/dlsym() caused error %d", (
int)errCode);
248 # else // __cplusplus 249 # define dlerror() "dlerror() is unimplemented." 250 # endif // __cplusplus 256 # define seteuid(x) 0 259 #if defined(_WIN32) && !defined(gmtime_r) 262 static __inline
struct tm *
gmtime_r(
const time_t *timep,
struct tm *result)
266 struct tm *
tmp = gmtime(timep);
276 #if defined(_WIN32) && !defined(localtime_r) 279 static __inline
struct tm *
localtime_r(
const time_t *timep,
struct tm *result)
284 struct tm *win_tmp = localtime(timep);
285 memcpy(result, win_tmp,
sizeof(
struct tm));
293 # define timeradd(a, b, result) \ 295 (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ 296 (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ 297 if ((result)->tv_usec >= 1000000) \ 299 ++(result)->tv_sec; \ 300 (result)->tv_usec -= 1000000; \ 303 # define timersub(a, b, result) \ 305 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 306 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 307 if ((result)->tv_usec < 0) { \ 308 --(result)->tv_sec; \ 309 (result)->tv_usec += 1000000; \ 314 # define daemon(x, y) -1 315 # define getloadavg(x, y) -1 318 # define WIFEXITED(w) (((w) & 0xff) == 0) 319 # define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f)) 320 # define WIFSTOPPED(w) (((w) & 0xff) == 0x7f) 321 # define WEXITSTATUS(w) (((w) >> 8) & 0xff) 322 # define WTERMSIG(w) ((w) & 0x7f) 328 #include <sys/param.h> 332 #if CONFIG_DARWIN && ! defined (_SUSECONDS_T) 339 typedef off_t off64_t;
340 #define lseek64(f,o,w) lseek(f,o,w) 343 #if defined(_MSC_VER) 344 #include <sys/stat.h> 345 # define S_IRUSR _S_IREAD 347 # define lseek64( f, o, w ) _lseeki64( f, o, w ) 352 # define fseeko(stream, offset, whence) fseeko64(stream, offset, whence) 353 # define ftello(stream) ftello64(stream) 356 #if defined(USING_MINGW) && defined(FILENAME_MAX) 361 static inline int readdir_r(
362 DIR *dirp,
struct dirent *entry,
struct dirent **result)
365 struct dirent *
tmp = readdir(dirp);
368 int offset = offsetof(
struct dirent, d_name);
369 memcpy(entry,
tmp, offset);
370 strncpy(entry->d_name,
tmp->d_name, FILENAME_MAX);
371 tmp->d_name[strlen(entry->d_name)] =
'\0';
386 # define PREFIX64 "I64" 388 # define PREFIX64 "ll" 393 #define S_IREAD S_IRUSR 396 #define S_IWRITE S_IRUSR 401 # ifdef LZO_COMPILE_TIME_ASSERT_HEADER 402 # undef LZO_COMPILE_TIME_ASSERT_HEADER 405 # define LZO_COMPILE_TIME_ASSERT_HEADER( a ) 407 # ifdef LZO_COMPILE_TIME_ASSERT 408 # undef LZO_COMPILE_TIME_ASSERT 411 # define LZO_COMPILE_TIME_ASSERT( a ) 414 #endif // __COMPAT_H__ static __inline struct tm * gmtime_r(const time_t *timep, struct tm *result)
static void srandom(unsigned int seed)
const char * dlerror(void)
static __inline struct tm * localtime_r(const time_t *timep, struct tm *result)
unsigned sleep(unsigned int x)
int statfs(const char *path, struct statfs *buffer)
static long int random(void)