sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit ad16c666dc65782226ff97c918eee2e026d94377
parent 9ef61c39e995116cfc9f0f0408bb083061fc7f6e
Author: Connor Lane Smith <cls@lubutu.com>
Date:   Sat,  4 Jun 2011 12:40:05 +0100

ls: show symlinks
Diffstat:
Mls.c | 12++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/ls.c b/ls.c @@ -152,6 +152,7 @@ output(Entry *ent) { char buf[BUFSIZ], *fmt; char mode[] = "----------"; + ssize_t len; struct group *gr; struct passwd *pw; @@ -204,11 +205,18 @@ output(Entry *ent) eprintf("getgrgid %d: no such group\n", ent->gid); if(time(NULL) > ent->mtime + (180*24*60*60)) /* 6 months ago? */ - fmt = "%b %d %Y"; + fmt = "%b %d %Y"; else fmt = "%b %d %H:%M"; strftime(buf, sizeof buf, fmt, localtime(&ent->mtime)); - printf("%s %2d %s %s %6lu %s %s\n", mode, ent->nlink, pw->pw_name, + printf("%s %2d %s %s %6lu %s %s", mode, ent->nlink, pw->pw_name, gr->gr_name, (unsigned long)ent->size, buf, ent->name); + if(S_ISLNK(ent->mode)) { + if((len = readlink(ent->name, buf, sizeof buf)) == -1) + eprintf("readlink %s:", ent->name); + buf[len] = '\0'; + printf(" -> %s", buf); + } + putchar('\n'); }