aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-10-20 18:36:55 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-10-20 18:36:55 +0000
commit830293e36b928e0e8da6aeaaa3f07b662a2ad80c (patch)
treec33b80a72a22047d49243ea6307de8e19d3a98e2
parent218c3406ad2d9611bcb9c138be7014d24fa62caa (diff)
downloadbusybox-w32-830293e36b928e0e8da6aeaaa3f07b662a2ad80c.tar.gz
busybox-w32-830293e36b928e0e8da6aeaaa3f07b662a2ad80c.tar.bz2
busybox-w32-830293e36b928e0e8da6aeaaa3f07b662a2ad80c.zip
readlink: do not emit errors if file doesnt not exist / not a link
getopt32: add =N support git-svn-id: svn://busybox.net/trunk/busybox@16414 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--debianutils/readlink.c37
-rw-r--r--libbb/getopt32.c9
2 files changed, 33 insertions, 13 deletions
diff --git a/debianutils/readlink.c b/debianutils/readlink.c
index 0d5ad94f4..9536d3200 100644
--- a/debianutils/readlink.c
+++ b/debianutils/readlink.c
@@ -13,21 +13,32 @@
13#include <stdlib.h> 13#include <stdlib.h>
14#include <getopt.h> 14#include <getopt.h>
15 15
16#define READLINK_FLAG_f (1 << 0)
17
18int readlink_main(int argc, char **argv) 16int readlink_main(int argc, char **argv)
19{ 17{
20 char *buf; 18 char *buf;
21 unsigned opt = ENABLE_FEATURE_READLINK_FOLLOW ? 19 char *fname;
22 getopt32(argc, argv, "f") : 0; 20
23 21 USE_FEATURE_READLINK_FOLLOW(
24 if (argc != (ENABLE_FEATURE_READLINK_FOLLOW ? optind + 1 : 2)) 22 unsigned opt;
25 bb_show_usage(); 23 /* We need exactly one non-option argument. */
26 24 opt_complementary = "=1";
27 if (opt & READLINK_FLAG_f) 25 opt = getopt32(argc, argv, "f");
28 buf = realpath(argv[optind], bb_common_bufsiz1); 26 fname = argv[optind];
29 else 27 )
30 buf = xreadlink(argv[ENABLE_FEATURE_READLINK_FOLLOW ? optind : 1]); 28 SKIP_FEATURE_READLINK_FOLLOW(
29 const unsigned opt = 0;
30 if (argc != 2) bb_show_usage();
31 fname = argv[1];
32 )
33
34 /* compat: coreutils readlink reports errors silently via exit code */
35 logmode = LOGMODE_NONE;
36
37 if (opt) {
38 buf = realpath(fname, bb_common_bufsiz1);
39 } else {
40 buf = xreadlink(fname);
41 }
31 42
32 if (!buf) 43 if (!buf)
33 return EXIT_FAILURE; 44 return EXIT_FAILURE;
@@ -36,5 +47,5 @@ int readlink_main(int argc, char **argv)
36 if (ENABLE_FEATURE_CLEAN_UP && buf != bb_common_bufsiz1) 47 if (ENABLE_FEATURE_CLEAN_UP && buf != bb_common_bufsiz1)
37 free(buf); 48 free(buf);
38 49
39 return EXIT_SUCCESS; 50 bb_fflush_stdout_and_exit(EXIT_SUCCESS);
40} 51}
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
index 2f2f0b9e9..73e6b8684 100644
--- a/libbb/getopt32.c
+++ b/libbb/getopt32.c
@@ -188,6 +188,10 @@ Special characters:
188 by a single digit (0-9) means that at least N non-option 188 by a single digit (0-9) means that at least N non-option
189 arguments must be present on the command line 189 arguments must be present on the command line
190 190
191 "=N" An equal sign as the first char in a opt_complementary group followed
192 by a single digit (0-9) means that exactly N non-option
193 arguments must be present on the command line
194
191 "V-" An option with dash before colon or end-of-line results in 195 "V-" An option with dash before colon or end-of-line results in
192 bb_show_usage being called if this option is encountered. 196 bb_show_usage being called if this option is encountered.
193 This is typically used to implement "print verbose usage message 197 This is typically used to implement "print verbose usage message
@@ -400,6 +404,11 @@ getopt32(int argc, char **argv, const char *applet_opts, ...)
400 } 404 }
401 continue; 405 continue;
402 } 406 }
407 if (*s == '=') {
408 min_arg = max_arg = c - '0';
409 s++;
410 continue;
411 }
403 for (on_off = complementary; on_off->opt; on_off++) 412 for (on_off = complementary; on_off->opt; on_off++)
404 if (on_off->opt == *s) 413 if (on_off->opt == *s)
405 break; 414 break;