summaryrefslogtreecommitdiff
path: root/Userland/Utilities/fgrep.cpp
blob: cdbbd7bbd955beb4416f66474fee96484f625258 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <AK/Assertions.h>
#include <AK/Format.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

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