summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2024-03-04 19:59:33 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2024-03-05 16:28:05 +0100
commit788f616946df66732ed8fde05f56b6329debdba3 (patch)
tree79536a35ce4bbf42dbd198d2ecf2294546e17361 /lib
parent35a903414ddcf8cef180a29a8271f59e0b1623cd (diff)
downloadbarebox-788f616946df66732ed8fde05f56b6329debdba3.tar.gz
barebox-788f616946df66732ed8fde05f56b6329debdba3.tar.xz
commands: time: refactor into new strjoin
time concatenates all its remaining arguments with a space in-between and then passes that to the command executor. This can be useful elsewhere as well, so factor it out into a new strjoin function. No functional change. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-49-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/string.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c
index bf0f0455ab..695e50bc8f 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -1000,3 +1000,31 @@ char *parse_assignment(char *str)
return value;
}
+
+char *strjoin(const char *separator, char **arr, size_t arrlen)
+{
+ size_t separatorlen;
+ int len = 1; /* '\0' */
+ char *buf, *p;
+ int i;
+
+ separatorlen = strlen(separator);
+
+ for (i = 0; i < arrlen; i++)
+ len += strlen(arr[i]) + separatorlen;
+
+ if (!arrlen)
+ return xzalloc(1);
+
+ p = buf = xmalloc(len);
+
+ for (i = 0; i < arrlen - 1; i++) {
+ p = stpcpy(p, arr[i]);
+ p = mempcpy(p, separator, separatorlen);
+ }
+
+ stpcpy(p, arr[i]);
+
+ return buf;
+}
+EXPORT_SYMBOL(strjoin);