11 FileStream::FileStream(
const Path& filename) { open(filename); }
13 FileStream::~FileStream() { close(); }
15 bool FileStream::open(
const Path& filename)
17 file = fopen(filename.c_str(),
"rb");
18 if (!file) setstate(failbit);
22 bool FileStream::close()
24 if (!file || fclose(file)) setstate(failbit);
32 const size_t readSize = fread(buffer,
sizeof(
char), size, file);
33 if (readSize != size) {
49 static_assert(FileStream::beg == SEEK_SET,
"");
50 static_assert(FileStream::cur == SEEK_CUR,
"");
51 static_assert(FileStream::end == SEEK_END,
"");
55 if (fseek(file, offset, origin) != 0) setstate(failbit);
61 const long curPos = ftell(file);
62 if (curPos == -1) setstate(failbit);
64 const long size = ftell(file);
65 if (size == -1) setstate(failbit);
68 if (curPos != -1 && !
seek(curPos, beg)) setstate(failbit);
74 const int c = fgetc(file);
75 if (c == EOF) { setstate(failbit | eofbit); }
bool seek(long offset, seekdir origin) override
Change the pointer of the stream to a given position.
long size() override
Computes the size of the file.
int getc() override
Read one byte from the stream.
size_t read(void *buffer, size_t size) override
Read data from the stream.
long tell() override
Return the current position of the stream pointer.