|
152 | 152 | #elif BLADERF_OS_WINDOWS |
153 | 153 |
|
154 | 154 | /* Rename a few functions and types */ |
155 | | -#include <Windows.h> |
156 | | -#define strtok_r strtok_s |
157 | | -#define strtoull _strtoui64 |
158 | | -#define snprintf _snprintf |
159 | | -#define vsnprintf _vsnprintf |
160 | | -#define strcasecmp _stricmp |
161 | | -#define strncasecmp _strnicmp |
162 | | -#define fileno _fileno |
163 | | -#define strdup _strdup |
| 155 | +#include <windows.h> |
164 | 156 | #define usleep(x) Sleep((x+999)/1000) |
165 | 157 |
|
| 158 | +/* Changes specific to Microsoft Visual Studio and its C89-compliant ways */ |
| 159 | +#if _MSC_VER |
| 160 | +# define strtok_r strtok_s |
| 161 | +# define strtoull _strtoui64 |
| 162 | +# define snprintf _snprintf |
| 163 | +# define vsnprintf _vsnprintf |
| 164 | +# define strcasecmp _stricmp |
| 165 | +# define strncasecmp _strnicmp |
| 166 | +# define fileno _fileno |
| 167 | +# define strdup _strdup |
| 168 | + |
166 | 169 | /* ssize_t lives elsewhere */ |
167 | | -#include <BaseTsd.h> |
168 | | -#define ssize_t SSIZE_T |
| 170 | +# include <BaseTsd.h> |
| 171 | +# define ssize_t SSIZE_T |
169 | 172 |
|
170 | 173 | /* With msvc, inline is only available for C++. Otherwise we need to use __inline: |
171 | 174 | * http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx */ |
172 | | -#define inline __inline |
| 175 | +# define inline __inline |
| 176 | +#endif // _MSC_VER |
173 | 177 |
|
174 | 178 | #endif |
175 | 179 |
|
|
184 | 188 | * Here's a sample regexep you could use in vim to clean these up in your code: |
185 | 189 | * @\(\s\+\)\(\.[a-zA-Z0-9_]\+\)\s*=\s*\([a-zA-Z0-9_]\+\)\(,\)\?@\1FIELD_INIT(\2,\3)\4@gc |
186 | 190 | */ |
187 | | -#if BLADERF_OS_WINDOWS |
| 191 | +#if _MSC_VER |
188 | 192 | # define FIELD_INIT(field, ...) __VA_ARGS__ |
189 | 193 | #else |
190 | 194 | # define FIELD_INIT(field, ...) field = __VA_ARGS__ |
191 | | -#endif |
| 195 | +#endif // _MSC_VER |
| 196 | + |
| 197 | +/* MSVC doesn't have inttypes.h. We'll use a local version for this environment. */ |
| 198 | +#if _MSC_VER |
| 199 | +# include <inttypes_msvc.h> |
| 200 | +#else |
| 201 | +# include <inttypes.h> |
| 202 | +#endif // _MSC_VER |
192 | 203 |
|
193 | 204 | #endif |
0 commit comments