ladybird/Userland/Utilities/fgrep.cpp
Linus Groh 2a940464b8 Userland: Return 1 when help text is shown for insufficient args
ArgsParser also does this, but we don't use that (yet) in a couple of
places. Fix the behaviour manually for consistency.
2021-06-01 21:30:16 +01:00

30 lines
605 B
C++

/*
* 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);
}
return 0;
}