From 8851737bedef88ddc42a6a63aec5a70e41260377 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 30 Sep 2019 17:15:40 -0700 Subject: readlink: support multiple arguments. Required by the new `ln -t` test if it's to pass on an all-toybox system :-) --- toys/other/readlink.c | 29 +++++++++++++++-------------- 1 file 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; + } } -- cgit v1.2.3