diff options
author | Lennart Poettering <lennart@poettering.net> | 2011-08-01 01:28:01 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2011-08-01 01:28:01 +0200 |
commit | 911a4828e054a531be961cea34de89b666bda710 (patch) | |
tree | 4ba6454e7e3b08b578a91d1728062c4efbf233bc /src/util.c | |
parent | 57a8eca84a1eda99c8cfb63889fa300ba982cb77 (diff) |
util: introduce join() to speed up simple string concatenations
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index 1a61a26046..b533b26daf 100644 --- a/src/util.c +++ b/src/util.c @@ -5493,6 +5493,54 @@ finish: return r; } +char *join(const char *x, ...) { + va_list ap; + size_t l; + char *r, *p; + + va_start(ap, x); + + if (x) { + l = strlen(x); + + for (;;) { + const char *t; + + t = va_arg(ap, const char *); + if (!t) + break; + + l += strlen(t); + } + } else + l = 0; + + va_end(ap); + + r = new(char, l+1); + if (!r) + return NULL; + + if (x) { + p = stpcpy(r, x); + + va_start(ap, x); + + for (;;) { + const char *t; + + t = va_arg(ap, const char *); + if (!t) + break; + + p = stpcpy(p, t); + } + } else + r[0] = 0; + + return r; +} + static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", [IOPRIO_CLASS_RT] = "realtime", |