From 3083290af868a18bdf3f2bd7a251f8567d266ef0 Mon Sep 17 00:00:00 2001 From: LJ Sonic <lamr@free.fr> Date: Mon, 10 Jan 2022 18:57:18 +0100 Subject: [PATCH] Add READSTRINGL and WRITESTRINGL macros --- src/byteptr.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/byteptr.h b/src/byteptr.h index f66d9fcaf1..3a13665778 100644 --- a/src/byteptr.h +++ b/src/byteptr.h @@ -160,6 +160,15 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) WRITECHAR(p, '\0'); \ }) +#define WRITESTRINGL(p, s, n) ({ \ + size_t tmp_i; \ + \ + for (tmp_i = 0; tmp_i < n - 1 && s[tmp_i] != '\0'; tmp_i++) \ + WRITECHAR(p, s[tmp_i]); \ + \ + WRITECHAR(p, '\0'); \ +}) + #define WRITESTRING(p, s) ({ \ size_t tmp_i; \ \ @@ -192,6 +201,15 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) s[tmp_i] = '\0'; \ }) +#define READSTRINGL(p, s, n) ({ \ + size_t tmp_i = 0; \ + \ + while (tmp_i < n - 1 && (s[tmp_i] = READCHAR(p)) != '\0') \ + tmp_i++; \ + \ + s[tmp_i] = '\0'; \ +}) + #define READSTRING(p, s) ({ \ size_t tmp_i = 0; \ \ -- GitLab