string-util: introduce strprepend() helper

This commit is contained in:
Mike Yuan
2025-02-10 19:03:08 +01:00
parent fd2a114061
commit b40694f5fc
3 changed files with 29 additions and 0 deletions

View File

@@ -46,6 +46,20 @@ char* first_word(const char *s, const char *word) {
return (char*) nw;
}
char* strprepend(char **x, const char *s) {
assert(x);
if (isempty(s) && *x)
return *x;
char *p = strjoin(strempty(s), *x);
if (!p)
return NULL;
free_and_replace(*x, p);
return *x;
}
char* strnappend(const char *s, const char *suffix, size_t b) {
size_t a;
char *r;