| author | David Anderson <dvander@alliedmods.net> |
| Tue Dec 23 01:33:37 2008 -0500 (2008-12-23) | |
| changeset 2471 | 194be299b700 |
| parent 1952 | b7aa2b626807 |
| permissions | -rw-r--r-- |
| ds@1952 | 1 |
#ifndef _INCLUDE_MEMFILE_H |
| ds@1952 | 2 |
#define _INCLUDE_MEMFILE_H |
| ds@1952 | 3 |
|
| dvander@2471 | 4 |
#include <stdlib.h> |
| ds@1952 | 5 |
|
| ds@1952 | 6 |
typedef struct memfile_s |
| ds@1952 | 7 |
{ |
| ds@1952 | 8 |
char *name; |
| ds@1952 | 9 |
char *base; |
| ds@1952 | 10 |
long offs; |
| ds@1952 | 11 |
long usedoffs; |
| ds@1952 | 12 |
size_t size; |
| ds@1952 | 13 |
int _static; |
| ds@1952 | 14 |
} memfile_t; |
| ds@1952 | 15 |
|
| ds@1952 | 16 |
/** |
| ds@1952 | 17 |
* Creates a new memory file |
| ds@1952 | 18 |
* init is the initial size in bytes |
| ds@1952 | 19 |
*/ |
| ds@1952 | 20 |
memfile_t *memfile_creat(const char *name, size_t init); |
| ds@1952 | 21 |
|
| ds@1952 | 22 |
/** |
| ds@1952 | 23 |
* Frees the memory associated. |
| ds@1952 | 24 |
*/ |
| ds@1952 | 25 |
void memfile_destroy(memfile_t *mf); |
| ds@1952 | 26 |
|
| ds@1952 | 27 |
/** |
| ds@1952 | 28 |
* Seeks to a given offset (always from start) |
| ds@1952 | 29 |
*/ |
| ds@1952 | 30 |
void memfile_seek(memfile_t *mf, long seek); |
| ds@1952 | 31 |
|
| ds@1952 | 32 |
/** |
| ds@1952 | 33 |
* Writes to a memory buffer (expands as necessary). |
| ds@1952 | 34 |
* Returns 1 on success, 0 on failure. |
| ds@1952 | 35 |
*/ |
| ds@1952 | 36 |
int memfile_write(memfile_t *mf, const void *buffer, size_t size); |
| ds@1952 | 37 |
|
| ds@1952 | 38 |
/** |
| ds@1952 | 39 |
* Reads a number of bytes from a memory buffer. |
| ds@1952 | 40 |
* Returns the number of bytes read until the end was hit. |
| ds@1952 | 41 |
*/ |
| ds@1952 | 42 |
size_t memfile_read(memfile_t *mf, void *buffer, size_t maxsize); |
| ds@1952 | 43 |
|
| ds@1952 | 44 |
/** |
| ds@1952 | 45 |
* Returns the current position from the start. |
| ds@1952 | 46 |
*/ |
| ds@1952 | 47 |
long memfile_tell(memfile_t *mf); |
| ds@1952 | 48 |
|
| ds@1952 | 49 |
/** |
| ds@1952 | 50 |
* Resets all the states of the memory buffer. |
| ds@1952 | 51 |
* (does not actually free or zero memory) |
| ds@1952 | 52 |
*/ |
| ds@1952 | 53 |
void memfile_reset(memfile_t *mf); |
| ds@1952 | 54 |
|
| ds@1952 | 55 |
#endif //_INCLUDE_MEMFILE_H |