137 lines
4.4 KiB
C
137 lines
4.4 KiB
C
#ifndef HOST_CONFIG_H__
|
|
#define HOST_CONFIG_H__
|
|
|
|
#cmakedefine01 BLADERF_OS_LINUX
|
|
#cmakedefine01 BLADERF_OS_OSX
|
|
#cmakedefine01 BLADERF_OS_WINDOWS
|
|
|
|
#if !(BLADERF_OS_LINUX || BLADERF_OS_OSX || BLADERF_OS_WINDOWS)
|
|
# error "Build not configured for any supported operating systems"
|
|
#endif
|
|
|
|
#if 1 < (BLADERF_OS_LINUX + BLADERF_OS_OSX + BLADERF_OS_WINDOWS)
|
|
#error "Build configured for multiple operating systems"
|
|
#endif
|
|
|
|
|
|
/*******************************************************************************
|
|
* Endianness conversions
|
|
*
|
|
* HOST_TO_LE16 16-bit host endianness to little endian conversion
|
|
* LE16_TO_HOST 16-bit little endian to host endianness conversion
|
|
* HOST_TO_BE16 16-bit host endianness to big endian conversion
|
|
* BE16_TO_HOST 16-bit big endian to host endianness conversion
|
|
* HOST_TO_LE32 32-bit host endianness to little endian conversion
|
|
* LE32_TO_HOST 32-bit little endian to host endianness conversion
|
|
******************************************************************************/
|
|
|
|
/*-----------------------
|
|
* Linux
|
|
*---------------------*/
|
|
#if BLADERF_OS_LINUX
|
|
#include <endian.h>
|
|
|
|
#define HOST_TO_LE16(val) htole16(val)
|
|
#define LE16_TO_HOST(val) le16toh(val)
|
|
#define HOST_TO_BE16(val) htobe16(val)
|
|
#define BE16_TO_HOST(val) be16toh(val)
|
|
#define HOST_TO_LE32(val) htole32(val)
|
|
#define LE32_TO_HOST(val) le32toh(val)
|
|
|
|
/*-----------------------
|
|
* Apple OSX
|
|
*---------------------*/
|
|
#elif BLADERF_OS_OSX
|
|
#include <libkern/OSByteOrder.h>
|
|
|
|
#define HOST_TO_LE16(val) OSSwapHostToLittleInt16(val)
|
|
#define LE16_TO_HOST(val) OSSwapLittleToHostInt16(val)
|
|
#define HOST_TO_BE16(val) OSSwapHostToBigInt16(val)
|
|
#define BE16_TO_HOST(val) OSSwapBigToHostInt16(val)
|
|
#define HOST_TO_LE32(val) OSSwapHostToLittleInt32(val)
|
|
#define LE32_TO_HOST(val) OSSwapLittleToHostInt32(val)
|
|
|
|
/*-----------------------
|
|
* Windows
|
|
*---------------------*/
|
|
#elif BLADERF_OS_WINDOWS
|
|
#include <intrin.h>
|
|
|
|
/* We'll assume little endian for Windows platforms:
|
|
* http://blogs.msdn.com/b/larryosterman/archive/2005/06/07/426334.aspx
|
|
*/
|
|
#define HOST_TO_LE16(val) (val)
|
|
#define LE16_TO_HOST(val) (val)
|
|
#define HOST_TO_BE16(val) _byteswap_ushort(val)
|
|
#define BE16_TO_HOST(val) _byteswap_ushort(val)
|
|
#define HOST_TO_LE32(val) (val)
|
|
#define LE32_TO_HOST(val) (val)
|
|
|
|
/*-----------------------
|
|
* Unsupported or bug
|
|
*---------------------*/
|
|
#else
|
|
#error "Encountered an OS that we do not have endian wrappers for?"
|
|
#endif
|
|
|
|
/*******************************************************************************
|
|
* Miscellaneous Linux fixups
|
|
******************************************************************************/
|
|
#if BLADERF_OS_LINUX
|
|
|
|
/* Added here just to keep this out of the other source files. We'll have
|
|
* a few Windows replacements for unistd.h items. */
|
|
#include <unistd.h>
|
|
|
|
/*******************************************************************************
|
|
* Miscellaneous OSX fixups
|
|
******************************************************************************/
|
|
#elif BLADERF_OS_OSX
|
|
|
|
#include <unistd.h>
|
|
|
|
/*******************************************************************************
|
|
* Miscellaneous Windows fixups
|
|
******************************************************************************/
|
|
#elif BLADERF_OS_WINDOWS
|
|
|
|
/* Rename a few functions and types */
|
|
#include <Windows.h>
|
|
#define strtok_r strtok_s
|
|
#define strtoull _strtoui64
|
|
#define snprintf _snprintf
|
|
#define vsnprintf _vsnprintf
|
|
#define strcasecmp _stricmp
|
|
#define strncasecmp _strnicmp
|
|
#define fileno _fileno
|
|
#define strdup _strdup
|
|
#define usleep(x) Sleep((x)/1000)
|
|
|
|
/* ssize_t lives elsewhere */
|
|
#include <BaseTsd.h>
|
|
#define ssize_t SSIZE_T
|
|
|
|
/* With msvc, inline is only available for C++. Otherwise we need to use __inline:
|
|
* http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx */
|
|
#define inline __inline
|
|
|
|
#endif
|
|
|
|
/* Windows (msvc) does not support C99 designated initializers.
|
|
*
|
|
* Therefore, the following macro should be used. However, note that you'll
|
|
* need to be sure to keep your elements in order to avoid breaking Windows
|
|
* portability!
|
|
*
|
|
* http://stackoverflow.com/questions/5440611/how-to-rewrite-c-struct-designated-initializers-to-c89-resp-msvc-c-compiler
|
|
*
|
|
* Here's a sample regexep you could use in vim to clean these up in your code:
|
|
* @\(\s\+\)\(\.[a-zA-Z0-9_]\+\)\s*=\s*\([a-zA-Z0-9_]\+\)\(,\)\?@\1FIELD_INIT(\2,\3)\4@gc
|
|
*/
|
|
#if BLADERF_OS_WINDOWS
|
|
# define FIELD_INIT(field, ...) __VA_ARGS__
|
|
#else
|
|
# define FIELD_INIT(field, ...) field = __VA_ARGS__
|
|
#endif
|
|
|
|
#endif
|