scoutfs-utils: add get_unaligned helpers

Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
Zach Brown
2020-06-23 12:41:47 -07:00
committed by Zach Brown
parent 35d1ad1422
commit c0fdd37e5a

View File

@@ -6,6 +6,8 @@
#include <string.h>
#include <math.h>
#include "sparse.h"
/*
* Generate build warnings if the condition is false but generate no
* code at run time if it's true.
@@ -85,6 +87,17 @@ do { \
((unsigned long)log2l((long double)x)); \
})
#define emit_get_unaligned_le(nr) \
static inline __u##nr get_unaligned_le##nr(void *buf) \
{ \
__le##nr x; \
memcpy(&x, buf, sizeof(x)); \
return le##nr##_to_cpu(x); \
}
emit_get_unaligned_le(16)
emit_get_unaligned_le(32)
emit_get_unaligned_le(64)
/*
* return -1,0,+1 based on the memcmp comparison of the minimum of their
* two lengths. If their min shared bytes are equal but the lengths