ls: show symlinks
This commit is contained in:
parent
9ef61c39e9
commit
ad16c666dc
10
ls.c
10
ls.c
|
@ -152,6 +152,7 @@ output(Entry *ent)
|
||||||
{
|
{
|
||||||
char buf[BUFSIZ], *fmt;
|
char buf[BUFSIZ], *fmt;
|
||||||
char mode[] = "----------";
|
char mode[] = "----------";
|
||||||
|
ssize_t len;
|
||||||
struct group *gr;
|
struct group *gr;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
|
||||||
|
@ -209,6 +210,13 @@ output(Entry *ent)
|
||||||
fmt = "%b %d %H:%M";
|
fmt = "%b %d %H:%M";
|
||||||
|
|
||||||
strftime(buf, sizeof buf, fmt, localtime(&ent->mtime));
|
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);
|
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');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user