15 #ifndef RAPIDJSON_FILEWRITESTREAM_H_
16 #define RAPIDJSON_FILEWRITESTREAM_H_
23 RAPIDJSON_DIAG_OFF(unreachable-code)
26 RAPIDJSON_NAMESPACE_BEGIN
36 FileWriteStream(std::FILE* fp,
char* buffer,
size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) {
41 if (current_ >= bufferEnd_)
47 void PutN(
char c,
size_t n) {
48 size_t avail = static_cast<size_t>(bufferEnd_ - current_);
50 std::memset(current_, c, avail);
54 avail = static_cast<size_t>(bufferEnd_ - current_);
58 std::memset(current_, c, n);
64 if (current_ != buffer_) {
65 size_t result = std::fwrite(buffer_, 1, static_cast<size_t>(current_ - buffer_), fp_);
66 if (result < static_cast<size_t>(current_ - buffer_)) {
83 FileWriteStream(
const FileWriteStream&);
84 FileWriteStream& operator=(
const FileWriteStream&);
98 RAPIDJSON_NAMESPACE_END
104 #endif // RAPIDJSON_FILESTREAM_H_