1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:17:35 +00:00

Add some simple write buffering to LibC's stdio.

Plumb it all the way to the VirtualConsole. Also fix /bin/cat to write()
the whole chunks we get from read() directly to stdout.
This commit is contained in:
Andreas Kling 2018-11-08 01:23:23 +01:00
parent e287f8ef3a
commit da3857b0c2
10 changed files with 42 additions and 22 deletions

View file

@ -17,7 +17,7 @@ int main(int argc, char** argv)
return 1;
}
for (;;) {
char buf[1024];
char buf[4096];
ssize_t nread = read(fd, buf, sizeof(buf));
if (nread == 0)
break;
@ -25,8 +25,7 @@ int main(int argc, char** argv)
printf("read() error: %s\n", strerror(errno));
return 2;
}
for (ssize_t i = 0; i < nread; ++i)
putchar(buf[i]);
write(1, buf, nread);
}
return 0;
}

View file

@ -25,6 +25,7 @@ static void prompt()
printf("# ");
else
printf("\033[31;1m%s\033[0m@\033[37;1m%s\033[0m:\033[32;1m%s\033[0m$> ", g->username.characters(), g->hostname, g->cwd.characters());
fflush(stdout);
}
static int sh_pwd(int, const char**)
@ -347,6 +348,7 @@ int main(int, char**)
}
for (ssize_t i = 0; i < nread; ++i) {
putchar(keybuf[i]);
fflush(stdout);
if (keybuf[i] != '\n') {
linebuf[linedx++] = keybuf[i];
linebuf[linedx] = '\0';