Some more polish to make xargs act like GNU xargs (thanks to kent robotti

<robotti@metconnect.com> for testing and pointing out the differences)
 -Erik
This commit is contained in:
Eric Andersen 2000-09-25 22:53:05 +00:00
parent 3570a34de4
commit d89882da16
2 changed files with 12 additions and 10 deletions

View File

@ -38,7 +38,7 @@ int xargs_main(int argc, char **argv)
char *args = NULL; char *args = NULL;
char *cmd_to_be_executed = NULL; char *cmd_to_be_executed = NULL;
char traceflag = 0; 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; pid_t pid;
int wpid, status; int wpid, status;
@ -69,9 +69,11 @@ int xargs_main(int argc, char **argv)
strcat(cmd_to_be_executed, *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 /* Now, read in one line at a time from stdin, and store this
* as an argument to the command we just stored */ * line to be used later as an argument to the command */
in_from_stdin = get_line_from_file(stdin); in_from_stdin = get_line_from_file(stdin);
for (;in_from_stdin!=NULL;) { for (;in_from_stdin!=NULL;) {
char *tmp; char *tmp;
@ -111,8 +113,7 @@ int xargs_main(int argc, char **argv)
} }
if (traceflag==1) { if (traceflag==1) {
fputs(cmd_to_be_executed, stderr); fprintf(stderr, "%s%s\n", cmd_to_be_executed, args);
fputs(args, stderr);
} }
if ((pid = fork()) == 0) { if ((pid = fork()) == 0) {

11
xargs.c
View File

@ -38,7 +38,7 @@ int xargs_main(int argc, char **argv)
char *args = NULL; char *args = NULL;
char *cmd_to_be_executed = NULL; char *cmd_to_be_executed = NULL;
char traceflag = 0; 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; pid_t pid;
int wpid, status; int wpid, status;
@ -69,9 +69,11 @@ int xargs_main(int argc, char **argv)
strcat(cmd_to_be_executed, *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 /* Now, read in one line at a time from stdin, and store this
* as an argument to the command we just stored */ * line to be used later as an argument to the command */
in_from_stdin = get_line_from_file(stdin); in_from_stdin = get_line_from_file(stdin);
for (;in_from_stdin!=NULL;) { for (;in_from_stdin!=NULL;) {
char *tmp; char *tmp;
@ -111,8 +113,7 @@ int xargs_main(int argc, char **argv)
} }
if (traceflag==1) { if (traceflag==1) {
fputs(cmd_to_be_executed, stderr); fprintf(stderr, "%s%s\n", cmd_to_be_executed, args);
fputs(args, stderr);
} }
if ((pid = fork()) == 0) { if ((pid = fork()) == 0) {