2 * Mini xargs implementation for busybox
3 * Only "-prt" options are supported in this version of xargs.
5 * (C) 2002 by Vladimir Oleynik <dzo@simtreas.ru>
7 * Special thanks Mark Whitley for stimul to rewrote :)
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include <sys/types.h>
36 This function have special algorithm.
37 Don`t use fork and include to main!
39 static void xargs_exec(char * const * args)
42 int common[4]; /* shared vfork stack */
45 if ((p = vfork()) >= 0) {
48 execvp(args[0], args);
49 common[0] = errno; /* set error to shared stack */
56 bb_perror_msg_and_die("%s", args[0]);
60 bb_perror_msg_and_die("vfork");
64 int xargs_main(int argc, char **argv)
69 char flg_vi; /* verbose |& interactive */
72 bb_opt_complementaly = "pt";
73 a = bb_getopt_ulflags(argc, argv, "tpr");
80 /* default behavior is to echo all the filenames */
84 /* allocating pointers for execvp: a*arg, arg from stdin, NULL */
85 args = xcalloc(a + 3, sizeof(char *));
87 /* Store the command to be executed (taken from the command line) */
88 for (i = 0; i < a; i++)
91 /* Now, read in one line at a time from stdin, and store this
92 * line to be used later as an argument to the command */
93 while ((file_to_act_on = bb_get_chomped_line_from_file(stdin)) != NULL) {
94 if(file_to_act_on[0] != 0 || flg_no_empty == 0) {
95 args[a] = file_to_act_on[0] ? file_to_act_on : NULL;
97 for(i=0; args[i]; i++) {
100 fputs(args[i], stderr);
102 fputs(((flg_vi & 2) ? " ?..." : "\n"), stderr);
104 if((flg_vi & 2) == 0 || bb_ask_confirmation() != 0 ) {
109 free(file_to_act_on);
111 #ifdef CONFIG_FEATURE_CLEAN_UP