[libcxx-commits] [libcxx] [libc++] Implements filebuf unbuffered. (PR #76629)

Jonathan Wakely via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 5 16:09:55 PST 2024


================
@@ -308,6 +308,43 @@ private:
   state_type __st_;
   state_type __st_last_;
   ios_base::openmode __om_;
+  // There have been no file operations yet, which allows setting unbuffered
+  // I/O mode.
+  static const ios_base::openmode __no_io_operations = ios_base::trunc;
+  // Unbuffered I/O mode has been requested.
+  static const ios_base::openmode __use_unbuffered_io = ios_base::ate;
+  // Used to track the currently used mode and track whether the output should
+  // be unbuffered.
+  // [filebuf.virtuals]/12
+  //   If setbuf(0, 0) is called on a stream before any I/O has occurred on
----------------
jwakely wrote:

I don't know, but I assume the behaviour is supposed to match `std::setvbuf` in C, which of course has to be used after opening the file because otherwise you don't have a `FILE*` to pass to `setvbuf`.

> The `setvbuf` function may be used only after the stream pointed to by stream has been associated
with an open file and before any other operation (other than an unsuccessful call to `setvbuf`) is
performed on the stream.

So I don't think opening the file should be considered an I/O operation.

https://github.com/llvm/llvm-project/pull/76629


More information about the libcxx-commits mailing list