diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-20 18:36:55 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-20 18:36:55 +0000 |
commit | 456fa6c0b17b2ff465a34db031f667b3fcd4bf2e (patch) | |
tree | c33b80a72a22047d49243ea6307de8e19d3a98e2 /debianutils | |
parent | df5189269074042a60fa87425ef8a01a9aaa4af6 (diff) | |
download | busybox-456fa6c0b17b2ff465a34db031f667b3fcd4bf2e.tar.gz |
readlink: do not emit errors if file doesnt not exist / not a link
getopt32: add =N support
Diffstat (limited to 'debianutils')
-rw-r--r-- | debianutils/readlink.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/debianutils/readlink.c b/debianutils/readlink.c index 0d5ad94f4..9536d3200 100644 --- a/debianutils/readlink.c +++ b/debianutils/readlink.c @@ -13,21 +13,32 @@ #include <stdlib.h> #include <getopt.h> -#define READLINK_FLAG_f (1 << 0) - int readlink_main(int argc, char **argv) { char *buf; - unsigned opt = ENABLE_FEATURE_READLINK_FOLLOW ? - getopt32(argc, argv, "f") : 0; - - if (argc != (ENABLE_FEATURE_READLINK_FOLLOW ? optind + 1 : 2)) - bb_show_usage(); - - if (opt & READLINK_FLAG_f) - buf = realpath(argv[optind], bb_common_bufsiz1); - else - buf = xreadlink(argv[ENABLE_FEATURE_READLINK_FOLLOW ? optind : 1]); + char *fname; + + USE_FEATURE_READLINK_FOLLOW( + unsigned opt; + /* We need exactly one non-option argument. */ + opt_complementary = "=1"; + opt = getopt32(argc, argv, "f"); + fname = argv[optind]; + ) + SKIP_FEATURE_READLINK_FOLLOW( + const unsigned opt = 0; + if (argc != 2) bb_show_usage(); + fname = argv[1]; + ) + + /* compat: coreutils readlink reports errors silently via exit code */ + logmode = LOGMODE_NONE; + + if (opt) { + buf = realpath(fname, bb_common_bufsiz1); + } else { + buf = xreadlink(fname); + } if (!buf) return EXIT_FAILURE; @@ -36,5 +47,5 @@ int readlink_main(int argc, char **argv) if (ENABLE_FEATURE_CLEAN_UP && buf != bb_common_bufsiz1) free(buf); - return EXIT_SUCCESS; + bb_fflush_stdout_and_exit(EXIT_SUCCESS); } |