# HG changeset patch # User Matti Hamalainen # Date 1425320203 -7200 # Node ID 9f06f6661cdf66679e0627510255b1eaaffa79bc # Parent a0c187dae495c96c5e8c0f0593055762ae44cbbb Cleanups for file endianess read/write helper functions. diff -r a0c187dae495 -r 9f06f6661cdf src/dmres.c --- a/src/dmres.c Mon Mar 02 20:10:44 2015 +0200 +++ b/src/dmres.c Mon Mar 02 20:16:43 2015 +0200 @@ -1253,8 +1253,8 @@ return tmp != EOF; } -#define DM_DEFINE_FUNC(xname, xtype, xmacro) \ -BOOL dmf_read_ ## xname (DMResource *f, xtype *v) { \ + +#define DM_DEFINE_FFUNC(xname, xtype, xmacro) \ BOOL dmf_read_ ## xname (DMResource *f, xtype *v) { \ xtype result; \ if (dmfread(&result, sizeof( xtype ), 1, f) != 1) \ @@ -1263,11 +1263,6 @@ return TRUE; \ } -DM_DEFINE_FUNC(le16, Uint16, LE16) -DM_DEFINE_FUNC(le32, Uint32, LE32) +#include "dmfiletmpl.h" -DM_DEFINE_FUNC(be16, Uint16, BE16) -DM_DEFINE_FUNC(be32, Uint32, BE32) - -DM_DEFINE_FUNC(le64, Uint64, LE64) -DM_DEFINE_FUNC(be64, Uint64, BE64) +#undef DM_DEFINE_FFUNC diff -r a0c187dae495 -r 9f06f6661cdf src/dmres.h --- a/src/dmres.h Mon Mar 02 20:10:44 2015 +0200 +++ b/src/dmres.h Mon Mar 02 20:16:43 2015 +0200 @@ -173,16 +173,15 @@ // Helper functions for endianess based reading etc -int dmf_read_str(DMResource *, void *, size_t); +int dmf_read_str(DMResource *, void *, const size_t); BOOL dmf_read_byte(DMResource *, Uint8 *); -BOOL dmf_read_be16(DMResource *, Uint16 *); -BOOL dmf_read_be32(DMResource *, Uint32 *); -BOOL dmf_read_be64(DMResource *, Uint64 *); +#define DM_DEFINE_FFUNC(xname, xtype, z) \ +BOOL dmf_read_ ## xname (DMResource *fh, xtype *v); -BOOL dmf_read_le16(DMResource *, Uint16 *); -BOOL dmf_read_le32(DMResource *, Uint32 *); -BOOL dmf_read_le64(DMResource *, Uint64 *); +#include "dmfiletmpl.h" + +#undef DM_DEFINE_FFUNC #ifdef __cplusplus diff -r a0c187dae495 -r 9f06f6661cdf src/dmresw.c --- a/src/dmresw.c Mon Mar 02 20:10:44 2015 +0200 +++ b/src/dmresw.c Mon Mar 02 20:16:43 2015 +0200 @@ -6,7 +6,8 @@ */ #include "dmresw.h" -int dmf_write_str(DMResource *f, void *s, size_t l) + +int dmf_write_str(DMResource *f, const void *s, const size_t l) { return dmfwrite(s, 1, l, f) == l; } @@ -18,18 +19,14 @@ } -#define DM_DEFINE_FUNC(xname, xtype, xmacro) \ -BOOL dmf_write_ ## xname (DMResource *f, xtype v) { \ +#define DM_DEFINE_FFUNC(xname, xtype, xmacro) \ +BOOL dmf_write_ ## xname (DMResource *f, const xtype v) { \ xtype result = DM_NATIVE_TO_ ## xmacro (v); \ if (dmfwrite(&result, sizeof( xtype ), 1, f) != 1) \ return FALSE; \ return TRUE; \ } -DM_DEFINE_FUNC(le16, Uint16, LE16) -DM_DEFINE_FUNC(le32, Uint32, LE32) -DM_DEFINE_FUNC(le64, Uint64, LE64) +#include "dmfiletmpl.h" -DM_DEFINE_FUNC(be16, Uint16, BE16) -DM_DEFINE_FUNC(be32, Uint32, BE32) -DM_DEFINE_FUNC(be64, Uint64, BE64) +#undef DM_DEFINE_FFUNC diff -r a0c187dae495 -r 9f06f6661cdf src/dmresw.h --- a/src/dmresw.h Mon Mar 02 20:10:44 2015 +0200 +++ b/src/dmresw.h Mon Mar 02 20:16:43 2015 +0200 @@ -13,17 +13,15 @@ extern "C" { #endif -int dmf_write_str(DMResource *, void *, size_t); +int dmf_write_str(DMResource *, const void *, const size_t); BOOL dmf_write_byte(DMResource *, const Uint8); -BOOL dmf_write_be16(DMResource *, Uint16); -BOOL dmf_write_be32(DMResource *, Uint32); -BOOL dmf_write_be64(DMResource *, Uint64); +#define DM_DEFINE_FFUNC(xname, xtype, z) \ +BOOL dmf_write_ ## xname (DMResource *fh, const xtype v); -BOOL dmf_write_le16(DMResource *, Uint16); -BOOL dmf_write_le32(DMResource *, Uint32); -BOOL dmf_write_le64(DMResource *, Uint64); +#include "dmfiletmpl.h" +#undef DM_DEFINE_FFUNC #ifdef __cplusplus }