diff options
-rw-r--r-- | debianutils/Config.in | 7 | ||||
-rw-r--r-- | debianutils/readlink.c | 24 | ||||
-rw-r--r-- | include/usage.h | 12 |
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 | |||
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 | ||
27 | config 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 | |||
27 | config CONFIG_RUN_PARTS | 34 | config 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 | |||
36 | static const char readlink_options[] = READLINK_FOLLOW; | ||
37 | |||
28 | int readlink_main(int argc, char **argv) | 38 | int 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); |
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 @@ | |||
1985 | "\t-s\tSet the system date and time (default).\n" \ | 1985 | "\t-s\tSet the system date and time (default).\n" \ |
1986 | "\t-p\tPrint the date and time." | 1986 | "\t-p\tPrint the date and time." |
1987 | 1987 | ||
1988 | #ifdef CONFIG_FEATURE_READLINK_FOLLOW | ||
1989 | #define USAGE_READLINK_FOLLOW(a) a | ||
1990 | #else | ||
1991 | #define USAGE_READLINK_FOLLOW(a) | ||
1992 | #endif | ||
1993 | |||
1988 | #define readlink_trivial_usage \ | 1994 | #define readlink_trivial_usage \ |
1989 | "" | 1995 | USAGE_READLINK_FOLLOW("[-f] ") "FILE" |
1990 | #define readlink_full_usage \ | 1996 | #define readlink_full_usage \ |
1991 | "Displays the value of a symbolic link." | 1997 | "Displays the value of a symbolic link." \ |
1998 | USAGE_READLINK_FOLLOW("\n\nOptions:\n" \ | ||
1999 | "\t-f\tcanonicalize by following all symlinks") | ||
1992 | 2000 | ||
1993 | #define realpath_trivial_usage \ | 2001 | #define realpath_trivial_usage \ |
1994 | "pathname ..." | 2002 | "pathname ..." |