Ticket #13869: 0002-libs-bsd-add-be64dec-3-and-be64enc-3.patch

File 0002-libs-bsd-add-be64dec-3-and-be64enc-3.patch, 1.6 KB (added by leorize, 6 years ago)
  • headers/compatibility/bsd/endian.h

    From 4d2b3561fc2b94fd9506b68a760365839c849a70 Mon Sep 17 00:00:00 2001
    From: Leorize <alaviss@users.noreply.github.com>
    Date: Thu, 14 Dec 2017 07:22:34 +0700
    Subject: [PATCH 2/5] libs/bsd: add be64dec(3) and be64enc(3)
    
    ---
     headers/compatibility/bsd/endian.h | 39 ++++++++++++++++++++++++++++++++++++++
     1 file changed, 39 insertions(+)
    
    diff --git a/headers/compatibility/bsd/endian.h b/headers/compatibility/bsd/endian.h
    index 07f564a1..44381ced 100644
    a b  
    1313
    1414#include <config/HaikuConfig.h>
    1515#include <support/ByteOrder.h>
     16#include <support/SupportDefs.h>
    1617
    1718#ifdef __cplusplus
    1819extern "C" {
    extern "C" {  
    5960#define le64toh(x)  bswap64((x))
    6061#endif /* BYTE_ORDER == LITTLE_ENDIAN */
    6162
     63/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */
     64
     65static __inline uint32_t
     66be32dec(const void *pp)
     67{
     68    uint8_t const *p = (uint8_t const *)pp;
     69
     70    return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
     71}
     72
     73static __inline uint64_t
     74be64dec(const void *pp)
     75{
     76    uint8_t const *p = (uint8_t const *)pp;
     77
     78    return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4));
     79}
     80
     81static __inline void
     82be32enc(void *pp, uint32_t u)
     83{
     84    uint8_t *p = (uint8_t *)pp;
     85
     86    p[0] = (u >> 24) & 0xff;
     87    p[1] = (u >> 16) & 0xff;
     88    p[2] = (u >> 8) & 0xff;
     89    p[3] = u & 0xff;
     90}
     91
     92static __inline void
     93be64enc(void *pp, uint64_t u)
     94{
     95    uint8_t *p = (uint8_t *)pp;
     96
     97    be32enc(p, (uint32_t)(u >> 32));
     98    be32enc(p + 4, (uint32_t)(u & 0xffffffffU));
     99}
     100
    62101#ifdef __cplusplus
    63102}
    64103#endif