[lxc-devel] [lxc/master] tools: do not add trailing spaces on lxc-ls -1

brauner on Github lxc-bot at linuxcontainers.org
Wed Sep 21 07:16:08 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 384 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160921/4c1a1e56/attachment.bin>
-------------- next part --------------
From 27de259f33a4ef4ecb086d53341acaaac120ccdd Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at canonical.com>
Date: Wed, 21 Sep 2016 09:15:14 +0200
Subject: [PATCH] tools: do not add trailing spaces on lxc-ls -1

Signed-off-by: Christian Brauner <christian.brauner at canonical.com>
---
 src/lxc/tools/lxc_ls.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/lxc/tools/lxc_ls.c b/src/lxc/tools/lxc_ls.c
index e22c715..8e7cbef 100644
--- a/src/lxc/tools/lxc_ls.c
+++ b/src/lxc/tools/lxc_ls.c
@@ -144,7 +144,7 @@ static void ls_print_fancy_format(struct ls *l, struct lengths *lht,
  * Only print names of containers.
  */
 static void ls_print_names(struct ls *l, struct lengths *lht,
-		size_t ls_arr, size_t termwidth);
+		size_t ls_arr, size_t termwidth, bool list);
 
 /*
  * Print default fancy format.
@@ -264,7 +264,7 @@ int main(int argc, char *argv[])
 		unsigned int cols = 0;
 		if (!my_args.ls_line)
 			cols = ls_get_term_width();
-		ls_print_names(ls_arr, &max_len, ls_size, cols);
+		ls_print_names(ls_arr, &max_len, ls_size, cols, my_args.ls_line);
 	}
 
 	ret = EXIT_SUCCESS;
@@ -743,7 +743,7 @@ static struct ls *ls_new(struct ls **ls, size_t *size)
 }
 
 static void ls_print_names(struct ls *l, struct lengths *lht,
-		size_t size, size_t termwidth)
+		size_t size, size_t termwidth, bool list)
 {
 	/* If list is empty do nothing. */
 	if (size == 0)
@@ -752,14 +752,18 @@ static void ls_print_names(struct ls *l, struct lengths *lht,
 	size_t i, len = 0;
 	struct ls *m = NULL;
 	for (i = 0, m = l; i < size; i++, m++) {
-		printf("%-*s", lht->name_length, m->name ? m->name : "-");
-		len += lht->name_length;
-		if ((len + lht->name_length) >= termwidth) {
-			printf("\n");
-			len = 0;
+		if (list) {
+			printf("%s\n", m->name ? m->name : "-");
 		} else {
-			printf(" ");
-			len++;
+			printf("%-*s", lht->name_length, m->name ? m->name : "-");
+			len += lht->name_length;
+			if ((len + lht->name_length) >= termwidth) {
+				printf("\n");
+				len = 0;
+			} else {
+				printf(" ");
+				len++;
+			}
 		}
 	}
 	if (len > 0)


More information about the lxc-devel mailing list