diff options
-rw-r--r-- | coreutils/readlink.c | 33 | ||||
-rw-r--r-- | include/usage.h | 7 |
2 files changed, 33 insertions, 7 deletions
diff --git a/coreutils/readlink.c b/coreutils/readlink.c index 8d4456214..20df38b96 100644 --- a/coreutils/readlink.c +++ b/coreutils/readlink.c | |||
@@ -6,9 +6,31 @@ | |||
6 | * | 6 | * |
7 | * Licensed under GPL v2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPL v2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | |||
10 | #include "libbb.h" | 9 | #include "libbb.h" |
11 | 10 | ||
11 | /* | ||
12 | * # readlink --version | ||
13 | * readlink (GNU coreutils) 6.10 | ||
14 | * # readlink --help | ||
15 | * -f, --canonicalize | ||
16 | * canonicalize by following every symlink in | ||
17 | * every component of the given name recursively; | ||
18 | * all but the last component must exist | ||
19 | * -e, --canonicalize-existing | ||
20 | * canonicalize by following every symlink in | ||
21 | * every component of the given name recursively, | ||
22 | * all components must exist | ||
23 | * -m, --canonicalize-missing | ||
24 | * canonicalize by following every symlink in | ||
25 | * every component of the given name recursively, | ||
26 | * without requirements on components existence | ||
27 | * -n, --no-newline do not output the trailing newline | ||
28 | * -q, --quiet, -s, --silent suppress most error messages | ||
29 | * -v, --verbose report error messages | ||
30 | * | ||
31 | * bbox supports: -f -n -v (fully), -q -s (accepts but ignores) | ||
32 | */ | ||
33 | |||
12 | int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 34 | int readlink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
13 | int readlink_main(int argc UNUSED_PARAM, char **argv) | 35 | int readlink_main(int argc UNUSED_PARAM, char **argv) |
14 | { | 36 | { |
@@ -20,7 +42,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) | |||
20 | unsigned opt; | 42 | unsigned opt; |
21 | /* We need exactly one non-option argument. */ | 43 | /* We need exactly one non-option argument. */ |
22 | opt_complementary = "=1"; | 44 | opt_complementary = "=1"; |
23 | opt = getopt32(argv, "f"); | 45 | opt = getopt32(argv, "fnvsq"); |
24 | fname = argv[optind]; | 46 | fname = argv[optind]; |
25 | ) | 47 | ) |
26 | IF_NOT_FEATURE_READLINK_FOLLOW( | 48 | IF_NOT_FEATURE_READLINK_FOLLOW( |
@@ -30,9 +52,10 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) | |||
30 | ) | 52 | ) |
31 | 53 | ||
32 | /* compat: coreutils readlink reports errors silently via exit code */ | 54 | /* compat: coreutils readlink reports errors silently via exit code */ |
33 | logmode = LOGMODE_NONE; | 55 | if (!(opt & 4)) /* not -v */ |
56 | logmode = LOGMODE_NONE; | ||
34 | 57 | ||
35 | if (opt) { | 58 | if (opt & 1) { /* -f */ |
36 | buf = realpath(fname, pathbuf); | 59 | buf = realpath(fname, pathbuf); |
37 | } else { | 60 | } else { |
38 | buf = xmalloc_readlink_or_warn(fname); | 61 | buf = xmalloc_readlink_or_warn(fname); |
@@ -40,7 +63,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) | |||
40 | 63 | ||
41 | if (!buf) | 64 | if (!buf) |
42 | return EXIT_FAILURE; | 65 | return EXIT_FAILURE; |
43 | puts(buf); | 66 | printf((opt & 2) ? "%s" : "%s\n", buf); |
44 | 67 | ||
45 | if (ENABLE_FEATURE_CLEAN_UP && !opt) | 68 | if (ENABLE_FEATURE_CLEAN_UP && !opt) |
46 | free(buf); | 69 | free(buf); |
diff --git a/include/usage.h b/include/usage.h index e6069259b..6fb31e260 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -3466,12 +3466,15 @@ | |||
3466 | "files do not block on disk I/O" | 3466 | "files do not block on disk I/O" |
3467 | 3467 | ||
3468 | #define readlink_trivial_usage \ | 3468 | #define readlink_trivial_usage \ |
3469 | IF_FEATURE_READLINK_FOLLOW("[-f] ") "FILE" | 3469 | IF_FEATURE_READLINK_FOLLOW("[-fnv] ") "FILE" |
3470 | #define readlink_full_usage "\n\n" \ | 3470 | #define readlink_full_usage "\n\n" \ |
3471 | "Display the value of a symlink" \ | 3471 | "Display the value of a symlink" \ |
3472 | IF_FEATURE_READLINK_FOLLOW( "\n" \ | 3472 | IF_FEATURE_READLINK_FOLLOW( "\n" \ |
3473 | "\nOptions:" \ | 3473 | "\nOptions:" \ |
3474 | "\n -f Canonicalize by following all symlinks") \ | 3474 | "\n -f Canonicalize by following all symlinks" \ |
3475 | "\n -n Don't add newline" \ | ||
3476 | "\n -v Verbose" \ | ||
3477 | ) \ | ||
3475 | 3478 | ||
3476 | #define readprofile_trivial_usage \ | 3479 | #define readprofile_trivial_usage \ |
3477 | "[OPTIONS]..." | 3480 | "[OPTIONS]..." |