Ver Fonte

LibC: Implement __fpurge

Tim Schumacher há 4 anos atrás
pai
commit
ccef5fe234
2 ficheiros alterados com 13 adições e 0 exclusões
  1. 12 0
      Userland/Libraries/LibC/stdio.cpp
  2. 1 0
      Userland/Libraries/LibC/stdio_ext.h

+ 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); }
 
     bool flush();
+    void purge();
     bool close();
 
     int fileno() const { return m_fd; }
@@ -192,6 +193,11 @@ bool FILE::flush()
     return true;
 }
 
+void FILE::purge()
+{
+    m_buffer.drop();
+}
+
 ssize_t FILE::do_read(u8* data, size_t size)
 {
     int nread = ::read(m_fd, data, size);
@@ -1323,4 +1329,10 @@ int __fwriting(FILE* stream)
 
     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 __fwriting(FILE*);
+void __fpurge(FILE*);
 
 __END_DECLS