[hackers] [sbase] find: Fix flushing input buffer with -ok || Wolfgang Corcoran-Mathe

From: <git_AT_suckless.org>
Date: Thu, 18 Jun 2015 15:24:19 +0200 (CEST)

commit cf769f2d8de2fd992fafcfd5ca4984af6d481a15
Author: Wolfgang Corcoran-Mathe <first.lord.of.teal_AT_gmail.com>
Date: Mon Jun 15 15:27:37 2015 -0400

    find: Fix flushing input buffer with -ok
    
    The original flush-stdin loop (with fgets()) hung until the user
    entered some extraneous characters for it to kill.
    
    emg's FIXME about nulls still applies.

diff --git a/find.c b/find.c
index e9d8c1d..35fab5f 100644
--- a/find.c
+++ b/find.c
_AT_@ -408,16 +408,16 @@ pri_ok(struct arg *arg)
 {
         int status, reply;
         pid_t pid;
- char ***brace, buf[256];
+ char ***brace, c;
         struct okarg *o = arg->extra.p;
 
         fprintf(stderr, "%s: %s ?", *o->argv, arg->path);
         reply = fgetc(stdin);
 
         /* throw away rest of line */
- while (fgets(buf, sizeof(buf), stdin) && *buf && buf[strlen(buf) - 1] == '\n')
+ while ((c = fgetc(stdin)) != '\n' && c != EOF)
                 /* FIXME: what if the first character of the rest of the line is a null
- * byte? probably shouldn't juse fgets() */
+ * byte? */
                 ;
 
         if (feof(stdin)) /* FIXME: ferror()? */
Received on Thu Jun 18 2015 - 15:24:19 CEST

This archive was generated by hypermail 2.3.0 : Thu Jun 18 2015 - 17:37:38 CEST