MiniGUI API Reference (MiniGUI-Threads)  v5.0.6
A mature and proven cross-platform GUI system for embedded and smart IoT devices
Data Structures | Macros | Typedefs | Functions
General read/write operations

MiniGUI's general read/write operation provides a general interface to read from and write to various data source, such as files, memory, and so on. More...

Data Structures

struct  _MG_RWops
 

Macros

#define MGUI_RWseek(ctx, offset, whence)   (ctx)->seek(ctx, offset, whence)
 Seeks an MG_RWops object. More...
 
#define MGUI_RWtell(ctx)   (ctx)->seek(ctx, 0, SEEK_CUR)
 Obtains the current value of the position indicator for a data source. More...
 
#define MGUI_RWread(ctx, ptr, size, n)   (ctx)->read(ctx, ptr, size, n)
 Reads data blocks from a data source. More...
 
#define MGUI_RWwrite(ctx, ptr, size, n)   (ctx)->write(ctx, ptr, size, n)
 Writes data blocks to a data source. More...
 
#define MGUI_RWclose(ctx)   (ctx)->close(ctx)
 Closes an MG_RWops object. More...
 
#define MGUI_RWeof(ctx)   (ctx)->eof(ctx)
 Tests the end-of-file indicator for an data source. More...
 

Typedefs

typedef struct _MG_RWops MG_RWops
 

Functions

MG_EXPORT MG_RWopsMGUI_RWFromFile (const char *file, const char *mode)
 Creates an MG_RWops object from a file. More...
 
MG_EXPORT MG_RWopsMGUI_RWFromFP (FILE *fp, int autoclose)
 Creates an MG_RWops object from an opened stdio FILE object. More...
 
MG_EXPORT MG_RWopsMGUI_RWFromMem (void *mem, size_t size)
 Creates an MG_RWops object from a block of memory. More...
 
MG_EXPORT void MGUI_InitMemRW (MG_RWops *area, void *mem, size_t size)
 Initializes an MG_RWops object from a block of memory. More...
 
MG_EXPORT MG_RWopsMGUI_AllocRW (void)
 Allocates an uninitialized MG_RWops object. More...
 
MG_EXPORT void MGUI_FreeRW (MG_RWops *area)
 Frees an MG_RWops object. More...
 
MG_EXPORT int MGUI_RWgetc (MG_RWops *area)
 Reads the next character from an data source. More...
 

Detailed Description

MiniGUI's general read/write operation provides a general interface to read from and write to various data source, such as files, memory, and so on.

Macro Definition Documentation

◆ MGUI_RWclose

#define MGUI_RWclose (   ctx)    (ctx)->close(ctx)

Closes an MG_RWops object.

This macro close the MG_RWops object pointed to by ctx.

Parameters
ctxThe pointer to the MG_RWops object.
Returns
Upon successful completion 0 is returned, otherwise non-zero on error.
See also
MGUI_RWread

Definition at line 359 of file endianrw.h.

◆ MGUI_RWeof

#define MGUI_RWeof (   ctx)    (ctx)->eof(ctx)

Tests the end-of-file indicator for an data source.

This macro tests the end-of-file indicator for the data source pointed to by ctx.

Parameters
ctxThe pointer to the MG_RWops object.
Returns
Non-zero if end-of-file indicator is set.
See also
MGUI_RWtell

Definition at line 374 of file endianrw.h.

◆ MGUI_RWread

#define MGUI_RWread (   ctx,
  ptr,
  size,
 
)    (ctx)->read(ctx, ptr, size, n)

Reads data blocks from a data source.

This macro reads up to n objects each of size size from the data source ctx to the area pointed to by ptr.

Parameters
ctxThe pointer to the MG_RWops object.
ptrThe buffer will save the data read.
sizeThe size of each object.
nThe number of objects to be read.
Returns
The number of objects read, or -1 if the read failed.
See also
MGUI_RWwrite

Definition at line 327 of file endianrw.h.

◆ MGUI_RWseek

#define MGUI_RWseek (   ctx,
  offset,
  whence 
)    (ctx)->seek(ctx, offset, whence)

Seeks an MG_RWops object.

This macro seeks to offset relative to whence.

Parameters
ctxThe pointer to the MG_RWops object.
offsetThe offset relative to whence.
whenceOne of stdio's whence values:
 - SEEK_SET\n
   the offset is relative to the start of the file.
 - SEEK_CUR\n
   the offset is relative to the current position indicator.
 - SEEK_END\n
   the offset is relative to the end of the file.
