mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 19:10:26 +00:00
Userland: Add a simple /bin/head program.
This commit is contained in:
parent
8effdc807a
commit
b5a1ee1d3e
Notes:
sideshowbarker
2024-07-19 14:35:08 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/b5a1ee1d3e0
1 changed files with 26 additions and 0 deletions
26
Userland/head.cpp
Normal file
26
Userland/head.cpp
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
// FIXME: Allow setting via command-line argument.
|
||||||
|
int line_count = 10;
|
||||||
|
|
||||||
|
if (argc > 1) {
|
||||||
|
for (int i = 1; i < argc; ++i) {
|
||||||
|
if (argv[i][0] == '-') {
|
||||||
|
line_count = atoi(&argv[i][1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int line = 0; line < line_count; ++line) {
|
||||||
|
char buffer[BUFSIZ];
|
||||||
|
auto* str = fgets(buffer, sizeof(buffer), stdin);
|
||||||
|
if (!str)
|
||||||
|
break;
|
||||||
|
fputs(str, stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue