[libcxx-commits] [PATCH] D58732: [libcxx] Portability fix: close an open file stream before removing the file.

Andrey Maksimov via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 27 11:54:31 PST 2019


amakc11 created this revision.
amakc11 added a reviewer: ldionne.
Herald added a reviewer: EricWF.
Herald added a subscriber: libcxx-commits.

The C standard says the following in the specification of the `remove` function: "If the file is open, the behavior of the remove function is implementation-defined". The recently added test `fopen`s a file, but does not close it before calling the `std::remove` function on this file, thus making this test dependent on the type of filesystem used for running the test suite. This patch adds the missing `std::fclose` call. BTW, it's a good practice of clean programming.


Repository:
  rCXX libc++

https://reviews.llvm.org/D58732

Files:
  test/std/input.output/stream.buffers/streambuf/streambuf.virtuals/streambuf.virt.put/xsputn.PR14074.pass.cpp


Index: test/std/input.output/stream.buffers/streambuf/streambuf.virtuals/streambuf.virt.put/xsputn.PR14074.pass.cpp
===================================================================
--- test/std/input.output/stream.buffers/streambuf/streambuf.virtuals/streambuf.virt.put/xsputn.PR14074.pass.cpp
+++ test/std/input.output/stream.buffers/streambuf/streambuf.virtuals/streambuf.virt.put/xsputn.PR14074.pass.cpp
@@ -34,6 +34,7 @@
     std::size_t count = 0;
     while (std::fgetc(f) != EOF)
         ++count;
+    std::fclose(f);
     return count;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58732.188589.patch
Type: text/x-patch
Size: 553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190227/acdfdcec/attachment.bin>


More information about the libcxx-commits mailing list