Returns
The final offset in the data source.
See also
MGUI_RWtell

Definition at line 295 of file endianrw.h.

◆ MGUI_RWtell

#define MGUI_RWtell (   ctx)    (ctx)->seek(ctx, 0, SEEK_CUR)

Obtains the current value of the position indicator for a data source.

This macro obtains the current value of the position indicator for the data source pointed to by ctx.

Parameters
ctxThe pointer to the MG_RWops object.
Returns
The current value of the position indicator.
See also
MGUI_RWseek

Definition at line 310 of file endianrw.h.

◆ MGUI_RWwrite

#define MGUI_RWwrite (   ctx,
  ptr,
  size,
 
)    (ctx)->write(ctx, ptr, size, n)

Writes data blocks to a data source.

This macro writes exactly n objects each of size size from the area pointed to by ptr to the data source ctx.

Parameters
ctxThe pointer to the MG_RWops object.
ptrThe buffer contains the data to be written.
sizeThe size of each object.
nThe number of objects to be written.
Returns
The number written, or -1 if the write failed.
See also
MGUI_RWread

Definition at line 344 of file endianrw.h.

Typedef Documentation

◆ MG_RWops

typedef struct _MG_RWops MG_RWops

The read/write operation structure.

Function Documentation

◆ MGUI_AllocRW()

MG_RWops * MGUI_AllocRW ( void  )

Allocates an uninitialized MG_RWops object.

This function allocates an uninitialized MG_RWops object. You can specify the fields of the structure, and implemente a customized MG_RWops object.

Returns
The pointer to allocated MG_RWops structure, NULL indicates error.
See also
MG_RWops

◆ MGUI_FreeRW()

void MGUI_FreeRW ( MG_RWops area)

Frees an MG_RWops object.

This function frees the MG_RWops object pointed to by area.

Parameters
areaThe pointer to the MG_RWops object.
See also
MGUI_RWFromFile, MGUI_RWFromFP, MGUI_RWFromMem

◆ MGUI_InitMemRW()

void MGUI_InitMemRW ( MG_RWops area,
void *  mem,
size_t  size 
)

Initializes an MG_RWops object from a block of memory.

This function initializes an MG_RWops object pointed to by area from a block of memory pointed to by mem, which is size bytes long.

Parameters
areaThe pointer to the MG_RWops object.
memThe pointer to the memory block.
sizeThe size of the memory block.
Returns
None.
See also
MG_RWops, MGUI_FreeRW, MGUI_RWFromMem

◆ MGUI_RWFromFile()

MG_RWops * MGUI_RWFromFile ( const char *  file,
const char *  mode 
)

Creates an MG_RWops object from a file.

This function uses the mode specified by mode and opens the file file by using stdio function fopen. If success, this function creates a MG_RWops object and returns it.

Parameters
fileThe file name.
modeThe mode will be passed to fopen.
Returns
The pointer to created MG_RWops structure, NULL indicates error.
See also
MG_RWops, MGUI_RWFromFP, MGUI_FreeRW, fopen(3)

◆ MGUI_RWFromFP()

MG_RWops * MGUI_RWFromFP ( FILE *  fp,
int  autoclose 
)

Creates an MG_RWops object from an opened stdio FILE object.

This function uses an opened stdio FILE object fp to create a MG_RWops object.

Parameters
fpThe opened stdio FILE object.
autocloseIndicates whether to close the FILE object when close method is called.
Returns
The pointer to created MG_RWops structure, NULL indicates error.
See also
MG_RWops, MGUI_RWFromFile, MGUI_FreeRW

◆ MGUI_RWFromMem()

MG_RWops * MGUI_RWFromMem ( void *  mem,
size_t  size 
)

Creates an MG_RWops object from a block of memory.

This function creates an MG_RWops object from a block of memory pointed to by mem, which is size bytes long.

Parameters
memThe pointer to the memory block.
sizeThe size of the memory block.
Returns
The pointer to created MG_RWops structure, NULL indicates error.
See also
MG_RWops, MGUI_FreeRW

◆ MGUI_RWgetc()

int MGUI_RWgetc ( MG_RWops area)

Reads the next character from an data source.

This function reads the next character from the data source pointed to by area, and returns it as an unsigned char cast to an int, or EOF on end of file or error.

Parameters
areaThe pointer to the MG_RWops object.
Returns
The character read, EOF indicates end-of-file or error.
See also
MGUI_RWread