Skip to content

Commit

Permalink
Minor coding conventions on defines
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane committed May 20, 2016
1 parent cb4d3ea commit 7ef3fa5
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/modbus-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
*/

#include <stdlib.h>

#ifndef _MSC_VER
#include <stdint.h>
# include <stdint.h>
#else
#include "stdint.h"
# include "stdint.h"
#endif

#include <string.h>
#include <assert.h>

#if defined(_WIN32)
# include <winsock2.h>
# include <winsock2.h>
#else
# include <arpa/inet.h>
# include <arpa/inet.h>
#endif

#include <config.h>
Expand All @@ -28,10 +30,10 @@
#endif

#if defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#define bswap_16 OSSwapInt16
#define bswap_32 OSSwapInt32
#define bswap_64 OSSwapInt64
# include <libkern/OSByteOrder.h>
# define bswap_16 OSSwapInt16
# define bswap_32 OSSwapInt32
# define bswap_64 OSSwapInt64
#endif

#if defined(__GNUC__)
Expand All @@ -42,14 +44,15 @@
# define bswap_32 __builtin_bswap32
# endif
#endif

#if defined(_MSC_VER) && (_MSC_VER >= 1400)
# define bswap_32 _byteswap_ulong
# define bswap_16 _byteswap_ushort
# define bswap_32 _byteswap_ulong
# define bswap_16 _byteswap_ushort
#endif

#if !defined(__CYGWIN__)
#if !defined(bswap_16)
# warning "Fallback on C functions for bswap_16"
# warning "Fallback on C functions for bswap_16"
static inline uint16_t bswap_16(uint16_t x)
{
return (x >> 8) | (x << 8);
Expand All @@ -58,7 +61,7 @@ static inline uint16_t bswap_16(uint16_t x)
#endif

#if !defined(bswap_32)
# warning "Fallback on C functions for bswap_32"
# warning "Fallback on C functions for bswap_32"
static inline uint32_t bswap_32(uint32_t x)
{
return (bswap_16(x & 0xffff) << 16) | (bswap_16(x >> 16));
Expand Down

0 comments on commit 7ef3fa5

Please sign in to comment.