aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-09-13 13:55:59 -0700
committerRob Landley <rob@landley.net>2016-09-13 17:16:32 -0500
commit493dc573825a862ee533c8aaf91ab23112b591c2 (patch)
tree8d9852393103841f0b3ec1ca7c2a0c99225d7e47 /toys/posix
parent9f42e832a186bb3f5320581a3a713d0a8a9c8384 (diff)
downloadtoybox-493dc573825a862ee533c8aaf91ab23112b591c2.tar.gz
Add -h and -L to file.
On a toybox system, most of your bin directory is symbolic links. Bug: http://b/31294746
Diffstat (limited to 'toys/posix')
-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) {