Browse Source

LibC: Implement __fpurge

Tim Schumacher 4 năm trước cách đây
mục cha
commit
ccef5fe234

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

@@ -40,6 +40,7 @@ public:
     void setbuf(u8* data, int mode, size_t size) { m_buffer.setbuf(data, mode, size); }
     void setbuf(u8* data, int mode, size_t size) { m_buffer.setbuf(data, mode, size); }
 
 
     bool flush();
     bool flush();
+    void purge();
     bool close();
     bool close();
 
 
     int fileno() const { return m_fd; }
     int fileno() const { return m_fd; }
@@ -192,6 +193,11 @@ bool FILE::flush()
     return true;
     return true;
 }
 }
 
 
+void FILE::purge()
+{
+    m_buffer.drop();
+}
+
 ssize_t FILE::do_read(u8* data, size_t size)
 ssize_t FILE::do_read(u8* data, size_t size)
 {
 {
     int nread = ::read(m_fd, data, size);
     int nread = ::read(m_fd, data, size);
@@ -1323,4 +1329,10 @@ int __fwriting(FILE* stream)
 
 
     return (stream->flags() & FILE::Flags::LastWrite);
     return (stream->flags() & FILE::Flags::LastWrite);
 }
 }
+
+void __fpurge(FILE* stream)
+{
+    ScopedFileLock lock(stream);
+    stream->purge();
+}
 }
 }

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

@@ -12,5 +12,6 @@ __BEGIN_DECLS
 
 
 int __freading(FILE*);
 int __freading(FILE*);
 int __fwriting(FILE*);
 int __fwriting(FILE*);
+void __fpurge(FILE*);
 
 
 __END_DECLS
 __END_DECLS