summaryrefslogtreecommitdiff
path: root/common/binfile.h
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2003-09-20 07:12:49 +0000
committerStef Walter <stef@thewalter.net>2003-09-20 07:12:49 +0000
commitb49d8ebefe9b10c53a6a09ad564e22111b7b25c6 (patch)
tree1d5dd4abc38170a7bc106dabbc59b915017222f0 /common/binfile.h
parent1cda9ebbd62916c7c2136722597a86c583e1ecf6 (diff)
Initial Import
Diffstat (limited to 'common/binfile.h')
-rw-r--r--common/binfile.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/common/binfile.h b/common/binfile.h
new file mode 100644
index 0000000..3b86b8f
--- /dev/null
+++ b/common/binfile.h
@@ -0,0 +1,110 @@
+/*
+ * AUTHOR
+ * N. Nielsen
+ *
+ * LICENSE
+ * This software is in the public domain.
+ *
+ * The software is provided "as is", without warranty of any kind,
+ * express or implied, including but not limited to the warranties
+ * of merchantability, fitness for a particular purpose, and
+ * noninfringement. In no event shall the author(s) be liable for any
+ * claim, damages, or other liability, whether in an action of
+ * contract, tort, or otherwise, arising from, out of, or in connection
+ * with the software or the use or other dealings in the software.
+ *
+ * SUPPORT
+ * Send bug reports to: <nielsen@memberwebs.com>
+ */
+
+#ifndef __BINFILE_H__
+#define __BINFILE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef _WIN32
+#pragma pack(push, ops)
+#endif
+
+#pragma pack(1)
+
+/* bfval: ----------------------------------------------------------
+ * A tagged value to be written/read from a binfile
+ */
+typedef struct _bfval
+{
+ short id; /* The tag id */
+ short type; /* The data type */
+ size_t len; /* The length in bytes */
+}
+bfval;
+
+#pragma pack()
+
+#ifdef _WIN32
+#pragma pack(pop, ops)
+#endif
+
+
+/* BFILE: --------------------------------------------------------
+ * The binfile open handle
+ */
+typedef void* BFILE;
+
+
+
+#define BINTYPE_NONE (short)0x0000
+#define BINTYPE_INT16 (short)0x0001
+#define BINTYPE_INT32 (short)0x0002
+#define BINTYPE_ASCII (short)0x0005
+#define BINTYPE_DATA (short)0x0010
+#define BINTYPE_END (short)0xFFFF
+
+#define BINSIZE_INT32 4 /* sizeof(int) */
+#define BINSIZE_INT16 2 /* sizeof(short) */
+
+#define BF_REALLOC 0x00000001
+
+/* Open a binfile based on a disk FILE */
+BFILE bfStartFile(FILE* file);
+/* Open a binfile based on memory */
+BFILE bfStartMem(void* mem, size_t len, int flags);
+
+
+/* Write raw data to a binfile at current position */
+int bfWriteRaw(BFILE h, const void* data, size_t len);
+/* Read raw data from a binfile at the current position */
+int bfReadRaw(BFILE h, void* data, size_t len);
+
+/* Check if an error occured during reading/writing */
+int bfError(BFILE h);
+
+/* Write a bfval to binfile */
+int bfWriteValue(BFILE h, const bfval* opt, const void* data);
+/* Write a string to a binfile */
+int bfWriteString(BFILE h, short id, const char* data);
+/* Write a 4 byte integer to a binfile */
+int bfWriteInt(BFILE h, short id, int data);
+/* Write the end tag marker */
+int bfWriteEnd(BFILE h);
+
+/* Read the tag information for a value */
+int bfReadValueInfo(BFILE h, bfval* opt);
+/* Read the data for a value */
+int bfReadValueData(BFILE h, const bfval* opt, void* data);
+/* Skip the data for the current value */
+int bfSkipValueData(BFILE h, const bfval* opt);
+
+size_t bfCount(BFILE h);
+void* bfInternal(BFILE h);
+
+/* Close a binfile */
+void bfClose(BFILE h);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BINFILE_H__ */