aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'toys/posix/file.c')
-rw-r--r--toys/posix/file.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/toys/posix/file.c b/toys/posix/file.c
index 27b4c0c2..335c67ce 100644
--- a/toys/posix/file.c
+++ b/toys/posix/file.c
@@ -6,15 +6,18 @@
*
* TODO: ar
-USE_FILE(NEWTOY(file, "<1", TOYFLAG_USR|TOYFLAG_BIN))
+USE_FILE(NEWTOY(file, "<1hL[!hL]", TOYFLAG_USR|TOYFLAG_BIN))
config FILE
bool "file"
default y
help
- usage: file [file...]
+ usage: file [-hL] [file...]
Examine the given files and describe their content types.
+
+ -h don't follow symlinks (default)
+ -L follow symlinks
*/
#define FOR_file
@@ -281,7 +284,7 @@ void file_main(void)
xprintf("%s: %*s", name, (int)(TT.max_name_len - strlen(name)), "");
- if (fd || !lstat(name, &sb)) {
+ if (fd || !((toys.optflags & FLAG_L) ? stat : lstat)(name, &sb)) {
if (fd || S_ISREG(sb.st_mode)) {
if (!sb.st_size) what = "empty";
else if ((fd = openro(name, O_RDONLY)) != -1) {