50 if (std::fseek(handle, 0, SEEK_END) != 0)
53 long fileSize = std::ftell(handle);
55 if (std::fseek(handle, 0, SEEK_SET) != 0)
72 if ((
uint64)((
unsigned long)fileSize) > (
uint64)0x7FFFFFFFULL) {
79 _size = (size_t)fileSize;
100 return std::feof(
_handle) != 0;
107 return (
size_t)std::ftell(
_handle);
115 static const int kSeekToWhence[
kOriginMAX] = { SEEK_SET, SEEK_CUR, SEEK_END };
122 size_t oldPos =
pos();
124 if (std::fseek(
_handle, offset, kSeekToWhence[whence]) != 0)
128 if ((p < 0) || ((
size_t)p >
_size))
139 return std::fread(dataPtr, 1, dataSize,
_handle);
size_t pos() const
Obtains the current value of the stream position indicator of the stream.
static long getInitialSize(std::FILE *handle)
A class holding an UTF-8 string.
static const size_t kPositionInvalid
size_t _size
The file's size.
bool eos() const
Returns true if a read failed because the stream has been reached.
size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)
Sets the stream position indicator for the stream.
Origin
The position a seeking offset takes as a base.
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
bool open(const UString &fileName)
Try to open the file with the given fileName.
size_t read(void *dataPtr, size_t dataSize)
Read data from the stream.
static const size_t kSizeInvalid
void warning(const char *s,...)
Implementing the stream reading interfaces for files.
std::FILE * _handle
The actual file handle.
size_t size() const
Obtains the total size of the stream, measured in bytes.
const Exception kSeekError("Seek error")
Exception when seeking a stream failed.
bool isOpen() const
Checks if the object opened a file successfully.
void close()
Close the file, if open.