Torc  0.1
torccompat.h
Go to the documentation of this file.
1 #ifndef TORCCOMPAT_H
2 #define TORCCOMPAT_H
3 
4 #ifdef _MSC_VER
5 #undef USING_MINGW
6 #include <time.h>
7 #endif
8 
9 #ifdef _WIN32
10 # ifndef _MSC_VER
11 # define close wsock_close
12 # endif
13 
14 #ifndef NOMINMAX
15 #define NOMINMAX
16 #endif
17 
18 #ifndef _MSC_VER
19 # include <winsock2.h>
20 # include <ws2tcpip.h>
21 #else
22 # include <io.h>
23 # endif
24 
25 #include <windows.h>
26 # undef DialogBox
27 # undef LoadImage
28 # undef LoadIcon
29 # undef GetObject
30 # undef DrawText
31 # undef CreateDialog
32 # undef CreateFont
33 # undef DeleteFile
34 # undef GetCurrentTime
35 # undef SetJob
36 # undef SendMessage
37 
38 # define setsockopt(a, b, c, d, e) setsockopt(a, b, c, (const char*)(d), e)
39 # undef close
40 # include <stdio.h> // for snprintf(), used by inline dlerror()
41 //# include <unistd.h> // for usleep()
42 #else
43 # include <sys/time.h> // Mac OS X needs this before sys/resource
44 # include <sys/resource.h> // for setpriority
45 # include <sys/socket.h>
46 # include <sys/wait.h> // For WIFEXITED on Mac OS X
47 #endif
48 
49 #ifdef _MSC_VER
50  // Turn off the visual studio warnings (identifier was truncated)
51  #pragma warning(disable:4786)
52 
53  #ifdef restrict
54  #undef restrict
55  #endif
56 
57  typedef int pid_t;
58  typedef int tid;
59  #include <stdint.h>
60  #include <direct.h>
61  #include <process.h>
62 
63  #define strtoll _strtoi64
64  #define strncasecmp _strnicmp
65  #define snprintf _snprintf
66 
67  #ifdef _WIN64
68  typedef __int64 ssize_t;
69  #else
70  typedef int ssize_t;
71  #endif
72 
73  // Check for execute, only checking existance in MSVC
74  #define X_OK 0
75 
76  #define rint( x ) floor(x + 0.5)
77  #define round( x ) floor(x + 0.5)
78  #define getpid() _getpid()
79  #define ftruncate( fd, fsize ) _chsize( fd, fsize )
80 
81  #ifndef S_ISCHR
82  # ifdef S_IFCHR
83  # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
84  # else
85  # define S_ISCHR(m) 0
86  # endif
87  #endif /* !S_ISCHR */
88 
89  #ifndef S_ISBLK
90  # define S_ISBLK(m) 0
91  #endif
92 
93  #ifndef S_ISREG
94  # define S_ISREG(m) 1
95  #endif
96 
97  #ifndef S_ISDIR
98  # ifdef S_IFDIR
99  # define S_ISDIR(m) (((m) & S_IFDIR) == S_IFDIR )
100  # else
101  # define S_ISDIR(m) 0
102  # endif
103  #endif
104 #endif
105 
106 #ifdef _WIN32
107 typedef unsigned int uint;
108 # undef M_PI
109 # define M_PI 3.14159265358979323846
110 #endif
111 
112 #ifdef USING_MINGW
113 #include <unistd.h> // for usleep()
114 #include <stdlib.h> // for rand()
115 #include <time.h>
116 #include <sys/time.h>
117 #define SIGHUP 1
118 #define SIGQUIT 3
119 #define SIGKILL 9
120 #define SIGUSR1 10 // used to force UPnP mediamap rebuild in the backend
121 #define SIGUSR2 12 // used to restart LIRC as required
122 #define SIGPIPE 13 // not implemented in MINGW, will produce "unable to ignore sigpipe"
123 #define SIGALRM 14
124 #define SIGCONT 18
125 #define SIGSTOP 19
126 #define O_SYNC 0
127 #define getuid() 0
128 #define geteuid() 0
129 #define setuid(x)
130 #endif // USING_MINGW
131 
132 #if defined(_MSC_VER) && !defined(localtime_r)
133 static inline struct tm* localtime_r(const time_t *timep, struct tm *result)
134 {
135  localtime_s(result, timep);
136  return result;
137 }
138 #endif
139 
140 #ifndef _MSC_VER
141 #include <sys/param.h> // Defines BSD on FreeBSD, Mac OS X
142 #endif
143 #include <sys/stat.h> // S_IREAD/WRITE on MinGW, umask() on BSD
144 
145 // suseconds_t
146 #include <sys/types.h>
147 
148 #if defined(Q_OS_MAC)
149 #include <sys/types.h>
150 #include <unistd.h>
151 typedef off_t off64_t;
152 #endif
153 
154 #if defined(_MSC_VER)
155 # define S_IRUSR _S_IREAD
156 # ifndef lseek64
157 # define lseek64( f, o, w ) _lseeki64( f, o, w )
158 # endif
159 #endif
160 
161 #ifdef _WIN32
162 #define PREFIX64 "I64"
163 #else
164 #define PREFIX64 "ll"
165 #endif
166 
167 #endif // TORCCOMPAT_H