aboutsummaryrefslogtreecommitdiff
path: root/cmd-list.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2015-11-27 15:41:28 +0000
committerThomas Adam <thomas@xteddy.org>2015-11-27 15:41:28 +0000
commit9fe8b28746faa5d38c25853449127d526beac8f9 (patch)
treea7d9f07efdbce0d4be8f8920efb7ccde1c5b308d /cmd-list.c
parent3b83bda29c51c7b2c3aeef01dde1d3ba6a441e89 (diff)
parent6a2ca34216530c687027cf9e767d2b46c85976e6 (diff)
downloadrtmux-9fe8b28746faa5d38c25853449127d526beac8f9.tar.gz
rtmux-9fe8b28746faa5d38c25853449127d526beac8f9.tar.bz2
rtmux-9fe8b28746faa5d38c25853449127d526beac8f9.zip
Merge branch 'obsd-master'
Diffstat (limited to 'cmd-list.c')
-rw-r--r--cmd-list.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/cmd-list.c b/cmd-list.c
index 0c75ed49..59fc7796 100644
--- a/cmd-list.c
+++ b/cmd-list.c
@@ -99,25 +99,28 @@ cmd_list_free(struct cmd_list *cmdlist)
free(cmdlist);
}
-size_t
-cmd_list_print(struct cmd_list *cmdlist, char *buf, size_t len)
+char *
+cmd_list_print(struct cmd_list *cmdlist)
{
struct cmd *cmd;
- size_t off, used;
+ char *buf, *this;
+ size_t len;
+
+ len = 1;
+ buf = xcalloc(1, len);
- off = 0;
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
- if (off >= len)
- break;
- off += cmd_print(cmd, buf + off, len - off);
- if (off >= len)
- break;
- if (TAILQ_NEXT(cmd, qentry) != NULL) {
- used = xsnprintf(buf + off, len - off, " ; ");
- if (used > len - off)
- used = len - off;
- off += used;
- }
+ this = cmd_print(cmd);
+
+ len += strlen(this) + 3;
+ buf = xrealloc(buf, len);
+
+ strlcat(buf, this, len);
+ if (TAILQ_NEXT(cmd, qentry) != NULL)
+ strlcat(buf, " ; ", len);
+
+ free(this);
}
- return (off);
+
+ return (buf);
}