Add /dev/{stdin,stdout,stderr} as symlinks to /proc/self/fd/{0,1,2}

Also change /bin/cat to open /dev/stdin if no arguments are provided.
This commit is contained in:
Andreas Kling 2019-02-03 12:38:03 +01:00
parent 5e9ba2ac84
commit 31f44481f3
Notes: sideshowbarker 2024-07-19 15:52:53 +09:00
2 changed files with 6 additions and 6 deletions

View File

@ -13,6 +13,9 @@ mknod mnt/dev/psaux c 10 1
mknod mnt/dev/ptmx c 5 2
mkdir mnt/dev/pts
mknod mnt/dev/gui_events c 66 1
ln -s /proc/self/fd/0 mnt/dev/stdin
ln -s /proc/self/fd/1 mnt/dev/stdout
ln -s /proc/self/fd/2 mnt/dev/stderr
cp -vR ../Base/* mnt/
chown -vR 100:100 mnt/users/anon
cp -v ../Userland/sh mnt/bin/sh

View File

@ -8,13 +8,10 @@
int main(int argc, char** argv)
{
if (argc != 2) {
printf("usage: cat <file>\n");
return 1;
}
int fd = open(argv[1], O_RDONLY);
const char* input_file = argc > 1 ? argv[1] : "/dev/stdin";
int fd = open(input_file, O_RDONLY);
if (fd == -1) {
printf("failed to open %s: %s\n", argv[1], strerror(errno));
printf("failed to open %s: %s\n", input_file, strerror(errno));
return 1;
}
for (;;) {