annotate src/dmres.h @ 2437:f7d54ac51880

Fix and improvements to dmres MemIO subsystem.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 25 Feb 2020 07:26:40 +0200
parents 5ffc48a0bebe
children fa089a430121
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 * -- Resource management
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Programmed and designed by Matti 'ccr' Hamalainen
863
27949209238b Update copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
5 * (C) Copyright 2011-2015 Tecnic Software productions (TNSP)
0
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 #ifndef DMRES_H
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #define DMRES_H
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include "dmlib.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
124
d5cfd29c87c4 Rename some conditional compilation directives.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
12 #ifdef DM_USE_PACKFS
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include "dmpack.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #ifdef __cplusplus
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 extern "C" {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 /* Constants
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 DMPRUNE_ATIME = 0x0001,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 DMPRUNE_MTIME = 0x0002,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 enum
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 DRF_USE_PACK = 0x0001,
613
15cd5b8a29b2 Add DRF_USE_STDIO flag for resources.
Matti Hamalainen <ccr@tnsp.org>
parents: 602
diff changeset
32 DRF_USE_STDIO = 0x0002,
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
33 DRF_PRELOAD_RAW = 0x0004,
613
15cd5b8a29b2 Add DRF_USE_STDIO flag for resources.
Matti Hamalainen <ccr@tnsp.org>
parents: 602
diff changeset
34 DRF_PRELOAD_RES = 0x0008,
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 {
1040
ebabf5aefb76 Work on resource handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
39 DMF_PERSIST = 0x0001, // Persist loaded RAW resource
ebabf5aefb76 Work on resource handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
40 DMF_COMPRESSED = 0x0002, // Resource is compressed in PACK file, otherwise raw
ebabf5aefb76 Work on resource handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
41 DMF_TEMPORARY = 0x0004,
ebabf5aefb76 Work on resource handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
42 DMF_PACK_MASK = 0x00ff, // Mask for flags that may be specified in PACK
ebabf5aefb76 Work on resource handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
43
ebabf5aefb76 Work on resource handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
44 DMF_UNALLOCATED = 0x1000, // The raw data is not allocated, so do not free it
ebabf5aefb76 Work on resource handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
45 DMF_LOADED_RAW = 0x2000, // Raw data has been loaded
ebabf5aefb76 Work on resource handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
46 DMF_LOADED_RES = 0x4000, // Resource has been loaded
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 };
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 /* Typedefs and structures
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 */
359
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
52 struct DMResourceLib;
26
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
53 struct DMResourceDataOps;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 struct DMResourceOps;
26
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
55 struct DMResource;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
26
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
57 typedef struct DMResource
0
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 // Timestamps (in seconds from time())
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 int mtime, // When resource was loaded
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
61 atime; // Last accessed (dmResourceRef()/unref)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 int refcount; // Reference count
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 int flags; // Resource flags (DMF_*)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 char *filename;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
67 // Raw data (or mem data)
2437
f7d54ac51880 Fix and improvements to dmres MemIO subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
68 size_t maxSize; // Maximum size (0 = no limit)
f7d54ac51880 Fix and improvements to dmres MemIO subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
69 size_t memSize; // Size of data
f7d54ac51880 Fix and improvements to dmres MemIO subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
70 size_t memAlloc; // Amount allocated
f7d54ac51880 Fix and improvements to dmres MemIO subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
71 size_t minAlloc; // Minimum allocation increase (0 = default)
f7d54ac51880 Fix and improvements to dmres MemIO subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
72 off_t memOffset; // Current offset in data
f7d54ac51880 Fix and improvements to dmres MemIO subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
73 Uint8 *memData; // Pointer to data
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
74
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
75 // Decoded resource data
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
76 void *resData;
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
77 size_t resSize;
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
78 struct DMResourceDataOps *rops;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 int error; // Error code
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
82 #ifdef DM_USE_STDIO
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
83 FILE * fh; // File handle for stdio
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
84 #endif
26
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
85
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
86 struct DMResourceOps *fops; // Pointer to file handling functions struct
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
87 struct DMResourceLib *lib; // Pointer to the resource library
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
88 struct DMResource *next, *prev;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 } DMResource;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
26
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
92 typedef struct DMResourceDataOps
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
93 {
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 103
diff changeset
94 BOOL (*probe)(DMResource *res, const char *fext);
26
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
95 int (*load)(DMResource *res);
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
96 void (*free)(DMResource *res);
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
97 } DMResourceDataOps;
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
98
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
99
359
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
100 typedef struct DMResourceLib
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
101 {
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
102 int flags;
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
103 char *resPath;
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
104
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
105 DMResource *resources, *preload;
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
106 DMMutex *mutex;
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
107
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
108 #ifdef DM_USE_PACKFS
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
109 char *packFilename;
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
110 DMPackFile *packFile;
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
111 #endif
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
112 } DMResourceLib;
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
113
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
114
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 typedef struct DMResourceOps
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 {
728
867fc7f205a8 More work on resource handling cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 722
diff changeset
117 char *name;
732
2f02d9b4caa3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 731
diff changeset
118
2f02d9b4caa3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 731
diff changeset
119 int (*freset)(DMResource *);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 int (*ferror)(DMResource *);
1106
f8e9f6b2a41a Hmm .. back out the Sint64 changes for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1088
diff changeset
121 int (*fseek)(DMResource *, const off_t, const int);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 off_t (*fsize)(DMResource *);
1106
f8e9f6b2a41a Hmm .. back out the Sint64 changes for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1088
diff changeset
123 off_t (*ftell)(DMResource *);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 BOOL (*feof)(DMResource *);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 int (*fgetc)(DMResource *);
59
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
126 int (*fputc)(int, DMResource *);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 size_t (*fread)(void *, const size_t, const size_t, DMResource *);
1086
7681f7063500 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 1047
diff changeset
128 size_t (*fwrite)(const void *, const size_t, const size_t, DMResource *);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 int (*fopen)(DMResource *);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 void (*fclose)(DMResource *);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 int (*preload)(DMResource *);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 } DMResourceOps;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 /* Functions
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 */
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
138 int dmResourcesInit(DMResourceLib **lib, const char *filename, const char *path, const int flags, int (*classifier)(DMResource *));
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
139 int dmResourcesClose(DMResourceLib *lib);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
141 void dmResourcesPrune(DMResourceLib *lib, const int agems, int const flags);
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
142 int dmResourcesPreload(DMResourceLib *lib, BOOL start, int *loaded, int *total);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143
1040
ebabf5aefb76 Work on resource handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
144 DMResource * dmResourceNew(DMResourceLib *lib, const char *filename, const size_t size, const int flags);
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
145 void dmResourceFree(DMResource *node);
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
146 void dmResourceInsert(DMResourceLib *lib, DMResource * node);
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
147 void dmResourceDelete(DMResourceLib *lib, DMResource * node);
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
148 DMResource * dmResourceFind(DMResourceLib *lib, const char *filename);
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
149 int dmResourceRef(DMResource *);
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
150 int dmResourceUnref(DMResource *);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 // Opening and closing resources
1607
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
154 int dmf_open(DMResourceLib *lib, const char *, DMResource **phandle);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
155 void dmf_close(DMResource *fh);
914
9ab4fb6458f9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 872
diff changeset
156
1606
93d1050eac99 Rename dmf_create_*() functions to dmf_open_*().
Matti Hamalainen <ccr@tnsp.org>
parents: 1106
diff changeset
157 int dmf_open_memio(DMResourceLib *lib, const char *, Uint8 *buf, size_t len, DMResource **phandle);
124
d5cfd29c87c4 Rename some conditional compilation directives.
Matti Hamalainen <ccr@tnsp.org>
parents: 114
diff changeset
158 #ifdef DM_USE_STDIO
1606
93d1050eac99 Rename dmf_create_*() functions to dmf_open_*().
Matti Hamalainen <ccr@tnsp.org>
parents: 1106
diff changeset
159 int dmf_open_stdio(const char *filename, const char *mode, DMResource **phandle);
1607
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
160 int dmf_open_stdio_stream(FILE *fh, DMResource **phandle);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 // Basic resource access functions
1607
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
165 int dmfreset(DMResource *fh);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
166 int dmferror(DMResource *fh);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
167 int dmfseek(DMResource *fh, const off_t offset, const int whence);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
168 off_t dmfsize(DMResource *fh);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
169 off_t dmftell(DMResource *fh);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
170 BOOL dmfeof(DMResource *fh);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
171 int dmfgetc(DMResource *fh);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
172 int dmfputc(int val, DMResource *fh);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
173 size_t dmfread(void *ptr, const size_t size, const size_t nmemb, DMResource *fh);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
174 size_t dmfwrite(const void *ptr, const size_t size, const size_t nmemb, DMResource *fh);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
175 char * dmfgets(char *str, const int size, DMResource *fh);
1608
7f9fe2a9a87e Implement dmfputs() in DMResource subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents: 1607
diff changeset
176 int dmfputs(const char *str, DMResource *fh);
1885
e69de47d2419 Implement resource helper functions dmfprintf() and dmvfprintf().
Matti Hamalainen <ccr@tnsp.org>
parents: 1881
diff changeset
177 int dmvfprintf(DMResource *fh, const char *fmt, va_list ap);
2383
43e39d9ec42f Add __attribute__(__format__ ..) specifiers for functions that use printf() style format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 1885
diff changeset
178 int dmfprintf(DMResource *fh, const char *fmt, ...)
2385
5ffc48a0bebe Conditionally define DM_ATTR_PRINTF_FMT(xstart, xend) instead of using
Matti Hamalainen <ccr@tnsp.org>
parents: 2383
diff changeset
179 DM_ATTR_PRINTF_FMT(2, 3);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180
437
3d9c044ec08d Add dmf_{write,read}_byte() convenience functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
181 // Helper functions for endianess based reading etc
1607
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
182 BOOL dmf_read_str(DMResource *fh, void *ptr, const size_t len);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
183 BOOL dmf_read_byte(DMResource *fh, Uint8 *val);
437
3d9c044ec08d Add dmf_{write,read}_byte() convenience functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
184
1088
9f06f6661cdf Cleanups for file endianess read/write helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1087
diff changeset
185 #define DM_DEFINE_FFUNC(xname, xtype, z) \
9f06f6661cdf Cleanups for file endianess read/write helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1087
diff changeset
186 BOOL dmf_read_ ## xname (DMResource *fh, xtype *v);
872
b01d04e44b6f Assume we always have 64bit type.
Matti Hamalainen <ccr@tnsp.org>
parents: 863
diff changeset
187
1088
9f06f6661cdf Cleanups for file endianess read/write helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1087
diff changeset
188 #include "dmfiletmpl.h"
9f06f6661cdf Cleanups for file endianess read/write helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1087
diff changeset
189
9f06f6661cdf Cleanups for file endianess read/write helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1087
diff changeset
190 #undef DM_DEFINE_FFUNC
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
1881
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
192 BOOL dmf_write_str(DMResource *fh, const void *data, const size_t len);
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
193 BOOL dmf_write_byte(DMResource *fh, const Uint8 val);
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
194
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
195 #define DM_DEFINE_FFUNC(xname, xtype, z) \
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
196 BOOL dmf_write_ ## xname (DMResource *fh, const xtype v);
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
197
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
198 #include "dmfiletmpl.h"
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
199
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
200 #undef DM_DEFINE_FFUNC
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
201
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 #ifdef __cplusplus
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 #endif // DMRES_H