0
|
1 /*
|
|
2 * DMLib
|
|
3 * -- Plain STDIO file endianess functions
|
|
4 * Programmed and designed by Matti 'ccr' Hamalainen
|
|
5 * (C) Copyright 2011 Tecnic Software productions (TNSP)
|
|
6 */
|
|
7 #include "dmfile.h"
|
|
8
|
|
9
|
|
10 BOOL dm_fread_str(FILE *f, void *buf, size_t len)
|
|
11 {
|
|
12 return fread(buf, len, 1, f) == 1;
|
|
13 }
|
|
14
|
|
15
|
|
16 #define DM_DEFINE_FFUNC(xname, xtype, xmacro) \
|
|
17 BOOL dm_fread_ ## xname (FILE *f, xtype *v) { \
|
|
18 xtype result; \
|
|
19 if (fread(&result, sizeof( xtype ), 1, f) != 1) \
|
|
20 return FALSE; \
|
|
21 *v = DM_ ## xmacro ## _TO_NATIVE (result); \
|
|
22 return TRUE; \
|
|
23 }
|
|
24
|
|
25 #include "dmfiletmpl.h"
|
|
26
|
|
27
|
|
28 #undef DM_DEFINE_FFUNC
|
|
29
|
|
30 BOOL dm_fwrite_str(FILE *f, void *buf, size_t len)
|
|
31 {
|
|
32 return fwrite(buf, len, 1, f) == 1;
|
|
33 }
|
|
34
|
|
35
|
|
36 #define DM_DEFINE_FFUNC(xname, xtype, xmacro) \
|
|
37 BOOL dm_fwrite_ ## xname (FILE *f, xtype v) { \
|
|
38 xtype result = DM_NATIVE_TO_ ## xmacro (v); \
|
|
39 if (fwrite(&result, sizeof( xtype ), 1, f) != 1) \
|
|
40 return FALSE; \
|
|
41 return TRUE; \
|
|
42 }
|
|
43
|
|
44 #include "dmfiletmpl.h"
|
|
45
|
|
46 #undef DM_DEFINE_FFUNC
|