mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:27:35 +00:00
fgrep: Don't repeat old incoming data if fgets() failed.
This commit is contained in:
parent
d5578826af
commit
aa84e2fc64
1 changed files with 4 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -10,11 +11,12 @@ int main(int argc, char** argv)
|
|||
}
|
||||
for (;;) {
|
||||
char buf[4096];
|
||||
fgets(buf, sizeof(buf), stdin);
|
||||
if (strstr(buf, argv[1]))
|
||||
auto* str = fgets(buf, sizeof(buf), stdin);
|
||||
if (str && strstr(str, argv[1]))
|
||||
write(1, buf, strlen(buf));
|
||||
if (feof(stdin))
|
||||
return 0;
|
||||
ASSERT(str);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue