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:
parent
c9aaf74e1d
commit
b365ad4aef
1 changed files with 8 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue