static int replace_variable_with_value(char *str, size_t len,
char *variable_start, char *variable_end,
- const char *value)
+ const char *value, char **endptr)
{
int value_len = strlen(value);
char *from, *to;
from = variable_end + 1;
to = variable_start + value_len;
+ *endptr = to;
+
while (*from) {
*to = *from;
from++;
to--;
}
+ *endptr = from;
+
/*
* use memcpy to avoid NULL terminating prematurely
* the target string
variable_end = ptr;
*ptr = 0;
- ptr++;
value = get_value_for_variable(variable_start, cfg);
if (!value) {
continue;
}
overflow = replace_variable_with_value(str, len, replace_start,
- variable_end, value);
+ variable_end, value, &ptr);
}
if (overflow)