26 constexpr
int kDefaultBlockSize = 4096;
29 ROOT::Internal::RRawFileWin::RRawFileWin(std::string_view url, ROptions options)
30 : RRawFile(url, options), fFilePtr(nullptr)
34 ROOT::Internal::RRawFileWin::~RRawFileWin()
36 if (fFilePtr !=
nullptr)
40 std::unique_ptr<ROOT::Internal::RRawFile> ROOT::Internal::RRawFileWin::Clone()
const
42 return std::make_unique<RRawFileWin>(fUrl, fOptions);
45 std::uint64_t ROOT::Internal::RRawFileWin::GetSizeImpl()
48 long size = ftell(fFilePtr);
50 throw std::runtime_error(
"Cannot tell position counter in '" + fUrl +
51 "', error: " + std::string(strerror(errno)));
52 Seek(fFilePos, SEEK_SET);
56 void ROOT::Internal::RRawFileWin::OpenImpl()
58 fFilePtr = fopen(GetLocation(fUrl).c_str(),
"rb");
59 if (fFilePtr ==
nullptr)
60 throw std::runtime_error(
"Cannot open '" + fUrl +
"', error: " + std::string(strerror(errno)));
62 int res = setvbuf(fFilePtr,
nullptr, _IONBF, 0);
64 if (fOptions.fBlockSize < 0)
65 fOptions.fBlockSize = kDefaultBlockSize;
68 size_t ROOT::Internal::RRawFileWin::ReadAtImpl(
void *buffer,
size_t nbytes, std::uint64_t offset)
70 Seek(offset, SEEK_SET);
71 size_t res = fread(buffer, 1, nbytes, fFilePtr);
72 if ((res < nbytes) && (ferror(fFilePtr) != 0)) {
74 throw std::runtime_error(
"Cannot read from '" + fUrl +
"', error: " + std::string(strerror(errno)));
79 void ROOT::Internal::RRawFileWin::Seek(
long offset,
int whence)
81 int res = fseek(fFilePtr, offset, whence);
83 throw std::runtime_error(
"Cannot seek in '" + fUrl +
"', error: " + std::string(strerror(errno)));