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.
This commit is contained in:
parent
1490b37bd2
commit
cf769f2d8d
6
find.c
6
find.c
|
@ -408,16 +408,16 @@ pri_ok(struct arg *arg)
|
||||||
{
|
{
|
||||||
int status, reply;
|
int status, reply;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
char ***brace, buf[256];
|
char ***brace, c;
|
||||||
struct okarg *o = arg->extra.p;
|
struct okarg *o = arg->extra.p;
|
||||||
|
|
||||||
fprintf(stderr, "%s: %s ?", *o->argv, arg->path);
|
fprintf(stderr, "%s: %s ?", *o->argv, arg->path);
|
||||||
reply = fgetc(stdin);
|
reply = fgetc(stdin);
|
||||||
|
|
||||||
/* throw away rest of line */
|
/* 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
|
/* 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()? */
|
if (feof(stdin)) /* FIXME: ferror()? */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user