1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:17:36 +00:00

LibC: fgets() shouldn't stop on '\0'

This commit is contained in:
Andreas Kling 2019-09-11 23:01:55 +02:00
parent f89944e804
commit 8b0d530584

View file

@ -105,24 +105,22 @@ int fflush(FILE* stream)
char* fgets(char* buffer, int size, FILE* stream)
{
assert(stream);
ASSERT(stream);
ASSERT(size);
ssize_t nread = 0;
for (;;) {
if (nread >= size)
break;
while (nread < (size + 1)) {
int ch = fgetc(stream);
if (ch == EOF) {
if (nread == 0)
return nullptr;
if (ch == EOF)
break;
}
buffer[nread++] = ch;
if (!ch || ch == '\n')
if (ch == '\n')
break;
}
if (nread < size)
if (nread) {
buffer[nread] = '\0';
return buffer;
return buffer;
}
return nullptr;
}
int fgetc(FILE* stream)