aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
Diffstat (limited to 'toys')
-rw-r--r--toys/other/stat.c4
-rw-r--r--toys/posix/file.c20
2 files changed, 15 insertions, 9 deletions
diff --git a/toys/other/stat.c b/toys/other/stat.c
index c4c1bf42..66c5dc3b 100644
--- a/toys/other/stat.c
+++ b/toys/other/stat.c
@@ -191,8 +191,8 @@ void stat_main(void)
"Block Size: %s Fundamental block size: %S\n"
"Blocks: Total: %b\tFree: %f\tAvailable: %a\n"
"Inodes: Total: %c\tFree: %d"
- : " File: %N\n Size: %s\t Blocks: %b\t IO Blocks: %B\t%F\n"
- "Device: %Dh/%dd\t Inode: %i\t Links: %h\n"
+ : " File: %N\n Size: %s\t Blocks: %b\t IO Blocks: %B\t %F\n"
+ "Device: %Dh/%dd\t Inode: %i\t Links: %h\t Device type: %t,%T\n"
"Access: (0%a/%A)\tUid: (%5u/%8U)\tGid: (%5g/%8G)\n"
"Access: %x\nModify: %y\nChange: %z";
diff --git a/toys/posix/file.c b/toys/posix/file.c
index 6b8c6779..2370be79 100644
--- a/toys/posix/file.c
+++ b/toys/posix/file.c
@@ -421,7 +421,7 @@ void file_main(void)
// Can't use loopfiles here because it doesn't call function when can't open
for (arg = toys.optargs; *arg; arg++) {
- char *name = *arg, *what = "cannot open";
+ char *name = *arg, *what = "unknown";
struct stat sb;
int fd = !strcmp(name, "-");
@@ -439,14 +439,20 @@ void file_main(void)
continue;
}
} else if (S_ISFIFO(sb.st_mode)) what = "fifo";
- else if (S_ISBLK(sb.st_mode)) what = "block special";
- else if (S_ISCHR(sb.st_mode)) what = "character special";
+ else if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode))
+ sprintf(what = toybuf, "%s special (%u/%u)",
+ S_ISBLK(sb.st_mode) ? "block" : "character",
+ dev_major(sb.st_rdev), dev_minor(sb.st_rdev));
else if (S_ISDIR(sb.st_mode)) what = "directory";
else if (S_ISSOCK(sb.st_mode)) what = "socket";
- else if (S_ISLNK(sb.st_mode)) what = "symbolic link";
- else what = "unknown";
- }
+ else if (S_ISLNK(sb.st_mode)) {
+ char *lnk = xreadlink(name);
- xputs(what);
+ sprintf(what = toybuf, "%ssymbolic link to %s",
+ stat(lnk, &sb) ? "broken " : "", lnk);
+ free(lnk);
+ }
+ xputs(what);
+ } else xprintf("cannot open: %s\n", strerror(errno));
}
}