From b365ad4aefdc4fb90b79e75778789f450b1bec87 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 8 Feb 2019 17:49:54 +0100 Subject: [PATCH] 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. --- LibC/stdio.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/LibC/stdio.cpp b/LibC/stdio.cpp index d3d4f6df52..ceb4f87095 100644 --- a/LibC/stdio.cpp +++ b/LibC/stdio.cpp @@ -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; }