1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:47:43 +00:00

LibC: fgetc() and pals should return EOF on error or EOF.

This was the reason that "uname | figlet" wasn't working. There was nothing
wrong with the pipe like I kept thinking.
This commit is contained in:
Andreas Kling 2019-02-08 17:49:54 +01:00
parent c9aaf74e1d
commit b365ad4aef

View file

@ -103,8 +103,8 @@ char* fgets(char* buffer, int size, FILE* stream)
for (;;) {
if (nread >= size)
break;
char ch = fgetc(stream);
if (feof(stream))
int ch = fgetc(stream);
if (ch == EOF)
break;
buffer[nread++] = ch;
if (!ch || ch == '\n')
@ -119,7 +119,12 @@ int fgetc(FILE* stream)
{
assert(stream);
char ch;
fread(&ch, sizeof(char), 1, stream);
size_t nread = fread(&ch, sizeof(char), 1, stream);
if (nread <= 0) {
stream->eof = nread == 0;
stream->error = -nread;
return EOF;
}
return ch;
}