Otherwise, we would have seen "(null)" which is not what we want.
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
/*
Simpler version when a string needs to be copied.
*/
-#define pakfire_string_set(s, value) pakfire_string_format(s, "%s", value)
+#define pakfire_string_set(s, value) \
+ __pakfire_string_set(s, sizeof(s), value)
+int __pakfire_string_set(char* s, const size_t length, const char* value);
int pakfire_string_startswith(const char* s, const char* prefix);
int pakfire_string_endswith(const char* s, const char* suffix);
return 0;
}
+int __pakfire_string_set(char* s, const size_t length, const char* value) {
+ // If value is NULL or an empty, we will overwrite the buffer with just zeros
+ if (!value || !*value) {
+ for (unsigned int i = 0; i < length; i++)
+ s[i] = '\0';
+
+ return 0;
+ }
+
+ // Otherwise just copy
+ return __pakfire_string_format(s, length, "%s", value);
+}
+
int pakfire_string_startswith(const char* s, const char* prefix) {
// Validate input
if (!s || !prefix) {