1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 00:47:34 +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 (;;) { for (;;) {
if (nread >= size) if (nread >= size)
break; break;
char ch = fgetc(stream); int ch = fgetc(stream);
if (feof(stream)) if (ch == EOF)
break; break;
buffer[nread++] = ch; buffer[nread++] = ch;
if (!ch || ch == '\n') if (!ch || ch == '\n')
@ -119,7 +119,12 @@ int fgetc(FILE* stream)
{ {
assert(stream); assert(stream);
char ch; 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; return ch;
} }