annotate dmresw.c @ 59:c560703e85ed

Add resource writing functions (only work for stdio backend)
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 01 Oct 2012 07:51:08 +0300
parents
children be6160981428
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
59
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * DMLib
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * -- Resource management
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Programmed and designed by Matti 'ccr' Hamalainen
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 * (C) Copyright 2011-2012 Tecnic Software productions (TNSP)
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 */
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "dmresw.h"
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 /* Helper resource access routines
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 */
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 int dmf_write_str(DMResource *f, Uint8 *s, size_t l)
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 {
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 return dmfwrite(s, sizeof(Uint8), l, f) == l;
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 }
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #define DM_DEFINE_FUNC(xname, xtype, xmacro) \
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 BOOL dmf_write_ ## xname (DMResource *f, xtype *v) { \
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 xtype result; \
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 if (dmfwrite(&result, sizeof( xtype ), 1, f) != 1) \
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 return FALSE; \
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 *v = DM_ ## xmacro ## _TO_NATIVE (result); \
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 return TRUE; \
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 }
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 DM_DEFINE_FUNC(le16, Uint16, LE16)
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 DM_DEFINE_FUNC(le32, Uint32, LE32)
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 DM_DEFINE_FUNC(be16, Uint16, BE16)
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 DM_DEFINE_FUNC(be32, Uint32, BE32)
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 #ifdef DM_HAVE_64BIT
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 DM_DEFINE_FUNC(le64, Uint64, LE64)
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 DM_DEFINE_FUNC(be64, Uint64, BE64)
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 #endif