From 493dc573825a862ee533c8aaf91ab23112b591c2 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 13 Sep 2016 13:55:59 -0700 Subject: Add -h and -L to file. On a toybox system, most of your bin directory is symbolic links. Bug: http://b/31294746 --- toys/posix/file.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'toys/posix/file.c') 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) { -- cgit v1.2.3