aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-09-30 17:15:40 -0700
committerRob Landley <rob@landley.net>2019-10-02 12:13:48 -0500
commit8851737bedef88ddc42a6a63aec5a70e41260377 (patch)
treed11df18cc7bfc17bf5565b9c84bd94690cfc24ae
parent1103c843a6b9213c6cf89449ff55a8c959dca910 (diff)
downloadtoybox-8851737bedef88ddc42a6a63aec5a70e41260377.tar.gz
readlink: support multiple arguments.
Required by the new `ln -t` test if it's to pass on an all-toybox system :-)
-rw-r--r--toys/other/readlink.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/toys/other/readlink.c b/toys/other/readlink.c
index beef92b0..eb63d7f4 100644
--- a/toys/other/readlink.c
+++ b/toys/other/readlink.c
@@ -8,7 +8,7 @@ config READLINK
bool "readlink"
default y
help
- usage: readlink FILE
+ usage: readlink FILE...
With no options, show what symlink points to, return error if not symlink.
@@ -26,17 +26,18 @@ config READLINK
void readlink_main(void)
{
- char *s;
-
- // Calculating full canonical path?
- // Take advantage of flag positions to calculate m = -1, f = 0, e = 1
- if (toys.optflags & (FLAG_f|FLAG_e|FLAG_m))
- s = xabspath(*toys.optargs, (toys.optflags&(FLAG_f|FLAG_e))-1);
- else s = xreadlink(*toys.optargs);
-
- if (s) {
- if (!(toys.optflags & FLAG_q))
- xprintf((toys.optflags & FLAG_n) ? "%s" : "%s\n", s);
- if (CFG_TOYBOX_FREE) free(s);
- } else toys.exitval = 1;
+ char **arg, *s;
+
+ for (arg = toys.optargs; *arg; arg++) {
+ // Calculating full canonical path?
+ // Take advantage of flag positions to calculate m = -1, f = 0, e = 1
+ if (toys.optflags & (FLAG_f|FLAG_e|FLAG_m))
+ s = xabspath(*arg, (toys.optflags&(FLAG_f|FLAG_e))-1);
+ else s = xreadlink(*arg);
+
+ if (s) {
+ if (!FLAG(q)) xprintf(FLAG(n) ? "%s" : "%s\n", s);
+ if (CFG_TOYBOX_FREE) free(s);
+ } else toys.exitval = 1;
+ }
}