ds@1952: #ifndef _INCLUDE_MEMFILE_H ds@1952: #define _INCLUDE_MEMFILE_H ds@1952: dvander@2471: #include ds@1952: ds@1952: typedef struct memfile_s ds@1952: { ds@1952: char *name; ds@1952: char *base; ds@1952: long offs; ds@1952: long usedoffs; ds@1952: size_t size; ds@1952: int _static; ds@1952: } memfile_t; ds@1952: ds@1952: /** ds@1952: * Creates a new memory file ds@1952: * init is the initial size in bytes ds@1952: */ ds@1952: memfile_t *memfile_creat(const char *name, size_t init); ds@1952: ds@1952: /** ds@1952: * Frees the memory associated. ds@1952: */ ds@1952: void memfile_destroy(memfile_t *mf); ds@1952: ds@1952: /** ds@1952: * Seeks to a given offset (always from start) ds@1952: */ ds@1952: void memfile_seek(memfile_t *mf, long seek); ds@1952: ds@1952: /** ds@1952: * Writes to a memory buffer (expands as necessary). ds@1952: * Returns 1 on success, 0 on failure. ds@1952: */ ds@1952: int memfile_write(memfile_t *mf, const void *buffer, size_t size); ds@1952: ds@1952: /** ds@1952: * Reads a number of bytes from a memory buffer. ds@1952: * Returns the number of bytes read until the end was hit. ds@1952: */ ds@1952: size_t memfile_read(memfile_t *mf, void *buffer, size_t maxsize); ds@1952: ds@1952: /** ds@1952: * Returns the current position from the start. ds@1952: */ ds@1952: long memfile_tell(memfile_t *mf); ds@1952: ds@1952: /** ds@1952: * Resets all the states of the memory buffer. ds@1952: * (does not actually free or zero memory) ds@1952: */ ds@1952: void memfile_reset(memfile_t *mf); ds@1952: ds@1952: #endif //_INCLUDE_MEMFILE_H