Blame src/internal/perk_impl.h

c0fbae
#ifndef PERK_IMPL_H
c0fbae
#define PERK_IMPL_H
c0fbae
c0fbae
#include <stdint.h>
c0fbae
#include <endian.h>
c0fbae
c0fbae
#if (BYTE_ORDER == LITTLE_ENDIAN)
c0fbae
c0fbae
static inline uint16_t pe_read_short(const unsigned char * raw)
c0fbae
{
c0fbae
	return *(uint16_t *)raw;
c0fbae
}
c0fbae
c0fbae
static inline uint32_t pe_read_long(const unsigned char * raw)
c0fbae
{
c0fbae
	return *(uint32_t *)raw;
c0fbae
}
c0fbae
c0fbae
static inline uint64_t pe_read_quad(const unsigned char * raw)
c0fbae
{
c0fbae
	return *(uint64_t *)raw;
c0fbae
}
c0fbae
c0fbae
#else
c0fbae
b5f7f5
static inline uint16_t pe_read_short(const unsigned char * raw)
c0fbae
{
c0fbae
	uint16_t x = *(uint16_t *)raw;
c0fbae
	return x<<8 | x>>8;
c0fbae
}
c0fbae
c0fbae
static inline uint32_t pe_swap_long(uint32_t x)
c0fbae
{
c0fbae
	return x<<24 | (x<<8) & 0xff0000 | (x>>8) & 0xff00 | x>>24;
c0fbae
}
c0fbae
b5f7f5
static inline uint32_t pe_read_long(const unsigned char * raw)
c0fbae
{
c0fbae
	return pe_swap_long(*(uint32_t *)raw);
c0fbae
}
c0fbae
b5f7f5
static inline uint64_t pe_read_quad(const unsigned char * raw)
c0fbae
{
c0fbae
	uint64_t x = *(uint64_t *)raw;
c0fbae
	return ((uint64_t)pe_swap_long(x)<<32) | pe_swap_long(x>>32);
c0fbae
}
c0fbae
c0fbae
#endif
c0fbae
c0fbae
#endif