From d959121b2f51511974e41471074db2140bb544f2 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Wed, 4 Sep 2024 13:08:29 +0200 Subject: [PATCH 1/2] [winpr,stream] add returning stream read/peek To make use easier add Stream functions that return the value read instead of taking it as argument. --- winpr/include/winpr/stream.h | 140 +++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/winpr/include/winpr/stream.h b/winpr/include/winpr/stream.h index 7a86d86ea..d895b36d7 100644 --- a/winpr/include/winpr/stream.h +++ b/winpr/include/winpr/stream.h @@ -348,6 +348,146 @@ extern "C" return v; } + static INLINE UINT8 Stream_Get_UINT8(wStream* _s) + { + return stream_read_u8(_s, TRUE); + } + + static INLINE INT8 Stream_Get_INT8(wStream* _s) + { + return stream_read_i8(_s, TRUE); + } + + static INLINE UINT16 Stream_Get_UINT16(wStream* _s) + { + return stream_read_u16_le(_s, TRUE); + } + + static INLINE INT16 Stream_Get_INT16(wStream* _s) + { + return stream_read_i16_le(_s, TRUE); + } + + static INLINE UINT16 Stream_Get_UINT16_BE(wStream* _s) + { + return stream_read_u16_be(_s, TRUE); + } + + static INLINE INT16 Stream_Get_INT16_BE(wStream* _s) + { + return stream_read_i16_be(_s, TRUE); + } + + static INLINE UINT32 Stream_Get_UINT32(wStream* _s) + { + return stream_read_u32_le(_s, TRUE); + } + + static INLINE INT32 Stream_Get_INT32(wStream* _s) + { + return stream_read_i32_le(_s, TRUE); + } + + static INLINE UINT32 Stream_Get_UINT32_BE(wStream* _s) + { + return stream_read_u32_be(_s, TRUE); + } + + static INLINE INT32 Stream_Get_INT32_BE(wStream* _s) + { + return stream_read_i32_be(_s, TRUE); + } + + static INLINE UINT64 Stream_Get_UINT64(wStream* _s) + { + return stream_read_u64_le(_s, TRUE); + } + + static INLINE INT64 Stream_Get_INT64(wStream* _s) + { + return stream_read_i64_le(_s, TRUE); + } + + static INLINE UINT64 Stream_Get_UINT64_BE(wStream* _s) + { + return stream_read_u64_be(_s, TRUE); + } + + static INLINE INT64 Stream_Get_INT64_BE(wStream* _s) + { + return stream_read_i64_be(_s, TRUE); + } + + static INLINE UINT8 Stream_Peek_Get_UINT8(wStream* _s) + { + return stream_read_u8(_s, FALSE); + } + + static INLINE INT8 Stream_Peek_Get_INT8(wStream* _s) + { + return stream_read_i8(_s, FALSE); + } + + static INLINE UINT16 Stream_Peek_Get_UINT16(wStream* _s) + { + return stream_read_u16_le(_s, FALSE); + } + + static INLINE INT16 Stream_Peek_Get_INT16(wStream* _s) + { + return stream_read_i16_le(_s, FALSE); + } + + static INLINE UINT16 Stream_Peek_Get_UINT16_BE(wStream* _s) + { + return stream_read_u16_be(_s, FALSE); + } + + static INLINE INT16 Stream_Peek_Get_INT16_BE(wStream* _s) + { + return stream_read_i16_be(_s, FALSE); + } + + static INLINE UINT32 Stream_Peek_Get_UINT32(wStream* _s) + { + return stream_read_u32_le(_s, FALSE); + } + + static INLINE INT32 Stream_Peek_Get_INT32(wStream* _s) + { + return stream_read_i32_le(_s, FALSE); + } + + static INLINE UINT32 Stream_Peek_Get_UINT32_BE(wStream* _s) + { + return stream_read_u32_be(_s, FALSE); + } + + static INLINE INT32 Stream_Peek_Get_INT32_BE(wStream* _s) + { + return stream_read_i32_be(_s, FALSE); + } + + static INLINE UINT64 Stream_Peek_Get_UINT64(wStream* _s) + { + return stream_read_u64_le(_s, FALSE); + } + + static INLINE INT64 Stream_Peek_Get_INT64(wStream* _s) + { + return stream_read_i64_le(_s, FALSE); + } + + static INLINE UINT64 Stream_Peek_Get_UINT64_BE(wStream* _s) + { + return stream_read_u64_be(_s, FALSE); + } + + static INLINE INT64 Stream_Peek_Get_INT64_BE(wStream* _s) + { + return stream_read_i64_be(_s, FALSE); + } + #define Stream_Read_UINT8(_s, _v) \ do \ { \ From a82821b756f77e414a993b4dbeb7d666a25feaac Mon Sep 17 00:00:00 2001 From: akallabeth Date: Wed, 4 Sep 2024 13:15:19 +0200 Subject: [PATCH 2/2] [winpr,stream] fix return value signed int functions should not return unsigned values --- winpr/include/winpr/stream.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/winpr/include/winpr/stream.h b/winpr/include/winpr/stream.h index d895b36d7..33411892b 100644 --- a/winpr/include/winpr/stream.h +++ b/winpr/include/winpr/stream.h @@ -188,7 +188,7 @@ extern "C" return v; } - static INLINE UINT16 stream_read_i16_le(wStream* _s, BOOL seek) + static INLINE INT16 stream_read_i16_le(wStream* _s, BOOL seek) { WINPR_ASSERT(_s); WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(INT16)); @@ -200,7 +200,7 @@ extern "C" return v; } - static INLINE UINT16 stream_read_i16_be(wStream* _s, BOOL seek) + static INLINE INT16 stream_read_i16_be(wStream* _s, BOOL seek) { WINPR_ASSERT(_s); WINPR_ASSERT(Stream_GetRemainingLength(_s) >= sizeof(INT16));