[BusyBox] bug#1041: [PATCH] support for ls -L

Matt Kraai kraai at alumni.carnegiemellon.edu
Thu Sep 21 19:43:36 UTC 2000


Howdy,

The appended patch adds support for the -L option.  I don't have access
to my Linux box, so it may not even compile, but the idea should be
sound.  I'll see about applying it to CVS later today.

Erik, after testing, should I 
	not put it in CVS?
	put it in as a feature off by default?
	put it in as a feature on by default?
	put it in unconditionally?

The patch below implements the third option.

Matt

--- busybox.def.h.orig	Thu Sep 21 12:21:49 2000
+++ busybox.def.h	Thu Sep 21 12:22:24 2000
@@ -169,6 +169,9 @@
 // enable ls -R
 #define BB_FEATURE_LS_RECURSIVE
 //
+// enable ls -L
+#define BB_FEATURE_LS_FOLLOWLINKS
+//
 // Change ping implementation -- simplified, featureless, but really small.
 //#define BB_FEATURE_SIMPLE_PING
 //
--- ls.c.orig	Thu Sep 21 12:18:27 2000
+++ ls.c	Thu Sep 21 12:27:58 2000
@@ -159,6 +159,9 @@
 #ifdef BB_FEATURE_LS_TIMESTAMPS
 static unsigned int time_fmt=	TIME_MOD;
 #endif
+#ifdef BB_FEATURE_LS_FOLLOWLINKS
+static unsigned int follow_links=FALSE;
+#endif
 
 static unsigned short column = 0;
 #ifdef BB_FEATURE_AUTOWIDTH
@@ -474,6 +477,16 @@
 		cur= (struct dnode *)xmalloc(sizeof(struct dnode));
 		cur->fullname= xstrdup(fullname);
 		cur->name= cur->fullname + (int)(fnend - fullname) ;
+#ifdef BB_FEATURE_LS_FOLLOWLINKS
+		if (follow_links == TRUE) {
+			if (stat(fullname, &cur->dstat)) {
+				errorMsg("%s: %s\n", fullname, strerror(errno));
+				free(cur->fullname);
+				free(cur);
+				continue;
+			}
+		} else
+#endif
 		if (lstat(fullname, &cur->dstat)) {   /* get file stat info into node */
 			errorMsg("%s: %s\n", fullname, strerror(errno));
 			free(cur->fullname);
@@ -682,6 +695,9 @@
 #ifdef BB_FEATURE_LS_TIMESTAMPS
 "cetu"
 #endif
+#ifdef BB_FEATURE_LS_FOLLOWLINKS
+"L"
+#endif
 	)) > 0) {
 		switch (opt) {
 			case '1': style_fmt = STYLE_SINGLE; break;
@@ -713,6 +729,9 @@
 			case 'c': time_fmt = TIME_CHANGE; sort_opts= SORT_CTIME; break;
 			case 't': sort_opts= SORT_MTIME; break;
 			case 'u': time_fmt = TIME_ACCESS; sort_opts= SORT_ATIME; break;
+#endif
+#ifdef BB_FEATURE_LS_FOLLOWLINKS
+			case 'L': follow_links= TRUE;
 #endif
 #ifdef BB_FEATURE_AUTOWIDTH
 			case 'T': tabstops= atoi(optarg); break;






More information about the busybox mailing list