mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 14:58:11 +00:00
LibC: Make fwrite() buffered.
This is a really naive implementation that makes fwrite() call fputc() internally, but it still performs a lot better due to avoiding the write() syscall every time.
This commit is contained in:
parent
52139a2392
commit
d3fb0a56ed
1 changed files with 7 additions and 7 deletions
|
@ -254,13 +254,13 @@ size_t fread(void* ptr, size_t size, size_t nmemb, FILE* stream)
|
||||||
size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream)
|
size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE* stream)
|
||||||
{
|
{
|
||||||
assert(stream);
|
assert(stream);
|
||||||
int rc = fflush(stream);
|
auto* bytes = (const byte*)ptr;
|
||||||
if (rc == EOF)
|
ssize_t nwritten = 0;
|
||||||
return 0;
|
for (size_t i = 0; i < (size * nmemb); ++i) {
|
||||||
ssize_t nwritten = write(stream->fd, ptr, nmemb * size);
|
int rc = fputc(bytes[i], stream);
|
||||||
if (nwritten < 0) {
|
if (rc == EOF)
|
||||||
stream->error = errno;
|
break;
|
||||||
return 0;
|
++nwritten;
|
||||||
}
|
}
|
||||||
return nwritten / size;
|
return nwritten / size;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue