From d89882da164d4e4f3506a85f27f3fd2bdd7b810a Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Mon, 25 Sep 2000 22:53:05 +0000 Subject: Some more polish to make xargs act like GNU xargs (thanks to kent robotti for testing and pointing out the differences) -Erik --- findutils/xargs.c | 11 ++++++----- xargs.c | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/findutils/xargs.c b/findutils/xargs.c index 4a3fe3c60..beada7a15 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c @@ -38,7 +38,7 @@ int xargs_main(int argc, char **argv) char *args = NULL; char *cmd_to_be_executed = NULL; char traceflag = 0; - int len_args=10, len_cmd_to_be_executed, opt; + int len_args=2, len_cmd_to_be_executed, opt; pid_t pid; int wpid, status; @@ -69,9 +69,11 @@ int xargs_main(int argc, char **argv) strcat(cmd_to_be_executed, *argv); } + args=xrealloc(args, len_args); + strcpy(args, " "); - /* Now, read in one line at a time from stdin, and stroe this to be used later - * as an argument to the command we just stored */ + /* Now, read in one line at a time from stdin, and store this + * line to be used later as an argument to the command */ in_from_stdin = get_line_from_file(stdin); for (;in_from_stdin!=NULL;) { char *tmp; @@ -111,8 +113,7 @@ int xargs_main(int argc, char **argv) } if (traceflag==1) { - fputs(cmd_to_be_executed, stderr); - fputs(args, stderr); + fprintf(stderr, "%s%s\n", cmd_to_be_executed, args); } if ((pid = fork()) == 0) { diff --git a/xargs.c b/xargs.c index 4a3fe3c60..beada7a15 100644 --- a/xargs.c +++ b/xargs.c @@ -38,7 +38,7 @@ int xargs_main(int argc, char **argv) char *args = NULL; char *cmd_to_be_executed = NULL; char traceflag = 0; - int len_args=10, len_cmd_to_be_executed, opt; + int len_args=2, len_cmd_to_be_executed, opt; pid_t pid; int wpid, status; @@ -69,9 +69,11 @@ int xargs_main(int argc, char **argv) strcat(cmd_to_be_executed, *argv); } + args=xrealloc(args, len_args); + strcpy(args, " "); - /* Now, read in one line at a time from stdin, and stroe this to be used later - * as an argument to the command we just stored */ + /* Now, read in one line at a time from stdin, and store this + * line to be used later as an argument to the command */ in_from_stdin = get_line_from_file(stdin); for (;in_from_stdin!=NULL;) { char *tmp; @@ -111,8 +113,7 @@ int xargs_main(int argc, char **argv) } if (traceflag==1) { - fputs(cmd_to_be_executed, stderr); - fputs(args, stderr); + fprintf(stderr, "%s%s\n", cmd_to_be_executed, args); } if ((pid = fork()) == 0) { -- cgit v1.2.3