summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/cmd-list.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/tmux/cmd-list.c')
-rw-r--r--usr.bin/tmux/cmd-list.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/usr.bin/tmux/cmd-list.c b/usr.bin/tmux/cmd-list.c
index 66eaeef1410..32505c13ed6 100644
--- a/usr.bin/tmux/cmd-list.c
+++ b/usr.bin/tmux/cmd-list.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-list.c,v 1.14 2014/09/01 21:50:18 nicm Exp $ */
+/* $OpenBSD: cmd-list.c,v 1.15 2015/11/27 15:06:43 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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);
}