12 #include <sys/param.h>
14 #include "mythconfig.h"
19 typedef off_t off64_t;
20 # define lseek64(f,o,w) lseek(f,o,w)
25 # define S_IREAD S_IRUSR
28 # define S_IWRITE S_IRUSR
32 #if defined(USING_MINGW)
37 # include <sys/time.h>
38 # include <sys/resource.h>
39 # include <sys/socket.h>
40 # include <sys/wait.h>
43 # define close wsock_close
60 # undef GetCurrentTime
65 # include <winsock2.h>
66 # include <ws2tcpip.h>
78 #if defined(__cplusplus)
81 typedef unsigned int uint;
85 # if defined(__cplusplus)
87 # define setenv(x, y, z) ::SetEnvironmentVariableA(x, y)
88 # define unsetenv(x) 0
105 DWORD spc = 0, bps = 0, fc = 0, c = 0;
107 if (buffer && GetDiskFreeSpaceA(path, &spc, &bps, &fc, &c))
120 #define nice(x) ((int)!::SetPriorityClass(\
121 ::GetCurrentProcess(), ((x) < -10) ? \
122 HIGH_PRIORITY_CLASS : (((x) < 0) ? \
123 ABOVE_NORMAL_PRIORITY_CLASS : (((x) > 10) ? \
124 IDLE_PRIORITY_CLASS : (((x) > 0) ? \
125 BELOW_NORMAL_PRIORITY_CLASS : \
126 NORMAL_PRIORITY_CLASS)))))
127 #define PRIO_PROCESS 0
128 #define setpriority(x, y, z) ((x) == PRIO_PROCESS && y == 0 ? nice(z) : -1)
135 # define SIGUSR1 10 // used to force UPnP mediamap rebuild in the backend
136 # define SIGUSR2 12 // used to restart LIRC as required
137 # define SIGPIPE 13 // not implemented in MINGW, will produce "unable to ignore sigpipe"
144 #define mkfifo(path, mode) \
145 (int)CreateNamedPipeA(path, PIPE_ACCESS_DUPLEX | WRITE_DAC, \
146 PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, \
147 1024, 1024, 10000, nullptr)
150 # define dlopen(x, y) LoadLibraryA((x))
151 # define dlclose(x) !FreeLibrary((HMODULE)(x))
152 # define dlsym(x, y) GetProcAddress((HMODULE)(x), (y))
158 #define DLERR_MAX 512
160 DWORD errCode = GetLastError();
162 if (!FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
163 FORMAT_MESSAGE_IGNORE_INSERTS |
164 FORMAT_MESSAGE_MAX_WIDTH_MASK,
166 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
169 "dlopen()/dlsym() caused error %d", (
int)errCode);
173 # else // __cplusplus
175 # define dlerror() "dlerror() is unimplemented."
176 # endif // __cplusplus
182 # define seteuid(x) 0
186 # define daemon(x, y) -1
187 # define getloadavg(x, y) -1
190 # define WIFEXITED(w) (((w) & 0xff) == 0)
191 # define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
192 # define WIFSTOPPED(w) (((w) & 0xff) == 0x7f)
193 # define WEXITSTATUS(w) (((w) >> 8) & 0xff)
194 # define WTERMSIG(w) ((w) & 0x7f)
197 # ifdef LZO_COMPILE_TIME_ASSERT_HEADER
198 # undef LZO_COMPILE_TIME_ASSERT_HEADER
201 # define LZO_COMPILE_TIME_ASSERT_HEADER( a )
203 # ifdef LZO_COMPILE_TIME_ASSERT
204 # undef LZO_COMPILE_TIME_ASSERT
207 # define LZO_COMPILE_TIME_ASSERT( a )
215 #include <sys/time.h>
218 #pragma warning(disable:4786)
228 #define strtoll _strtoi64
229 #define strncasecmp _strnicmp
230 #define snprintf _snprintf
233 using ssize_t = __int64;
241 #if (_MSC_VER < 1800)
242 #define rint( x ) floor(x + 0.5)
243 #define round( x ) floor(x + 0.5)
245 #if ( _MSC_VER < 1700)
246 #define signbit( x ) ( x < 0 )
250 #define M_PI 3.14159265358979323846
253 #define getpid() _getpid()
254 #define ftruncate( fd, fsize ) _chsize( fd, fsize )
258 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
260 # define S_ISCHR(m) 0
265 # define S_ISBLK(m) 0
269 # define S_ISREG(m) 1
274 # define S_ISDIR(m) (((m) & S_IFDIR) == S_IFDIR )
276 # define S_ISDIR(m) 0
280 using mode_t = uint32_t;
282 #if !defined(__cplusplus) && !defined( inline )
283 # define inline __inline
286 #if !defined(__func__) // C99 & C++11
287 # define __func__ __FUNCTION__
290 # define SIGTRAP SIGBREAK
291 # define STDERR_FILENO (int)GetStdHandle( STD_ERROR_HANDLE )
294 # if !defined(gmtime_r)
297 static __inline
struct tm *gmtime_r(
const time_t *timep,
struct tm *result)
301 struct tm *
tmp = gmtime(timep);
311 # if !defined(localtime_r)
314 static __inline
struct tm *localtime_r(
const time_t *timep,
struct tm *result)
319 struct tm *win_tmp = localtime(timep);
320 memcpy(result, win_tmp,
sizeof(
struct tm));
327 #include <sys/stat.h>
328 # define S_IRUSR _S_IREAD
330 # define lseek64( f, o, w ) _lseeki64( f, o, w )
337 # define O_NONBLOCK 04000