1 #ifndef _INCLUDE_SPFILE_H
2 #define _INCLUDE_SPFILE_H
4 #include "sp_file_headers.h"
7 * Used for overwriting writing routines.
9 typedef struct sp_writefuncs_s
11 void *(*fnOpen)(const char *); /* filename, returns handle */
12 void (*fnClose)(void *); /* handle */
13 /* buffer, size, count, handle, returns count written */
14 size_t (*fnWrite)(const void *, size_t, size_t, void *);
15 /* buffer, size, count, handle, returns count read */
16 size_t (*fnRead)(void *, size_t, size_t, void *);
17 /* returns current position from start */
18 size_t (*fnGetPos)(void *);
19 /* sets current position from start, return 0 for success, nonzero for error */
20 int (*fnSetPos)(void *, size_t);
23 typedef struct sp_file_s
26 sp_file_section_t *sections;
28 sp_writefuncs_t funcs;
38 * Creates a new SourcePawn binary file.
39 * You may optionally specify alternative writing functions.
41 sp_file_t *spfw_create(const char *name, sp_writefuncs_t *optfuncs);
44 * Closes file handle and frees memory.
46 void spfw_destroy(sp_file_t *spf);
49 * Adds a section name to the header.
50 * Only valid BEFORE finalization.
51 * Returns the number of sections, or 0 on failure.
53 uint8_t spfw_add_section(sp_file_t *spf, const char *name);
56 * Finalizes the section header.
57 * This means no more sections can be added after this call.
58 * Also, aligns the writer to the first section.
59 * Returns 0 on success, nonzero on error.
61 int spfw_finalize_header(sp_file_t *spf);
64 * Finalizes the current section and advances to the next.
65 * In order for this to be accurate, the file pointer must
66 * reside at the end before calling this, because the size
67 * is calculated by differencing with the last known offset.
68 * Returns 1 if there are more sections left, 0 otherwise.
69 * Returns -1 if the file state is wrong.
71 int spfw_next_section(sp_file_t *spf);
74 * Finalizes all sections.
75 * Cannot be called until all sections are used.
76 * Must be called with the file pointer at the end.
77 * Also does compression!
79 int spfw_finalize_all(sp_file_t *spf);
81 #endif //_INCLUDE_SPFILE_H