LibC: Partially implement __fpending

This commit is contained in:
Tim Schumacher 2021-05-27 12:47:01 +02:00 committed by Brian Gianforcaro
parent 304dbb0242
commit 4917a610ab
Notes: sideshowbarker 2024-07-17 23:07:41 +09:00
3 changed files with 18 additions and 0 deletions

View File

@ -31,6 +31,7 @@ public:
bool flush();
void purge();
size_t pending();
bool close();
void lock();

View File

@ -102,6 +102,16 @@ void FILE::purge()
m_buffer.drop();
}
size_t FILE::pending()
{
if (m_mode & O_RDONLY) {
return 0;
}
// FIXME: Check if our buffer is a write buffer, and only count those bytes.
return m_buffer.buffered_size();
}
ssize_t FILE::do_read(u8* data, size_t size)
{
int nread = ::read(m_fd, data, size);
@ -1279,6 +1289,12 @@ FILE* tmpfile()
return fdopen(fd, "rw");
}
size_t __fpending(FILE* stream)
{
ScopedFileLock lock(stream);
return stream->pending();
}
int __freading(FILE* stream)
{
ScopedFileLock lock(stream);

View File

@ -10,6 +10,7 @@
__BEGIN_DECLS
size_t __fpending(FILE*);
int __freading(FILE*);
int __fwriting(FILE*);
void __fpurge(FILE*);