mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] commands: stat: print symlink destination when called without -L
@ 2023-05-31 13:23 Ahmad Fatoum
  2023-05-31 13:23 ` [PATCH 2/2] commands: stat: add basic handling for cdev links Ahmad Fatoum
  2023-06-01  7:06 ` [PATCH 1/2] commands: stat: print symlink destination when called without -L Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2023-05-31 13:23 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

This aligns behavior with usual implementations of stat.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 fs/fs.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 368458cc54f8..311571ba3088 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -130,8 +130,6 @@ void stat_print(const char *filename, const struct stat *st)
 		case S_IFREG:    type = "regular file"; break;
 	}
 
-	printf("  File: %s\n", filename);
-
 	if (st->st_mode & S_IFCHR) {
 		char *path;
 
@@ -147,6 +145,21 @@ void stat_print(const char *filename, const struct stat *st)
 		}
 	}
 
+	printf("  File: %s", filename);
+
+	if (S_ISLNK(st->st_mode)) {
+		char realname[PATH_MAX] = {};
+		int ret;
+
+		ret = readlink(filename, realname, PATH_MAX - 1);
+		if (ret)
+			printf(" -> <readlink error %pe>", ERR_PTR(ret));
+		else
+			printf(" -> %s", realname);
+	}
+
+	printf("\n");
+
 	printf("  Size: %-20llu", st->st_size);
 	if (bdev)
 		printf("Blocks: %llu\tIO Block: %u\t",
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-01  7:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-31 13:23 [PATCH 1/2] commands: stat: print symlink destination when called without -L Ahmad Fatoum
2023-05-31 13:23 ` [PATCH 2/2] commands: stat: add basic handling for cdev links Ahmad Fatoum
2023-06-01  7:06 ` [PATCH 1/2] commands: stat: print symlink destination when called without -L Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox