Mercurial > hg > dmlib
changeset 437:3d9c044ec08d
Add dmf_{write,read}_byte() convenience functions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 04 Nov 2012 03:15:35 +0200 |
parents | 86f956e4580f |
children | c1f6def0c1da |
files | dmres.c dmres.h dmresw.c dmresw.h |
diffstat | 4 files changed, 17 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/dmres.c Sun Nov 04 02:50:03 2012 +0200 +++ b/dmres.c Sun Nov 04 03:15:35 2012 +0200 @@ -1119,6 +1119,12 @@ return dmfread(s, sizeof(Uint8), l, f) == l; } +BOOL dmf_read_byte(DMResource *f, Uint8 *val) +{ + int tmp = dmfgetc(f); + *val = tmp; + return tmp != EOF; +} #define DM_DEFINE_FUNC(xname, xtype, xmacro) \ BOOL dmf_read_ ## xname (DMResource *f, xtype *v) { \
--- a/dmres.h Sun Nov 04 02:50:03 2012 +0200 +++ b/dmres.h Sun Nov 04 03:15:35 2012 +0200 @@ -168,8 +168,10 @@ char * dmfgets(char *s, int size, DMResource * f); -// Specialized functions for endianess based reading etc +// Helper functions for endianess based reading etc int dmf_read_str(DMResource *, Uint8 *, size_t); +BOOL dmf_read_byte(DMResource *, Uint8 *); + BOOL dmf_read_be16(DMResource *, Uint16 *); BOOL dmf_read_be32(DMResource *, Uint32 *); BOOL dmf_read_le16(DMResource *, Uint16 *);
--- a/dmresw.c Sun Nov 04 02:50:03 2012 +0200 +++ b/dmresw.c Sun Nov 04 03:15:35 2012 +0200 @@ -6,14 +6,18 @@ */ #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; } +BOOL dmf_write_byte(DMResource *f, const Uint8 val) +{ + return dmfputc(val, f) == val; +} + + #define DM_DEFINE_FUNC(xname, xtype, xmacro) \ BOOL dmf_write_ ## xname (DMResource *f, xtype v) { \ xtype result = DM_NATIVE_TO_ ## xmacro (v); \
--- a/dmresw.h Sun Nov 04 02:50:03 2012 +0200 +++ b/dmresw.h Sun Nov 04 03:15:35 2012 +0200 @@ -14,6 +14,8 @@ #endif int dmf_write_str(DMResource *, Uint8 *, size_t); +BOOL dmf_write_byte(DMResource *, const Uint8); + BOOL dmf_write_be16(DMResource *, Uint16); BOOL dmf_write_be32(DMResource *, Uint32); BOOL dmf_write_le16(DMResource *, Uint16);