Browse Source

LibC: Partially implement __fpending

Tim Schumacher 4 years ago
parent
commit
4917a610ab

+ 1 - 0
Userland/Libraries/LibC/bits/stdio_file_implementation.h

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

+ 16 - 0
Userland/Libraries/LibC/stdio.cpp

@@ -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);

+ 1 - 0
Userland/Libraries/LibC/stdio_ext.h

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