#include <mspack.h>
Data Fields | |
mspack_file *(* | open )(struct mspack_system *self, char *filename, int mode) |
Opens a file for reading, writing, appending or updating. | |
void(* | close )(struct mspack_file *file) |
Closes a previously opened file. | |
int(* | read )(struct mspack_file *file, void *buffer, int bytes) |
Reads a given number of bytes from an open file. | |
int(* | write )(struct mspack_file *file, void *buffer, int bytes) |
Writes a given number of bytes to an open file. | |
int(* | seek )(struct mspack_file *file, off_t offset, int mode) |
Seeks to a specific file offset within an open file. | |
off_t(* | tell )(struct mspack_file *file) |
Returns the current file position (in bytes) of the given file. | |
void(* | message )(struct mspack_file *file, char *format,...) |
Used to send messages from the library to the user. | |
void *(* | alloc )(struct mspack_system *self, size_t bytes) |
Allocates memory. | |
void(* | free )(void *ptr) |
Frees memory. | |
void(* | copy )(void *src, void *dest, size_t bytes) |
Copies from one region of memory to another. | |
void * | null_ptr |
A null pointer to mark the end of mspack_system. |
The library always uses the mspack_system structure for interaction with the file system and to allocate, free and copy all memory. It also uses it to send literal messages to the library user.
When the library is compiled normally, passing NULL to a compressor or decompressor constructor will result in a default mspack_system being used, where all methods are implemented with the standard C library. However, all constructors support being given a custom created mspack_system structure, with the library user's own methods. This allows for more abstract interaction, such as reading and writing files directly to memory, or from a network socket or pipe.
Implementors of an mspack_system structure should read all documentation entries for every structure member, and write methods which conform to those standards.
|
Allocates memory.
|
|
Closes a previously opened file. If any memory was allocated for this particular file handle, it should be freed at this time.
|
|
Copies from one region of memory to another. The regions of memory are guaranteed not to overlap, are usually less than 256 bytes, and may not be aligned. Please note that the source parameter comes before the destination parameter, unlike the standard C function memcpy().
|
|
Frees memory.
|
|
Used to send messages from the library to the user. Occasionally, the library generates warnings or other messages in plain english to inform the human user. These are informational only and can be ignored if not wanted.
|
|
A null pointer to mark the end of mspack_system. It must equal NULL. Should the mspack_system structure extend in the future, this NULL will be seen, rather than have an invalid method pointer called. |
|
Opens a file for reading, writing, appending or updating.
|
|
Reads a given number of bytes from an open file.
|
|
Seeks to a specific file offset within an open file. Sometimes the library needs to know the length of a file. It does this by seeking to the end of the file with seek(file, 0, MSPACK_SYS_SEEK_END), then calling tell(). Implementations may want to make a special case for this. Due to the potentially varying 32/64 bit datatype off_t on some architectures, the MSPACK_SYS_SELFTEST macro MUST be used before using the library. If not, the error caused by the library passing an inappropriate stackframe to seek() is subtle and hard to trace.
|
|
Returns the current file position (in bytes) of the given file.
|
|
Writes a given number of bytes to an open file.
|