37 FileWriteStream(std::FILE* fp,
char* buffer,
size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) {
42 if (current_ >= bufferEnd_)
48 void PutN(
char c,
size_t n) {
49 size_t avail =
static_cast<size_t>(bufferEnd_ - current_);
51 std::memset(current_, c, avail);
55 avail =
static_cast<size_t>(bufferEnd_ - current_);
59 std::memset(current_, c, n);
65 if (current_ != buffer_) {
66 size_t result = std::fwrite(buffer_, 1,
static_cast<size_t>(current_ - buffer_), fp_);
67 if (result <
static_cast<size_t>(current_ - buffer_)) {