Explorar o código

BufferedFile: Flush content on close

Tatsuhiro Tsujikawa %!s(int64=7) %!d(string=hai) anos
pai
achega
431fcde29a
Modificáronse 1 ficheiros con 6 adicións e 0 borrados
  1. 6 0
      src/BufferedFile.cc

+ 6 - 0
src/BufferedFile.cc

@@ -80,6 +80,12 @@ int BufferedFile::onClose()
 {
   int rv = 0;
   if (fp_) {
+    fflush(fp_);
+#ifndef __MINGW32__
+    fsync(fileno(fp_));
+#else  // __MINGW32__
+    _commit(fileno(fp_));
+#endif // __MINGW32__
     rv = fclose(fp_);
     fp_ = nullptr;
   }