aboutsummaryrefslogtreecommitdiff
path: root/src/nc-util.h
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-07-05 00:03:48 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2024-07-05 00:03:48 -0400
commit23fe6e8c8596333c2183f0f4389817087442c551 (patch)
tree1b87644b34141f9deedf7c655084a3c0d5b22817 /src/nc-util.h
parentdc71f861df8929deee300368b88ef47d45560695 (diff)
push latest utils and changes
Diffstat (limited to 'src/nc-util.h')
-rw-r--r--src/nc-util.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/nc-util.h b/src/nc-util.h
index dd319c7..0647f4c 100644
--- a/src/nc-util.h
+++ b/src/nc-util.h
@@ -68,6 +68,28 @@
#define _overflow_check(x)
#endif
+#ifdef NC_EXTREME_COMPAT
+
+ void _nc_memmove(void* dst, const void* src, uint32_t size)
+ {
+ uint32_t i;
+
+ for (i = 0; i < size; i++)
+ {
+ ((uint8_t*)dst)[i] = ((uint8_t*)src)[i];
+ }
+ }
+
+ #define MEMMOV _nc_memmove
+
+#else
+
+ /* Include string for memmove */
+ #include <string.h>
+ #define MEMMOV(dst, src, size) memmove(dst, src, size)
+
+#endif /* NC_EXTREME_COMPAT */
+
typedef struct memory_span_struct
{
uint8_t* data;
@@ -92,4 +114,28 @@ static _nc_fn_inline void ncSpanInit(span_t* span, uint8_t* data, uint32_t size)
span->size = size;
}
+static _nc_fn_inline void ncSpanWrite(span_t span, uint32_t offset, const uint8_t* data, uint32_t size)
+{
+ DEBUG_ASSERT2(span.data != NULL, "Expected span to be non-null")
+ DEBUG_ASSERT2(data != NULL, "Expected data to be non-null")
+ DEBUG_ASSERT2(offset + size <= span.size, "Expected offset + size to be less than span size")
+
+ /* Copy data to span */
+ MEMMOV(span.data + offset, data, size);
+}
+
+static _nc_fn_inline void ncSpanAppend(span_t span, uint32_t* offset, const uint8_t* data, uint32_t size)
+{
+ DEBUG_ASSERT2(span.data != NULL, "Expected span to be non-null")
+ DEBUG_ASSERT2(offset != NULL, "Expected offset to be non-null")
+ DEBUG_ASSERT2(data != NULL, "Expected data to be non-null")
+ DEBUG_ASSERT2(*offset + size <= span.size, "Expected offset + size to be less than span size")
+
+ /* Copy data to span */
+ MEMMOV(span.data + *offset, data, size);
+
+ /* Increment offset */
+ *offset += size;
+}
+
#endif /* !_NC_UTIL_H */ \ No newline at end of file