str_sanitize(const char *str)
{
	if (!str)
		return NULL;

	if (!strchr(str, '%'))
		return strdup(str);

	size_t slen = min(strlen(str), 512);
	char *sanitized = zalloc(2 * slen + 1);
	const char *src = str;
	char *dst = sanitized;

	for (size_t i = 0; i < slen; i++) {
		if (*src == '%')
			*dst++ = '%';
		*dst++ = *src++;
	}
	*dst = '\0';

	return sanitized;
}
str_sanitize(const char *str)
{
	if (!str)
		return NULL;

	if (!strchr(str, '%'))
		return strdup(str);

	size_t slen = min(strlen(str), 512);
	char *sanitized = zalloc(2 * slen + 1);
	const char *src = str;
	char *dst = sanitized;

	for (size_t i = 0; i < slen; i++) {
		if (*src == '%')
			*dst++ = '%';
		*dst++ = *src++;
	}
	*dst = '\0';

	return sanitized;
}