Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions libcxx/include/fstream
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,14 @@ private:
}
}
}

_LIBCPP_HIDE_FROM_ABI typename traits_type::int_type __overflow_failed() {
if (this->pptr() == this->epptr() + 1) {
this->pbump(-1); // lose the character we overflowed above -- we don't really have a
// choice since we couldn't commit the contents of the put area
}
return traits_type::eof();
}
};

template <class _CharT, class _Traits>
Expand Down Expand Up @@ -821,14 +829,6 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>

template <class _CharT, class _Traits>
typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::overflow(int_type __c) {
auto __failed = [this]() {
if (this->pptr() == this->epptr() + 1) {
this->pbump(-1); // lose the character we overflowed above -- we don't really have a
// choice since we couldn't commit the contents of the put area
}
return traits_type::eof();
};

if (__file_ == nullptr)
return traits_type::eof();
__write_mode();
Expand All @@ -850,7 +850,7 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
if (__always_noconv_) {
size_t __n = static_cast<size_t>(this->pptr() - this->pbase());
if (std::fwrite(this->pbase(), sizeof(char_type), __n, __file_) != __n) {
return __failed();
return __overflow_failed();
}
} else {
if (!__cv_)
Expand All @@ -864,22 +864,22 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
do {
codecvt_base::result __r = __cv_->out(__st_, __b, __p, __end, __extbuf_, __extbuf_ + __ebs_, __extbuf_end);
if (__end == __b) {
return __failed();
return __overflow_failed();
}

// No conversion needed: output characters directly to the file, done.
if (__r == codecvt_base::noconv) {
size_t __n = static_cast<size_t>(__p - __b);
if (std::fwrite(__b, 1, __n, __file_) != __n) {
return __failed();
return __overflow_failed();
}
break;

// Conversion successful: output the converted characters to the file, done.
} else if (__r == codecvt_base::ok) {
size_t __n = static_cast<size_t>(__extbuf_end - __extbuf_);
if (std::fwrite(__extbuf_, 1, __n, __file_) != __n) {
return __failed();
return __overflow_failed();
}
break;

Expand All @@ -888,13 +888,13 @@ typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>
} else if (__r == codecvt_base::partial) {
size_t __n = static_cast<size_t>(__extbuf_end - __extbuf_);
if (std::fwrite(__extbuf_, 1, __n, __file_) != __n) {
return __failed();
return __overflow_failed();
}
__b = const_cast<char_type*>(__end);
continue;

} else {
return __failed();
return __overflow_failed();
}
} while (true);
}
Expand Down
Loading