aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Ludd <solar@gentoo.org>2004-12-08 16:47:28 +0000
committerNed Ludd <solar@gentoo.org>2004-12-08 16:47:28 +0000
commitc6fbed5dba0ebf333fbe7af4d07ff839492f8882 (patch)
tree32f4a2fb3de679b3b670f21909272026fd35004e
parentd824853de335d969f4d009f445bb6dfb1b18493b (diff)
downloadbusybox-c6fbed5dba0ebf333fbe7af4d07ff839492f8882.tar.gz
- CONFIG_FEATURE_READLINK_FOLLOW readlink -f patch from Colin Watson <cjwatson@debian.org> on busybox mailing list 08/11/04
-rw-r--r--debianutils/Config.in7
-rw-r--r--debianutils/readlink.c24
-rw-r--r--include/usage.h12
3 files changed, 39 insertions, 4 deletions
diff --git a/debianutils/Config.in b/debianutils/Config.in
index 7cf7cadb5..f13d56ec7 100644
--- a/debianutils/Config.in
+++ b/debianutils/Config.in
@@ -24,6 +24,13 @@ config CONFIG_READLINK
This program reads a symbolic link and returns the name
of the file it points to
+config CONFIG_FEATURE_READLINK_FOLLOW
+ bool " Enable canonicalization by following all symlinks (-f)"
+ default n
+ depends on CONFIG_READLINK
+ help
+ Enable the readlink option (-f).
+
config CONFIG_RUN_PARTS
bool "run-parts"
default n
diff --git a/debianutils/readlink.c b/debianutils/readlink.c
index d8d7e8c2d..90927bb74 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);
diff --git a/include/usage.h b/include/usage.h
index 377eb10e7..d928a10a3 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1985,10 +1985,18 @@
"\t-s\tSet the system date and time (default).\n" \
"\t-p\tPrint the date and time."
+#ifdef CONFIG_FEATURE_READLINK_FOLLOW
+#define USAGE_READLINK_FOLLOW(a) a
+#else
+#define USAGE_READLINK_FOLLOW(a)
+#endif
+
#define readlink_trivial_usage \
- ""
+ USAGE_READLINK_FOLLOW("[-f] ") "FILE"
#define readlink_full_usage \
- "Displays the value of a symbolic link."
+ "Displays the value of a symbolic link." \
+ USAGE_READLINK_FOLLOW("\n\nOptions:\n" \
+ "\t-f\tcanonicalize by following all symlinks")
#define realpath_trivial_usage \
"pathname ..."