diff th_string.c @ 487:702c64a6c570

Add new string helper functions th_strndup_no0() and th_strndup_no0_trim() to make copies of non-NUL terminated strings.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 19 Sep 2019 06:18:50 +0300
parents e4ce60239d16
children 8917c39ef6c5
line wrap: on
line diff
--- a/th_string.c	Thu Sep 19 06:18:18 2019 +0300
+++ b/th_string.c	Thu Sep 19 06:18:50 2019 +0300
@@ -108,6 +108,24 @@
 }
 
 
+char *th_strndup_no0(const char *src, const size_t len)
+{
+    if ((res = th_malloc(len + 1)) == NULL)
+        return NULL;
+
+    memcpy(res, src, len);
+    res[len] = 0;
+
+    return res;
+}
+
+
+char *th_strndup_no0_trim(const char *src, const size_t len, const int flags)
+{
+    return th_strdup_trim_do(src, len, flags);
+}
+
+
 //
 // Simple implementations of printf() type functions
 //