Re: [PATCH 07/19] compat: add endianness helpers
- From
Thomas Rast <tr@thomasrast.ch>
- Date
- Oct 26, 2013, 07:55 UTC
- Message-ID
- <87txg4sbyf.fsf@linux-k42r.v.cablecom.net>
- In-Reply-To
- <20131024180157.GG24180@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
> From: Vicent Marti <tanoku@gmail.com> > > The POSIX standard doesn't currently define a `nothll`/`htonll`
typo: ntohll
> function pair to perform network-to-host and host-to-network > swaps of 64-bit data. These 64-bit swaps are necessary for the on-disk > storage of EWAH bitmaps if they are not in native byte order.
[...]
> +# include <byteswap.h>
Do we need a hack on top similar to what ntoh_l and hton_l do, for platforms that do not support unaligned access?
---- read-cache.c:1316 ----
#ifndef NEEDS_ALIGNED_ACCESS
#define ntoh_s(var) ntohs(var)
#define ntoh_l(var) ntohl(var)
#else
static inline uint16_t ntoh_s_force_align(void *p)
{
uint16_t x;
memcpy(&x, p, sizeof(x));
return ntohs(x);
}
static inline uint32_t ntoh_l_force_align(void *p)
{
uint32_t x;
memcpy(&x, p, sizeof(x));
return ntohl(x);
}
#define ntoh_s(var) ntoh_s_force_align(&(var))
#define ntoh_l(var) ntoh_l_force_align(&(var))
#endif-- Thomas Rast tr@thomasrast.ch