diff options
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/util.c | 19 | ||||
-rw-r--r-- | src/shared/util.h | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index f94abbcc02..69f1b00934 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -5797,3 +5797,22 @@ char *strextend(char **x, ...) { return r + l; } + +char *strrep(const char *s, unsigned n) { + size_t l; + char *r, *p; + unsigned i; + + assert(s); + + l = strlen(s); + p = r = malloc(l * n + 1); + if (!r) + return NULL; + + for (i = 0; i < n; i++) + p = stpcpy(p, s); + + *p = 0; + return r; +} diff --git a/src/shared/util.h b/src/shared/util.h index 25c00843ec..f75c66bb83 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -608,3 +608,4 @@ static inline void *mempset(void *s, int c, size_t n) { char *hexmem(const void *p, size_t l); char *strextend(char **x, ...); +char *strrep(const char *s, unsigned n); |