aboutsummaryrefslogtreecommitdiff
path: root/debianutils
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 /debianutils
parentd824853de335d969f4d009f445bb6dfb1b18493b (diff)
downloadbusybox-w32-c6fbed5dba0ebf333fbe7af4d07ff839492f8882.tar.gz
busybox-w32-c6fbed5dba0ebf333fbe7af4d07ff839492f8882.tar.bz2
busybox-w32-c6fbed5dba0ebf333fbe7af4d07ff839492f8882.zip
- CONFIG_FEATURE_READLINK_FOLLOW readlink -f patch from Colin Watson <cjwatson@debian.org> on busybox mailing list 08/11/04
Diffstat (limited to 'debianutils')
-rw-r--r--debianutils/Config.in7
-rw-r--r--debianutils/readlink.c24
2 files changed, 29 insertions, 2 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
24 This program reads a symbolic link and returns the name 24 This program reads a symbolic link and returns the name
25 of the file it points to 25 of the file it points to
26 26
27config CONFIG_FEATURE_READLINK_FOLLOW
28 bool " Enable canonicalization by following all symlinks (-f)"
29 default n
30 depends on CONFIG_READLINK
31 help
32 Enable the readlink option (-f).
33
27config CONFIG_RUN_PARTS 34config CONFIG_RUN_PARTS
28 bool "run-parts" 35 bool "run-parts"
29 default n 36 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 @@
23#include <errno.h> 23#include <errno.h>
24#include <unistd.h> 24#include <unistd.h>
25#include <stdlib.h> 25#include <stdlib.h>
26#include <getopt.h>
26#include "busybox.h" 27#include "busybox.h"
27 28
29#ifdef CONFIG_FEATURE_READLINK_FOLLOW
30# define READLINK_FOLLOW "f"
31# define READLINK_FLAG_f (1 << 0)
32#else
33# define READLINK_FOLLOW ""
34#endif
35
36static const char readlink_options[] = READLINK_FOLLOW;
37
28int readlink_main(int argc, char **argv) 38int readlink_main(int argc, char **argv)
29{ 39{
30 char *buf = NULL; 40 char *buf = NULL;
41 unsigned long opt = bb_getopt_ulflags(argc, argv, readlink_options);
42#ifdef CONFIG_FEATURE_READLINK_FOLLOW
43 RESERVE_CONFIG_BUFFER(resolved_path, PATH_MAX);
44#endif
31 45
32 /* no options, no getopt */ 46 /* no options, no getopt */
33 47
34 if (argc != 2) 48 if (optind + 1 != argc)
35 bb_show_usage(); 49 bb_show_usage();
36 50
37 buf = xreadlink(argv[1]); 51#ifdef CONFIG_FEATURE_READLINK_FOLLOW
52 if (opt & READLINK_FLAG_f) {
53 buf = realpath(argv[optind], resolved_path);
54 } else
55#endif
56 buf = xreadlink(argv[optind]);
57
38 if (!buf) 58 if (!buf)
39 return EXIT_FAILURE; 59 return EXIT_FAILURE;
40 puts(buf); 60 puts(buf);