stdio_file.h 893 B

123456789101112131415161718192021222324252627282930313233
  1. #pragma once
  2. #include "buffered.h"
  3. #include <library/cpp/yson_pull/detail/macros.h>
  4. #include <library/cpp/yson_pull/exceptions.h>
  5. #include <cstdio>
  6. namespace NYsonPull {
  7. namespace NDetail {
  8. namespace NOutput {
  9. class TStdioFile: public TBuffered<TStdioFile> {
  10. FILE* file_;
  11. public:
  12. TStdioFile(FILE* file, size_t buffer_size)
  13. : TBuffered<TStdioFile>(buffer_size)
  14. , file_(file)
  15. {
  16. }
  17. void write(TStringBuf data) {
  18. auto nwritten = ::fwrite(data.data(), 1, data.size(), file_);
  19. if (Y_UNLIKELY(static_cast<size_t>(nwritten) != data.size())) {
  20. throw NException::TSystemError();
  21. }
  22. }
  23. };
  24. }
  25. } // namespace NDetail
  26. }