[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#231994: ls adds newline before first directory header



Package: busybox-cvs
Version: 20040101-6
Tags: patch

ls prints a newline before the first directory header:

 $ mkdir /tmp/foo
 $ busybox ls /tmp/foo

 /tmp/foo:
 $ exit

but it should be omitted.  The attached patch makes it do so.

-- 
Matt Kraai            kraai@ftbfs.org            http://ftbfs.org/
--- busybox-cvs-20040101/coreutils/ls.c.orig	2004-02-09 17:21:27.000000000 -0800
+++ busybox-cvs-20040101/coreutils/ls.c	2004-02-09 17:21:33.000000000 -0800
@@ -532,7 +532,7 @@
 }
 
 /*----------------------------------------------------------------------*/
-static void showdirs(struct dnode **dn, int ndirs)
+static void showdirs(struct dnode **dn, int ndirs, int first)
 {
 	int i, nfiles;
 	struct dnode **subdnp;
@@ -547,7 +547,10 @@
 
 	for (i = 0; i < ndirs; i++) {
 		if (all_fmt & (DISP_DIRNAME | DISP_RECURSIVE)) {
-			printf("\n%s:\n", dn[i]->fullname);
+			if (!first)
+				printf("\n");
+			first = 0;
+			printf("%s:\n", dn[i]->fullname);
 		}
 		subdnp = list_dir(dn[i]->fullname);
 		nfiles = countfiles(subdnp);
@@ -566,7 +569,7 @@
 #ifdef CONFIG_FEATURE_LS_SORTFILES
 					shellsort(dnd, dndirs);
 #endif
-					showdirs(dnd, dndirs);
+					showdirs(dnd, dndirs, 0);
 					free(dnd);	/* free the array of dnode pointers to the dirs */
 				}
 			}
@@ -1084,7 +1087,7 @@
 #ifdef CONFIG_FEATURE_LS_SORTFILES
 			shellsort(dnd, dndirs);
 #endif
-			showdirs(dnd, dndirs);
+			showdirs(dnd, dndirs, dnfiles == 0);
 		}
 	}
 	return (status);

Reply to: