[dev] [sbase] [PATCH] ls: List directory contents if file is a symlink to a directory

From: Michael Forney <mforney_AT_mforney.org>
Date: Sun, 7 Dec 2014 22:40:42 +0000

---
 ls.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/ls.c b/ls.c
index b48391b..90193cc 100644
--- a/ls.c
+++ b/ls.c
_AT_@ -21,6 +21,7 @@ typedef struct {
 	off_t size;
 	time_t mtime;
 	ino_t ino;
+	int isdir;
 } Entry;
 
 static int entcmp(const void *, const void *);
_AT_@ -117,7 +118,7 @@ entcmp(const void *va, const void *vb)
 static void
 ls(Entry *ent)
 {
-	if (S_ISDIR(ent->mode) && !dflag) {
+	if (ent->isdir && !dflag) {
 		lsdir(ent->name);
 	} else {
 		output(ent);
_AT_@ -191,6 +192,7 @@ mkent(Entry *ent, char *path, int dostat)
 	ent->size   = st.st_size;
 	ent->mtime  = st.st_mtime;
 	ent->ino    = st.st_ino;
+	ent->isdir  = S_ISLNK(ent->mode) && stat(path, &st) == 0 && S_ISDIR(st.st_mode);
 }
 
 static char *
-- 
2.1.3.1.g339ec9c
Received on Sun Dec 07 2014 - 23:40:42 CET

This archive was generated by hypermail 2.3.0 : Sun Dec 07 2014 - 23:48:07 CET