64 fh = fopen(filename,
"wb");
66 OJPH_ERROR(0x00060001,
"failed to open %s for writing", filename);
73 return fwrite(ptr, 1,
size,
fh);
123 assert(this->
is_open ==
false);
175 size_t needed_size = (size_t)
tell() + new_size;
179 memcpy(this->
cur_ptr, ptr, new_size);
190 FILE *f = fopen(file_name,
"wb");
192 OJPH_ERROR(0x00060003,
"failed to open %s for writing", file_name);
195 OJPH_ERROR(0x00060004,
"failed writing to %s", file_name);
204 needed_size += (needed_size + 1) >> 1;
211 OJPH_ERROR(0x00060005,
"failed to allocate memory (%zu bytes)",
214 if (this->
buf != NULL)
244 fh = fopen(filename,
"rb");
246 OJPH_ERROR(0x00060002,
"failed to open %s for reading", filename);
253 return fread(ptr, 1,
size,
fh);
290 assert(this->data == NULL);
298 std::ptrdiff_t bytes_left = (
data + this->size) -
cur_ptr;
301 size_t bytes_to_read =
ojph_min(
size, (
size_t)bytes_left);
302 memcpy(ptr,
cur_ptr, bytes_to_read);
304 return bytes_to_read;
316 if (offset >= 0 && (
size_t)offset <=
size)
325 if (bytes_off >= 0 && (
size_t)bytes_off <=
size)
333 if (offset <= 0 && (std::ptrdiff_t)
size + offset >= 0)
void open(const char *filename)
size_t read(void *ptr, size_t size) override
void open(const char *filename)
size_t write(const void *ptr, size_t size) override
size_t read(void *ptr, size_t size) override
void open(const ui8 *data, size_t size)
si64 tell() override
Call this function to know the file size (i.e., number of bytes used to store the file).
static const size_t ALIGNED_ALLOC_MASK
size_t write(const void *ptr, size_t size) override
Call this function to write data to the memory file.
void expand_storage(size_t new_size, bool clear_all)
This function expands storage by x1.5 needed space.
void open(size_t initial_size=65536, bool clear_mem=false)
Call this function to open a memory file.
void write_to_file(const char *file_name) const
Call this function to write the memory file data to a file.
int ojph_fseek(FILE *stream, si64 offset, int origin)
void * ojph_aligned_malloc(size_t alignment, size_t size)
si64 ojph_ftell(FILE *stream)
void ojph_aligned_free(void *pointer)
#define OJPH_ERROR(t,...)