diff options
author | Ned Ludd | 2004-12-08 16:47:28 +0000 |
---|---|---|
committer | Ned Ludd | 2004-12-08 16:47:28 +0000 |
commit | c6fbed5dba0ebf333fbe7af4d07ff839492f8882 (patch) | |
tree | 32f4a2fb3de679b3b670f21909272026fd35004e /debianutils/readlink.c | |
parent | d824853de335d969f4d009f445bb6dfb1b18493b (diff) | |
download | busybox-c6fbed5dba0ebf333fbe7af4d07ff839492f8882.zip busybox-c6fbed5dba0ebf333fbe7af4d07ff839492f8882.tar.gz |
- CONFIG_FEATURE_READLINK_FOLLOW readlink -f patch from Colin Watson <cjwatson@debian.org> on busybox mailing list 08/11/04
Diffstat (limited to 'debianutils/readlink.c')
-rw-r--r-- | debianutils/readlink.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/debianutils/readlink.c b/debianutils/readlink.c index d8d7e8c..90927bb 100644 --- a/debianutils/readlink.c +++ b/debianutils/readlink.c @@ -23,18 +23,38 @@ #include <errno.h> #include <unistd.h> #include <stdlib.h> +#include <getopt.h> #include "busybox.h" +#ifdef CONFIG_FEATURE_READLINK_FOLLOW +# define READLINK_FOLLOW "f" +# define READLINK_FLAG_f (1 << 0) +#else +# define READLINK_FOLLOW "" +#endif + +static const char readlink_options[] = READLINK_FOLLOW; + int readlink_main(int argc, char **argv) { char *buf = NULL; + unsigned long opt = bb_getopt_ulflags(argc, argv, readlink_options); +#ifdef CONFIG_FEATURE_READLINK_FOLLOW + RESERVE_CONFIG_BUFFER(resolved_path, PATH_MAX); +#endif /* no options, no getopt */ - if (argc != 2) + if (optind + 1 != argc) bb_show_usage(); - buf = xreadlink(argv[1]); +#ifdef CONFIG_FEATURE_READLINK_FOLLOW + if (opt & READLINK_FLAG_f) { + buf = realpath(argv[optind], resolved_path); + } else +#endif + buf = xreadlink(argv[optind]); + if (!buf) return EXIT_FAILURE; puts(buf); |