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:
parent
f89944e804
commit
8b0d530584
1 changed files with 9 additions and 11 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue