From 9201f501eae07c0b19f600c15685348b896e9edb Mon Sep 17 00:00:00 2001 From: rwatson Date: Thu, 24 Oct 2002 01:01:53 +0000 Subject: Attempt improved use of fts results: use the correct path to the object to retrieve label information on, rather than directly consuming the fts-provided paths (none of which are quite right). This is based on the similar readlink() code, and may contain the same bugs. Obtained from: TrustedBSD Project Sponsored by: DARPA, Network Associates Laboratories --- bin/ls/ls.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'bin') diff --git a/bin/ls/ls.c b/bin/ls/ls.c index 6cacf4f..cddbb79 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -685,6 +686,7 @@ display(FTSENT *p, FTSENT *list, int options) flen = 0; labelstr = NULL; if (f_label) { + char name[PATH_MAX + 1]; mac_t label; int error; @@ -696,12 +698,20 @@ display(FTSENT *p, FTSENT *list, int options) goto label_out; } + if (cur->fts_level == FTS_ROOTLEVEL) + snprintf(name, sizeof(name), + "%s", cur->fts_name); + else + snprintf(name, sizeof(name), + "%s/%s", cur->fts_parent->fts_accpath, + cur->fts_name); + if (options & FTS_LOGICAL) - error = mac_get_file( - cur->fts_path, label); + error = mac_get_file(name, + label); else - error = mac_get_link( - cur->fts_name, label); + error = mac_get_link(name, + label); if (error == -1) { perror(cur->fts_name); mac_free(label); -- cgit v1.1