1
Fork 0
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:
Andreas Kling 2019-04-25 14:07:17 +02:00
parent d5578826af
commit aa84e2fc64

View file

@ -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;
}