libplist win编译相关

4 篇文章 0 订阅
bplist.c 

#ifndef _MSC_VER
#define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__))
#else
#define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
#endif

2.get_unaligned的win适配


#ifdef _MSC_VER
uint64_t get_unaligned_64(uint64_t *ptr)
{
	uint64_t temp;
	memcpy(&temp, ptr, sizeof(temp));
	return temp;
}

uint32_t get_unaligned_32(uint32_t *ptr)
{
	uint32_t temp;
	memcpy(&temp, ptr, sizeof(temp));
	return temp;
}

uint16_t get_unaligned_16(uint16_t *ptr)
{
	uint16_t temp;
	memcpy(&temp, ptr, sizeof(temp));
	return temp;
}
#else
#define get_unaligned(ptr)			  \
  ({                                              \
    struct __attribute__((packed)) {		  \
      typeof(*(ptr)) __v;			  \
    } *__p = (void *) (ptr);			  \
    __p->__v;					  \
  })
#endif

3.UINT_TO_HOST的vs适配

#ifdef _MSC_VER
uint64_t UINT_TO_HOST(void* x, uint8_t n)
{
	union plist_uint_ptr __up;
	// Adding to void* is a GCC extension, see http://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html
	__up.src = (n > 8) ? (char *)x + (n - 8) : x;
	return (n >= 8 ? be64toh(get_unaligned_64(__up.u64ptr)) :
		(n == 4 ? be32toh(get_unaligned_32(__up.u32ptr)) :
		(n == 2 ? be16toh(get_unaligned_16(__up.u16ptr)) :
			(n == 1 ? *__up.u8ptr :
				beNtoh(get_unaligned_64(__up.u64ptr), n)
				))));
}
#else
#define UINT_TO_HOST(x, n) \
	({ \
		union plist_uint_ptr __up; \
		__up.src = (n > 8) ? x + (n - 8) : x; \
		(n >= 8 ? be64toh( get_unaligned(__up.u64ptr) ) : \
		(n == 4 ? be32toh( get_unaligned(__up.u32ptr) ) : \
		(n == 2 ? be16toh( get_unaligned(__up.u16ptr) ) : \
                (n == 1 ? *__up.u8ptr : \
		beNtoh( get_unaligned(__up.u64ptr), n) \
		)))); \
	})
#endif

4.plist.h的接口声明

#ifdef _MSC_VER 
#define PLIST_API_MSC __declspec( dllexport ) 
#else  
#define PLIST_API_MSC 
#endif 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值