commit 22b65257e224f47d9d1dc5c76d989753c06eb68d
parent 9d8a2307b35e4943508386531e888888f40dad01
Author: Remy Noulin <loader2x@gmail.com>
Date: Thu, 31 Oct 2024 09:16:08 +0200
add bPushNulB to convert btt buffer to char*
release/libsheepy.h | 2 +-
release/libsheepyBt.c | 20 ++++++++++++++++++++
release/libsheepyBt.h | 3 +++
src/libsheepy.h | 2 +-
src/libsheepyBt.c | 20 ++++++++++++++++++++
src/libsheepyBt.h | 3 +++
6 files changed, 48 insertions(+), 2 deletions(-)
Diffstat:
6 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/release/libsheepy.h b/release/libsheepy.h
@@ -98,7 +98,7 @@
// version accoring to the version package: Release.Major.minor.patch
// https://noulin.net/version/file/README.md.html
-#define LIBSHEEPY_VERSION "2.2.15"
+#define LIBSHEEPY_VERSION "2.2.16"
#ifndef SH_PREFIX
#define SH_PREFIX(NAME) NAME
diff --git a/release/libsheepyBt.c b/release/libsheepyBt.c
@@ -269,6 +269,26 @@ btt *bPushB(btt *b, const char *s) {
ret b;
}
+/**
+ * update b and append '\0'
+ * b.b is reallocated
+ */
+btt *bPushNulB(btt *b) {
+ if (!b or !b->b) ret null;
+
+ u32 newsize = makeRoom(b->len, b->alloc, 1);
+ // check if there is enough space
+ if (newsize > b->alloc) {
+ u8 *tmp = realloc(b->b, newsize);
+ if (!tmp) ret null;
+ b->b = tmp;
+ b->alloc = newsize;
+ }
+ b->b[b->len] = 0;
+ b->len++;
+ ret b;
+}
+
// TODO bPushManyB
/**
diff --git a/release/libsheepyBt.h b/release/libsheepyBt.h
@@ -454,6 +454,9 @@ btt pushB(const btt b, const char *s);
#define bAppendB bPushB
btt *bPushB(btt *b, const char *s);
+// '\0' at the end of b to convert b.b to C string char*
+btt *bPushNulB(btt *b);
+
// TODO bPushManyB
// return a btt object with s btt object appended to b
diff --git a/src/libsheepy.h b/src/libsheepy.h
@@ -98,7 +98,7 @@
// version accoring to the version package: Release.Major.minor.patch
// https://noulin.net/version/file/README.md.html
-#define LIBSHEEPY_VERSION "2.2.15"
+#define LIBSHEEPY_VERSION "2.2.16"
#ifndef SH_PREFIX
#define SH_PREFIX(NAME) NAME
diff --git a/src/libsheepyBt.c b/src/libsheepyBt.c
@@ -269,6 +269,26 @@ btt *bPushB(btt *b, const char *s) {
ret b;
}
+/**
+ * update b and append '\0'
+ * b.b is reallocated
+ */
+btt *bPushNulB(btt *b) {
+ if (!b or !b->b) ret null;
+
+ u32 newsize = makeRoom(b->len, b->alloc, 1);
+ // check if there is enough space
+ if (newsize > b->alloc) {
+ u8 *tmp = realloc(b->b, newsize);
+ if (!tmp) ret null;
+ b->b = tmp;
+ b->alloc = newsize;
+ }
+ b->b[b->len] = 0;
+ b->len++;
+ ret b;
+}
+
// TODO bPushManyB
/**
diff --git a/src/libsheepyBt.h b/src/libsheepyBt.h
@@ -454,6 +454,9 @@ btt pushB(const btt b, const char *s);
#define bAppendB bPushB
btt *bPushB(btt *b, const char *s);
+// '\0' at the end of b to convert b.b to C string char*
+btt *bPushNulB(btt *b);
+
// TODO bPushManyB
// return a btt object with s btt object appended to b