Mercurial > hg > dmlib
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmresw.c Mon Oct 01 07:51:08 2012 +0300 @@ -0,0 +1,35 @@ +/* + * DMLib + * -- Resource management + * Programmed and designed by Matti 'ccr' Hamalainen + * (C) Copyright 2011-2012 Tecnic Software productions (TNSP) + */ +#include "dmresw.h" + +/* Helper resource access routines + */ +int dmf_write_str(DMResource *f, Uint8 *s, size_t l) +{ + return dmfwrite(s, sizeof(Uint8), l, f) == l; +} + + +#define DM_DEFINE_FUNC(xname, xtype, xmacro) \ +BOOL dmf_write_ ## xname (DMResource *f, xtype *v) { \ + xtype result; \ + if (dmfwrite(&result, sizeof( xtype ), 1, f) != 1) \ + return FALSE; \ + *v = DM_ ## xmacro ## _TO_NATIVE (result); \ + return TRUE; \ +} + +DM_DEFINE_FUNC(le16, Uint16, LE16) +DM_DEFINE_FUNC(le32, Uint32, LE32) + +DM_DEFINE_FUNC(be16, Uint16, BE16) +DM_DEFINE_FUNC(be32, Uint32, BE32) + +#ifdef DM_HAVE_64BIT +DM_DEFINE_FUNC(le64, Uint64, LE64) +DM_DEFINE_FUNC(be64, Uint64, BE64) +#endif