last_patch95 from vodz:
[oweals/busybox.git] / findutils / xargs.c
index 677618dc062bbb032afbf00dc4b9c3823bae670a..2b18f8f28fd5f31d2caba41224129afa90ea0c52 100644 (file)
@@ -53,11 +53,11 @@ static void xargs_exec(char * const * args)
                        wait(NULL);
                        if(common[0]) {
                                errno = common[0];
-                               perror_msg_and_die("%s", args[0]);
+                               bb_perror_msg_and_die("%s", args[0]);
                        }
                }
        } else {
-               perror_msg_and_die("vfork");
+               bb_perror_msg_and_die("vfork");
        }
 }
 
@@ -66,24 +66,13 @@ int xargs_main(int argc, char **argv)
        char *file_to_act_on;
        char **args;
        int  i, a;
-       char flg_vi       = 0;    /* verbose |& interactive */
-       char flg_no_empty = 0;
+       char flg_vi;            /* verbose |& interactive */
+       char flg_no_empty;
 
-       while ((a = getopt(argc, argv, "prt")) > 0) {
-               switch(a) {
-                       case 'p':
-                               flg_vi |= 3;
-                               break;
-                       case 't':
-                               flg_vi |= 1;
-                               break;
-                       case 'r':
-                               flg_no_empty = 1;
-                               break;
-                       default:
-                               show_usage();
-               }
-       }
+       bb_opt_complementaly = "pt";
+       a = bb_getopt_ulflags(argc, argv, "tpr");
+       flg_vi = a & 3;
+       flg_no_empty = a & 4;
 
        a = argc - optind;
        argv += optind;
@@ -101,9 +90,7 @@ int xargs_main(int argc, char **argv)
 
        /* Now, read in one line at a time from stdin, and store this 
         * line to be used later as an argument to the command */
-       while ((file_to_act_on = get_line_from_file(stdin)) != NULL) {
-               /* eat the newline off the filename. */
-               chomp(file_to_act_on);
+       while ((file_to_act_on = bb_get_chomped_line_from_file(stdin)) != NULL) {
                if(file_to_act_on[0] != 0 || flg_no_empty == 0) {
                        args[a] = file_to_act_on[0] ? file_to_act_on : NULL;
                        if(flg_vi) {
@@ -112,9 +99,9 @@ int xargs_main(int argc, char **argv)
                                                fputc(' ', stderr);
                                        fputs(args[i], stderr);
                                }
-                               fprintf(stderr, "%s", ((flg_vi & 2) ? " ?..." : "\n"));
+                               fputs(((flg_vi & 2) ? " ?..." : "\n"), stderr);
                        }
-                       if((flg_vi & 2) == 0 || ask_confirmation() != 0 ) {
+                       if((flg_vi & 2) == 0 || bb_ask_confirmation() != 0 ) {
                                xargs_exec(args);
                        }
                }