From 710696420f50234716579c98367696a43a211482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Courr=C3=A8ges-Anglas?= Date: Tue, 4 Mar 2014 02:49:35 +0100 Subject: Simplify list_unmanaged_windows using sbuf --- src/manage.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/manage.c b/src/manage.c index 5a9a9d8..f54c63a 100644 --- a/src/manage.c +++ b/src/manage.c @@ -57,25 +57,21 @@ char * list_unmanaged_windows (void) { char *tmp = NULL; + if (unmanaged_window_list) { - char *tpos; - int len = 0; + struct sbuf *buf; int i; - for (i = 0; i < num_unmanaged_windows; i++) - len += (strlen(unmanaged_window_list[i]) + 1); - - tmp = xmalloc(len + 1); - tpos = tmp; + buf = sbuf_new (0); for (i = 0; i < num_unmanaged_windows; i++) { - sprintf(tpos, "%s\n", unmanaged_window_list[i]); - tpos += strlen(unmanaged_window_list[i])+1; + sbuf_concat (buf, unmanaged_window_list[i]); + sbuf_concat (buf, "\n"); } - tpos--; - *tpos = '\0'; + sbuf_chop (buf); + tmp = sbuf_free_struct (buf); } return tmp; } -- cgit v1.2.3