mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:38:13 +00:00
Implement argc/argv support for spawned tasks.
Celebrate the new functionality with a simple /bin/cat implementation. :^)
This commit is contained in:
parent
53abfa7ea1
commit
df87dda63c
13 changed files with 105 additions and 17 deletions
30
Userland/cat.cpp
Normal file
30
Userland/cat.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <LibC/stdio.h>
|
||||
#include <LibC/unistd.h>
|
||||
#include <LibC/errno.h>
|
||||
#include <LibC/string.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
printf("usage: cat <file>\n");
|
||||
return 1;
|
||||
}
|
||||
int fd = open(argv[1]);
|
||||
if (fd == -1) {
|
||||
printf("failed to open %s: %s\n", argv[1], strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
for (;;) {
|
||||
char buf[128];
|
||||
ssize_t nread = read(fd, buf, sizeof(buf));
|
||||
if (nread == 0)
|
||||
break;
|
||||
if (nread < 0) {
|
||||
printf("read() error: %s\n", strerror(errno));
|
||||
return 2;
|
||||
}
|
||||
for (ssize_t i = 0; i < nread; ++i)
|
||||
putchar(buf[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue