diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2012-08-16 21:36:42 +0800 |
---|---|---|
committer | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2012-09-05 03:22:14 +0800 |
commit | f26472f2d1fe42e8d96fafae1077e5a67767a236 (patch) | |
tree | cdbab34f14d901954e88bf32f787db3657f39ff6 /commands/test.c | |
parent | 0e22047a993ebdc900855cd752fd230b5b6a86e4 (diff) | |
download | barebox-f26472f2d1fe42e8d96fafae1077e5a67767a236.tar.gz barebox-f26472f2d1fe42e8d96fafae1077e5a67767a236.tar.xz |
test: add -L support to test if it's a symbolic link
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Diffstat (limited to 'commands/test.c')
-rw-r--r-- | commands/test.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/commands/test.c b/commands/test.c index 9ffa892524..18eeaab8c1 100644 --- a/commands/test.c +++ b/commands/test.c @@ -43,6 +43,7 @@ typedef enum { OPT_DIRECTORY, OPT_FILE, OPT_EXISTS, + OPT_SYMBOLIC_LINK, OPT_MAX, } test_opts; @@ -62,6 +63,7 @@ static char *test_options[] = { [OPT_FILE] = "-f", [OPT_DIRECTORY] = "-d", [OPT_EXISTS] = "-e", + [OPT_SYMBOLIC_LINK] = "-L", }; static int parse_opt(const char *opt) @@ -140,9 +142,10 @@ static int do_test(int argc, char *argv[]) case OPT_FILE: case OPT_DIRECTORY: case OPT_EXISTS: + case OPT_SYMBOLIC_LINK: adv = 2; if (ap[1] && *ap[1] != ']' && strlen(ap[1])) { - expr = stat(ap[1], &statbuf); + expr = (opt == OPT_SYMBOLIC_LINK ? lstat : stat)(ap[1], &statbuf); if (expr < 0) { expr = 0; break; @@ -160,6 +163,10 @@ static int do_test(int argc, char *argv[]) expr = 1; break; } + if (opt == OPT_SYMBOLIC_LINK && S_ISLNK(statbuf.st_mode)) { + expr = 1; + break; + } } break; @@ -224,7 +231,7 @@ static const char *test_aliases[] = { "[", NULL}; static const __maybe_unused char cmd_test_help[] = "Usage: test [OPTIONS]\n" -"options: !, =, !=, -eq, -ne, -ge, -gt, -le, -lt, -o, -a, -z, -n, -d, -e, -f\n" +"options: !, =, !=, -eq, -ne, -ge, -gt, -le, -lt, -o, -a, -z, -n, -d, -e, -f, -L\n" "see 'man test' on your PC for more information.\n"; static const __maybe_unused char cmd_test_usage[] = "minimal test like /bin/sh"; |