annotate dmfile.c @ 410:e4b2f689aff6

Stdint -> SDL types conversion.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 03 Nov 2012 02:41:15 +0200
parents d0257d0004f6
children c452a459e552
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * DMLib
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * -- Plain STDIO file endianess functions
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Programmed and designed by Matti 'ccr' Hamalainen
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 * (C) Copyright 2011 Tecnic Software productions (TNSP)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include "dmfile.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
405
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
10 BOOL dm_fread_str(FILE *f, void *buf, const size_t len)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 return fread(buf, len, 1, f) == 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
405
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
16 BOOL dm_fread_byte(FILE *f, Uint8 *val)
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
17 {
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
18 return fread(val, 1, 1, f) == 1;
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
19 }
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
20
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
21
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 #define DM_DEFINE_FFUNC(xname, xtype, xmacro) \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 BOOL dm_fread_ ## xname (FILE *f, xtype *v) { \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 xtype result; \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 if (fread(&result, sizeof( xtype ), 1, f) != 1) \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 return FALSE; \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 *v = DM_ ## xmacro ## _TO_NATIVE (result); \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 return TRUE; \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 #include "dmfiletmpl.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 #undef DM_DEFINE_FFUNC
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
405
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
36
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
37 BOOL dm_fwrite_str(FILE *f, const void *buf, const size_t len)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 return fwrite(buf, len, 1, f) == 1;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
405
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
43 BOOL dm_fwrite_byte(FILE *f, const Uint8 val)
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
44 {
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
45 return fwrite(&val, 1, 1, f) == 1;
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
46 }
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
47
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
48
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 #define DM_DEFINE_FFUNC(xname, xtype, xmacro) \
405
d0257d0004f6 Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
50 BOOL dm_fwrite_ ## xname (FILE *f, const xtype v) { \
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 xtype result = DM_NATIVE_TO_ ## xmacro (v); \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 if (fwrite(&result, sizeof( xtype ), 1, f) != 1) \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 return FALSE; \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 return TRUE; \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 #include "dmfiletmpl.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 #undef DM_DEFINE_FFUNC