{
streamsize __ret = 0;
// Optimization in the always_noconv() case, to be generalized in the
- // future: when __n is sufficiently large we write directly instead of
- // using the buffer.
+ // future: when __n is larger than the available capacity we write
+ // directly instead of using the buffer.
const bool __testout = (_M_mode & ios_base::out
|| _M_mode & ios_base::app);
if (__check_facet(_M_codecvt).always_noconv()
&& __testout && !_M_reading)
{
- // Measurement would reveal the best choice.
- const streamsize __chunk = 1ul << 10;
streamsize __bufavail = this->epptr() - this->pptr();
// Don't mistake 'uncommitted' mode buffered with unbuffered.
if (!_M_writing && _M_buf_size > 1)
__bufavail = _M_buf_size - 1;
- const streamsize __limit = std::min(__chunk, __bufavail);
- if (__n >= __limit)
+ if (__n >= __bufavail)
{
const streamsize __buffill = this->pptr() - this->pbase();
const char* __buf = reinterpret_cast<const char*>(this->pbase());
--- /dev/null
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+class testbuf : public std::filebuf {
+public:
+ char_type* pub_pprt() const
+ {
+ return this->pptr();
+ }
+
+ char_type* pub_pbase() const
+ {
+ return this->pbase();
+ }
+};
+
+void test01()
+{
+ using namespace std;
+
+ // Leave capacity to avoid flush.
+ const streamsize chunk_size = BUFSIZ - 1 - 1;
+ const char data[chunk_size] = {};
+
+ testbuf a_f;
+ VERIFY( a_f.open("tmp_63746_sputn", ios_base::out) );
+ VERIFY( chunk_size == a_f.sputn(data, chunk_size) );
+ VERIFY( (a_f.pub_pprt() - a_f.pub_pbase()) == chunk_size );
+ VERIFY( a_f.close() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}