---
Not sure if you want to break up the long line. Up to you.
Another possibility is
if (S_ISLINK(ent->mode))
stat(path, &st);
ent->isdir = S_ISDIR(st.st_mode);
which looks nicer, but I'm not sure if stat(2) is required to not modify the st
argument if it fails.
ls.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/ls.c b/ls.c
index b48391b..a6e4309 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_ISDIR(ent->mode) || S_ISLNK(ent->mode) && stat(path, &st) == 0 && S_ISDIR(st.st_mode);
}
static char *
--
2.1.3.1.g339ec9c
Received on Mon Dec 08 2014 - 00:06:13 CET
This archive was generated by hypermail 2.3.0 : Mon Dec 08 2014 - 00:12:27 CET