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