diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-12-13 18:49:15 -0500 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-12-13 18:49:15 -0500 |
commit | c578a300c7d0d46662fcd0bdce69af95a821bc18 (patch) | |
tree | a99de333f2812d7c018820f39d78b8c4e744f705 /lib9p/internal.h | |
parent | 6a719c63ecb83a850c317ea94b8932aa0c857770 (diff) | |
parent | 57cc0523f600575feda09bd9fae13f685ce85b0f (diff) |
Merge commit '57cc0523f600575feda09bd9fae13f685ce85b0f'
Diffstat (limited to 'lib9p/internal.h')
-rw-r--r-- | lib9p/internal.h | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/lib9p/internal.h b/lib9p/internal.h index 57f7aa7..b1a367d 100644 --- a/lib9p/internal.h +++ b/lib9p/internal.h @@ -8,7 +8,12 @@ #define _LIB9P_INTERNAL_H_ #include <stddef.h> /* for size_t */ -#include <limits.h> /* for SSIZE_MAX */ +#include <limits.h> /* for SSIZE_MAX, not set by newlib */ +#ifndef SSIZE_MAX +#define SSIZE_MAX (SIZE_MAX >> 1) +#endif + +#include <libmisc/macro.h> #include <lib9p/9p.h> @@ -36,15 +41,6 @@ static_assert(CONFIG_9P_MAX_ERR_SIZE <= UINT16_MAX); static_assert(CONFIG_9P_MAX_MSG_SIZE <= CONFIG_9P_MAX_HOSTMSG_SIZE); static_assert(CONFIG_9P_MAX_HOSTMSG_SIZE <= SSIZE_MAX); -/* C language *****************************************************************/ - -#define UNUSED(name) -#define ALWAYS_INLINE [[gnu::always_inline]] inline -#define FLATTEN [[gnu::flatten]] -#define ARRAY_LEN(arr) (sizeof(arr)/sizeof((arr)[0])) -#define CAT2(a, b) a##b -#define CAT3(a, b, c) a##b##c - /* specialized contexts *******************************************************/ struct _validate_ctx { @@ -99,22 +95,22 @@ bool _lib9p_marshal_stat(struct _marshal_ctx *ctx, struct lib9p_stat *val); /* unmarshal utilities ********************************************************/ -ALWAYS_INLINE static uint8_t decode_u8le(uint8_t *in) { +LM_ALWAYS_INLINE static uint8_t decode_u8le(uint8_t *in) { return in[0]; } -ALWAYS_INLINE static uint16_t decode_u16le(uint8_t *in) { +LM_ALWAYS_INLINE static uint16_t decode_u16le(uint8_t *in) { return (((uint16_t)(in[0])) << 0) | (((uint16_t)(in[1])) << 8) ; } -ALWAYS_INLINE static uint32_t decode_u32le(uint8_t *in) { +LM_ALWAYS_INLINE static uint32_t decode_u32le(uint8_t *in) { return (((uint32_t)(in[0])) << 0) | (((uint32_t)(in[1])) << 8) | (((uint32_t)(in[2])) << 16) | (((uint32_t)(in[3])) << 24) ; } -ALWAYS_INLINE static uint64_t decode_u64le(uint8_t *in) { +LM_ALWAYS_INLINE static uint64_t decode_u64le(uint8_t *in) { return (((uint64_t)(in[0])) << 0) | (((uint64_t)(in[1])) << 8) | (((uint64_t)(in[2])) << 16) @@ -152,20 +148,20 @@ static inline bool _is_valid_utf8(uint8_t *str, size_t len, bool forbid_nul) { /* marshal utilities **********************************************************/ -ALWAYS_INLINE static void encode_u8le(uint8_t in, uint8_t *out) { +LM_ALWAYS_INLINE static void encode_u8le(uint8_t in, uint8_t *out) { out[0] = in; } -ALWAYS_INLINE static void encode_u16le(uint16_t in, uint8_t *out) { +LM_ALWAYS_INLINE static void encode_u16le(uint16_t in, uint8_t *out) { out[0] = (uint8_t)((in >> 0) & 0xFF); out[1] = (uint8_t)((in >> 8) & 0xFF); } -ALWAYS_INLINE static void encode_u32le(uint32_t in, uint8_t *out) { +LM_ALWAYS_INLINE static void encode_u32le(uint32_t in, uint8_t *out) { out[0] = (uint8_t)((in >> 0) & 0xFF); out[1] = (uint8_t)((in >> 8) & 0xFF); out[2] = (uint8_t)((in >> 16) & 0xFF); out[3] = (uint8_t)((in >> 24) & 0xFF); } -ALWAYS_INLINE static void encode_u64le(uint64_t in, uint8_t *out) { +LM_ALWAYS_INLINE static void encode_u64le(uint64_t in, uint8_t *out) { out[0] = (uint8_t)((in >> 0) & 0xFF); out[1] = (uint8_t)((in >> 8) & 0xFF); out[2] = (uint8_t)((in >> 16) & 0xFF); |