+ ret:
+ *p = '\0';
+ /* store_param(NULL) - caller will do it */
+ dbg_msg("return:'%s'", s);
+ return s;
+}
+#endif /* FEATURE_XARGS_SUPPORT_ZERO_TERM */
+
+#if ENABLE_FEATURE_XARGS_SUPPORT_CONFIRMATION
+/* Prompt the user for a response, and
+ if the user responds affirmatively, return true;
+ otherwise, return false. Uses "/dev/tty", not stdin. */
+static int xargs_ask_confirmation(void)
+{
+ FILE *tty_stream;
+ int c, savec;
+
+ tty_stream = xfopen_for_read(CURRENT_TTY);
+ fputs(" ?...", stderr);
+ fflush_all();
+ c = savec = getc(tty_stream);
+ while (c != EOF && c != '\n')
+ c = getc(tty_stream);
+ fclose(tty_stream);
+ return (savec == 'y' || savec == 'Y');
+}
+#else
+# define xargs_ask_confirmation() 1
+#endif
+
+//usage:#define xargs_trivial_usage
+//usage: "[OPTIONS] [PROG ARGS]"
+//usage:#define xargs_full_usage "\n\n"
+//usage: "Run PROG on every item given by stdin\n"
+//usage: IF_FEATURE_XARGS_SUPPORT_CONFIRMATION(
+//usage: "\n -p Ask user whether to run each command"
+//usage: )
+//usage: "\n -r Don't run command if input is empty"
+//usage: IF_FEATURE_XARGS_SUPPORT_ZERO_TERM(
+//usage: "\n -0 Input is separated by NUL characters"
+//usage: )
+//usage: "\n -t Print the command on stderr before execution"
+//usage: "\n -e[STR] STR stops input processing"
+//usage: "\n -n N Pass no more than N args to PROG"
+//usage: "\n -s N Pass command line of no more than N bytes"
+//usage: IF_FEATURE_XARGS_SUPPORT_TERMOPT(
+//usage: "\n -x Exit if size is exceeded"
+//usage: )
+//usage:#define xargs_example_usage
+//usage: "$ ls | xargs gzip\n"
+//usage: "$ find . -name '*.c' -print | xargs rm\n"
+
+/* Correct regardless of combination of CONFIG_xxx */
+enum {
+ OPTBIT_VERBOSE = 0,
+ OPTBIT_NO_EMPTY,
+ OPTBIT_UPTO_NUMBER,
+ OPTBIT_UPTO_SIZE,
+ OPTBIT_EOF_STRING,
+ OPTBIT_EOF_STRING1,
+ IF_FEATURE_XARGS_SUPPORT_CONFIRMATION(OPTBIT_INTERACTIVE,)
+ IF_FEATURE_XARGS_SUPPORT_TERMOPT( OPTBIT_TERMINATE ,)
+ IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( OPTBIT_ZEROTERM ,)
+
+ OPT_VERBOSE = 1 << OPTBIT_VERBOSE ,
+ OPT_NO_EMPTY = 1 << OPTBIT_NO_EMPTY ,
+ OPT_UPTO_NUMBER = 1 << OPTBIT_UPTO_NUMBER,
+ OPT_UPTO_SIZE = 1 << OPTBIT_UPTO_SIZE ,
+ OPT_EOF_STRING = 1 << OPTBIT_EOF_STRING , /* GNU: -e[<param>] */
+ OPT_EOF_STRING1 = 1 << OPTBIT_EOF_STRING1, /* SUS: -E<param> */
+ OPT_INTERACTIVE = IF_FEATURE_XARGS_SUPPORT_CONFIRMATION((1 << OPTBIT_INTERACTIVE)) + 0,
+ OPT_TERMINATE = IF_FEATURE_XARGS_SUPPORT_TERMOPT( (1 << OPTBIT_TERMINATE )) + 0,
+ OPT_ZEROTERM = IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( (1 << OPTBIT_ZEROTERM )) + 0,
+};
+#define OPTION_STR "+trn:s:e::E:" \
+ IF_FEATURE_XARGS_SUPPORT_CONFIRMATION("p") \
+ IF_FEATURE_XARGS_SUPPORT_TERMOPT( "x") \
+ IF_FEATURE_XARGS_SUPPORT_ZERO_TERM( "0")
+
+int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int xargs_main(int argc, char **argv)
+{
+ int i;
+ int child_error = 0;
+ char *max_args;
+ char *max_chars;
+ char *buf;
+ unsigned opt;
+ int n_max_chars;
+ int n_max_arg;
+#if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM
+ char* FAST_FUNC (*read_args)(int, int, char*) = process_stdin;
+#else
+#define read_args process_stdin
+#endif
+
+ INIT_G();
+
+#if ENABLE_DESKTOP && ENABLE_LONG_OPTS
+ /* For example, Fedora's build system uses --no-run-if-empty */
+ applet_long_options =
+ "no-run-if-empty\0" No_argument "r"
+ ;
+#endif
+ opt = getopt32(argv, OPTION_STR, &max_args, &max_chars, &G.eof_str, &G.eof_str);
+
+ /* -E ""? You may wonder why not just omit -E?
+ * This is used for portability:
+ * old xargs was using "_" as default for -E / -e */
+ if ((opt & OPT_EOF_STRING1) && G.eof_str[0] == '\0')
+ G.eof_str = NULL;
+
+ if (opt & OPT_ZEROTERM)
+ IF_FEATURE_XARGS_SUPPORT_ZERO_TERM(read_args = process0_stdin);