summaryrefslogtreecommitdiff
path: root/Userland/fgrep.cpp
blob: 2d9c7bc5ea8838ce8665606cf442fa9dd637e793 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char** argv)
{
    if (argc < 2) {
        printf("usage: fgrep <str>\n");
        return 0;
    }
    for (;;) {
        char buf[4096];
        fgets(buf, sizeof(buf), stdin);
        if (strstr(buf, argv[1]))
            write(1, buf, strlen(buf));
        if (feof(stdin))
            return 0;
    }
    return 0;
}