Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
return -ENOBUFS;
}
+#define collecty_string_setn(s, value, l) \
+ __collecty_string_setn(s, sizeof(s), value, l)
+
+static inline int __collecty_string_setn(char* s, const size_t length, const char* value, const size_t l) {
+ // Fail if we don't have enough space
+ if (unlikely(l >= length))
+ return -ENOBUFS;
+
+ // Copy the data
+ if (likely(l > 0))
+ memcpy(s, value, l);
+
+ // Terminate the result buffer
+ s[l] = '\0';
+
+ return l;
+}
+
static inline void collecty_string_lstrip(char* s) {
if (!s)
return;