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) {
+ if (!value) {
*s = '\0';
-
return 0;
}
- // Otherwise just copy
- return __pakfire_string_format(s, length, "%s", value);
+ // Copy everything until we hit the end of the input string
+ for (unsigned int i = 0; i < length; i++) {
+ s[i] = value[i];
+
+ // Done
+ if (value[i] == '\0')
+ return 0;
+ }
+
+ // It seems that the buffer was not large enough. Terminate and return an error.
+ s[length - 1] = '\0';
+
+ return -ENOBUFS;
}
int __pakfire_string_setn(char* s, const size_t length, const char* value, const size_t l) {