Unverified Commit 99b7f9db by Wolfgang Bumiller Committed by Christian Brauner

utils: add must_concat helper

parent f6eea250
......@@ -2426,6 +2426,30 @@ int run_command(char *buf, size_t buf_size, int (*child_fn)(void *), void *args)
return fret;
}
char *must_concat(const char *first, ...)
{
va_list args;
char *cur, *dest;
size_t cur_len, it_len;
dest = must_copy_string(first);
cur_len = it_len = strlen(first);
va_start(args, first);
while ((cur = va_arg(args, char *)) != NULL) {
it_len = strlen(cur);
dest = must_realloc(dest, cur_len + it_len + 1);
(void)memcpy(dest + cur_len, cur, it_len);
cur_len += it_len;
}
va_end(args);
dest[cur_len] = 0;
return dest;
}
char *must_make_path(const char *first, ...)
{
va_list args;
......
......@@ -567,6 +567,7 @@ extern int run_command(char *buf, size_t buf_size, int (*child_fn)(void *),
/* Concatenate all passed-in strings into one path. Do not fail. If any piece
* is not prefixed with '/', add a '/'.
*/
__attribute__((sentinel)) extern char *must_concat(const char *first, ...);
__attribute__((sentinel)) extern char *must_make_path(const char *first, ...);
__attribute__((sentinel)) extern char *must_append_path(char *first, ...);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment