klibc-bot for H. Peter Anvin
2014-Apr-15 16:36 UTC
[klibc] [klibc:master] readlink: Handle multiple input arguments
Commit-ID: 1ba3e80738407d13bc4a71812578848b6f657e23 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=1ba3e80738407d13bc4a71812578848b6f657e23 Author: H. Peter Anvin <hpa at linux.intel.com> AuthorDate: Tue, 15 Apr 2014 09:34:45 -0700 Committer: H. Peter Anvin <hpa at linux.intel.com> CommitDate: Tue, 15 Apr 2014 09:34:45 -0700 readlink: Handle multiple input arguments Handle multiple links as parguments passed to readlink(). Signed-off-by: H. Peter Anvin <hpa at linux.intel.com> --- usr/utils/readlink.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/usr/utils/readlink.c b/usr/utils/readlink.c index 8b620fd..bf9501b 100644 --- a/usr/utils/readlink.c +++ b/usr/utils/readlink.c @@ -3,11 +3,11 @@ #include <unistd.h> #include <sys/stat.h> -char *progname; +const char *progname; static __noreturn usage(void) { - fprintf(stderr, "Usage: %s link\n", progname); + fprintf(stderr, "Usage: %s link...\n", progname); exit(1); } @@ -16,19 +16,22 @@ int main(int argc, char *argv[]) const char *name; char link_name[PATH_MAX]; int rv; + int i; progname = *argv++; - name = *argv++; - if (!name) + if (argc < 2) usage(); - rv = readlink(name, link_name, sizeof link_name - 1); - if (rv < 0) { - perror(name); - exit(1); + while ((name = *argv++)) { + rv = readlink(name, link_name, sizeof link_name - 1); + if (rv < 0) { + perror(name); + exit(1); + } + link_name[rv] = '\0'; + puts(link_name); } - link_name[rv] = '\0'; - puts(link_name); - exit(0); + + return 0; }