+ }
+ return list_arg;
+}
+
+# define READ_ARGS(l, e, nmc, mc) (*read_args)(l, e, nmc, mc)
+# define OPT_INC_0 1 /* future use */
+#else
+# define OPT_INC_0 0 /* future use */
+# define READ_ARGS(l, e, nmc, mc) process_stdin(l, e, nmc, mc)
+#endif /* CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM */
+
+
+#define OPT_VERBOSE (1<<0)
+#define OPT_NO_EMPTY (1<<1)
+#define OPT_UPTO_NUMBER (1<<2)
+#define OPT_UPTO_SIZE (1<<3)
+#define OPT_EOF_STRING (1<<4)
+#ifdef CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION
+#define OPT_INTERACTIVE (1<<5)
+#else
+#define OPT_INTERACTIVE (0) /* require for algorithm &| */
+#endif
+#define OPT_TERMINATE (1<<(5+OPT_INC_P))
+#define OPT_ZEROTERM (1<<(5+OPT_INC_P+OPT_INC_X))
+/* next future
+#define OPT_NEXT_OTHER (1<<(5+OPT_INC_P+OPT_INC_X+OPT_INC_0))
+*/
+
+int xargs_main(int argc, char **argv)
+{
+ char **args;
+ int i, a, n;
+ xlist_t *list = NULL;
+ xlist_t *cur;
+ int child_error = 0;
+ char *max_args, *max_chars;
+ int n_max_arg;
+ size_t n_chars = 0;
+ long orig_arg_max;
+ const char *eof_str = "_";
+ unsigned long opt;
+ size_t n_max_chars;
+
+#ifdef CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM
+ xlist_t *(*read_args) (xlist_t *, const char *, size_t, char *) = process_stdin;
+#endif
+
+#ifdef CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION
+ bb_opt_complementally = "pt";
+#endif
+
+ opt = bb_getopt_ulflags(argc, argv, "+trn:s:e::"
+#ifdef CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION
+ "p"
+#endif
+#ifdef CONFIG_FEATURE_XARGS_SUPPORT_TERMOPT
+ "x"
+#endif
+#ifdef CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM
+ "0"
+#endif
+ ,&max_args, &max_chars, &eof_str);
+
+ a = argc - optind;
+ argv += optind;
+ if (a == 0) {
+ /* default behavior is to echo all the filenames */
+ *argv = "echo";
+ a++;
+ }
+
+ orig_arg_max = ARG_MAX;
+ if (orig_arg_max == -1)
+ orig_arg_max = LONG_MAX;
+ orig_arg_max -= 2048; /* POSIX.2 requires subtracting 2048. */
+ if ((opt & OPT_UPTO_SIZE)) {
+ n_max_chars = bb_xgetularg10_bnd(max_chars, 1, orig_arg_max);
+ for (i = 0; i < a; i++) {
+ n_chars += strlen(*argv) + 1;
+ }
+ if (n_max_chars < n_chars) {
+ bb_error_msg_and_die("can not fit single argument within argument list size limit");
+ }
+ n_max_chars -= n_chars;
+ } else {
+ /* Sanity check for systems with huge ARG_MAX defines (e.g., Suns which
+ have it at 1 meg). Things will work fine with a large ARG_MAX but it
+ will probably hurt the system more than it needs to; an array of this
+ size is allocated. */
+ if (orig_arg_max > 20 * 1024)
+ orig_arg_max = 20 * 1024;
+ n_max_chars = orig_arg_max;
+ }
+ max_chars = xmalloc(n_max_chars);