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 = 0; /* verbose |& interactive */
70 char flg_no_empty = 0;
72 while ((a = getopt(argc, argv, "prt")) > 0) {
91 /* default behavior is to echo all the filenames */
95 /* allocating pointers for execvp: a*arg, arg from stdin, NULL */
96 args = xcalloc(a + 3, sizeof(char *));
98 /* Store the command to be executed (taken from the command line) */
99 for (i = 0; i < a; i++)
102 /* Now, read in one line at a time from stdin, and store this
103 * line to be used later as an argument to the command */
104 while ((file_to_act_on = bb_get_chomped_line_from_file(stdin)) != NULL) {
105 if(file_to_act_on[0] != 0 || flg_no_empty == 0) {
106 args[a] = file_to_act_on[0] ? file_to_act_on : NULL;
108 for(i=0; args[i]; i++) {
111 fputs(args[i], stderr);
113 fprintf(stderr, "%s", ((flg_vi & 2) ? " ?..." : "\n"));
115 if((flg_vi & 2) == 0 || bb_ask_confirmation() != 0 ) {
120 free(file_to_act_on);
122 #ifdef CONFIG_FEATURE_CLEAN_UP