mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:07:44 +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 <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
@ -10,11 +11,12 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
fgets(buf, sizeof(buf), stdin);
|
auto* str = fgets(buf, sizeof(buf), stdin);
|
||||||
if (strstr(buf, argv[1]))
|
if (str && strstr(str, argv[1]))
|
||||||
write(1, buf, strlen(buf));
|
write(1, buf, strlen(buf));
|
||||||
if (feof(stdin))
|
if (feof(stdin))
|
||||||
return 0;
|
return 0;
|
||||||
|
ASSERT(str);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue