maug
Quick and dirty C mini-augmentation library.
Modules | Files | Data Structures | Macros | Typedefs | Functions
RetroFile API

Abstraction layer for dealing with files on retro systems. More...

Collaboration diagram for RetroFile API:

Modules

 RetroFile Types
 Types of files/data stores that mfile can abstract from.
 
 RetroFile Byte Order
 Flags controlling byte order for read operations.
 
 RetroFlat Assets API
 Functions and macros for handling graphical asset files.
 

Files

file  mfile.h
 

Data Structures

struct  MFILE_CADDY
 

Macros

#define MAUG_PATH_SZ_MAX   256
 Maximum size allocated for asset paths.
 
#define MFILE_READ_FLAG_LSBF   0x01
 Flag for mfile_read_int_t() indicating integer should always be read least significant byte first.
 
#define MFILE_READ_FLAG_MSBF   0x01
 Flag for mfile_read_int_t() indicating integer should always be read most significant byte first.
 
#define MFILE_ASSIGN_FLAG_TRIM_EXT   0x01
 
#define MFILE_READ_TRACE_LVL   0
 
#define MFILE_WRITE_TRACE_LVL   0
 
#define MFILE_SEEK_TRACE_LVL   0
 
#define MFILE_CONTENTS_TRACE_LVL   0
 
#define mfile_get_sz(p_file)   ((p_file)->sz)
 

Typedefs

typedef struct MFILE_CADDY mfile_t
 
typedef off_t(* mfile_cursor_t) (struct MFILE_CADDY *p_file)
 
typedef off_t(* mfile_has_bytes_t) (struct MFILE_CADDY *p_file)
 
typedef MERROR_RETVAL(* mfile_read_byte_t) (struct MFILE_CADDY *p_file, uint8_t *buf)
 
typedef MERROR_RETVAL(* mfile_read_block_t) (struct MFILE_CADDY *p_file, uint8_t *buf, size_t buf_sz)
 
typedef MERROR_RETVAL(* mfile_seek_t) (struct MFILE_CADDY *p_file, off_t pos)
 
typedef MERROR_RETVAL(* mfile_read_int_t) (struct MFILE_CADDY *p_file, uint8_t *buf, size_t buf_sz, uint8_t flags)
 
typedef MERROR_RETVAL(* mfile_read_line_t) (struct MFILE_CADDY *p_file, char *buf, off_t buf_sz, uint8_t flags)
 
typedef MERROR_RETVAL(* mfile_printf_t) (struct MFILE_CADDY *p_file, uint8_t flags, const char *fmt,...)
 
typedef MERROR_RETVAL(* mfile_write_block_t) (struct MFILE_CADDY *p_f, const uint8_t *buf, size_t buf_sz)
 
typedef MERROR_RETVAL(* mfile_vprintf_t) (struct MFILE_CADDY *p_file, uint8_t flags, const char *fmt, va_list args)
 Callback to printf the given format string, replacing tokens from the providied pre-initialized list of args. More...
 

Functions

off_t mfile_mem_cursor (struct MFILE_CADDY *p_file)
 
off_t mfile_mem_has_bytes (struct MFILE_CADDY *p_file)
 
MERROR_RETVAL mfile_mem_read_byte (struct MFILE_CADDY *p_file, uint8_t *buf)
 
MERROR_RETVAL mfile_mem_read_block (struct MFILE_CADDY *p_file, uint8_t *buf, size_t buf_sz)
 
MERROR_RETVAL mfile_mem_seek (struct MFILE_CADDY *p_file, off_t pos)
 
MERROR_RETVAL mfile_mem_read_line (struct MFILE_CADDY *p_f, char *buffer, off_t buffer_sz, uint8_t flags)
 
MERROR_RETVAL mfile_mem_vprintf (mfile_t *p_file, uint8_t flags, const char *fmt, va_list args)
 
MERROR_RETVAL mfile_plt_init ()
 
off_t mfile_file_has_bytes (struct MFILE_CADDY *p_file)
 
MERROR_RETVAL mfile_file_read_byte (struct MFILE_CADDY *p_file, uint8_t *buf)
 
MERROR_RETVAL mfile_file_read_block (struct MFILE_CADDY *p_file, uint8_t *buf, size_t buf_sz)
 
MERROR_RETVAL mfile_file_read_int (struct MFILE_CADDY *p_f, uint8_t *buf, size_t buf_sz, uint8_t flags)
 
MERROR_RETVAL mfile_file_seek (struct MFILE_CADDY *p_file, off_t pos)
 
MERROR_RETVAL mfile_file_read_line (struct MFILE_CADDY *p_f, char *buffer, off_t buffer_sz, uint8_t flags)
 
MERROR_RETVAL mfile_file_printf (struct MFILE_CADDY *p_f, uint8_t flags, const char *fmt,...)
 
MERROR_RETVAL mfile_file_write_block (struct MFILE_CADDY *p_f, const uint8_t *buf, size_t buf_sz)
 
MERROR_RETVAL mfile_file_vprintf (struct MFILE_CADDY *p_f, uint8_t flags, const char *fmt, va_list args)
 
MERROR_RETVAL mfile_lock_buffer (MAUG_MHANDLE, void *ptr, off_t, mfile_t *p_file)
 Lock a buffer and assign it to an ::mfile_t to read/write.
 
MERROR_RETVAL mfile_open_read (const char *filename, mfile_t *p_file)
 Open a file and read it into memory or memory-map it. More...
 
MERROR_RETVAL mfile_open_write (const char *filename, mfile_t *p_file)
 
void mfile_close (mfile_t *p_file)
 Close a file opened with mfile_open_read().
 
MERROR_RETVAL mfile_mem_write_block (struct MFILE_CADDY *p_f, const uint8_t *buf, size_t buf_sz)
 Insert provided buffer into the given file. More...
 

Detailed Description

Abstraction layer for dealing with files on retro systems.

Typedef Documentation

◆ mfile_vprintf_t

typedef MERROR_RETVAL(* mfile_vprintf_t) (struct MFILE_CADDY *p_file, uint8_t flags, const char *fmt, va_list args)
related

Callback to printf the given format string, replacing tokens from the providied pre-initialized list of args.

Parameters
Pre-initializedlist of token format args.
Warning
The args parameter must have already been initialized with va_start!

Function Documentation

◆ mfile_mem_write_block()

MERROR_RETVAL mfile_mem_write_block ( struct MFILE_CADDY p_f,
const uint8_t *  buf,
size_t  buf_sz 
)
related

Insert provided buffer into the given file.

Note that this method inserts the given buffer into the file, shifting the rest of the contents forward.

◆ mfile_open_read()

MERROR_RETVAL mfile_open_read ( const char *  filename,
mfile_t p_file 
)

Open a file and read it into memory or memory-map it.

Parameters
filenameNULL-terminated path to file to open.