annotate src/dmres.h @ 2586:9807ae37ad69

Require stdbool.h, we require C11 now.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 08 Dec 2022 15:59:22 +0200
parents 8193f62a541d
children
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 DRF_USE_PACK = 0x0001,
613
15cd5b8a29b2 Add DRF_USE_STDIO flag for resources.
Matti Hamalainen <ccr@tnsp.org>
parents: 602
diff changeset
26 DRF_USE_STDIO = 0x0002,
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
27 DRF_PRELOAD_RAW = 0x0004,
613
15cd5b8a29b2 Add DRF_USE_STDIO flag for resources.
Matti Hamalainen <ccr@tnsp.org>
parents: 602
diff changeset
28 DRF_PRELOAD_RES = 0x0008,
0
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 enum
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 {
1040
ebabf5aefb76 Work on resource handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
33 DMF_PERSIST = 0x0001, // Persist loaded RAW resource
ebabf5aefb76 Work on resource handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
34 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
35 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
36
ebabf5aefb76 Work on resource handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
37 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
38 DMF_LOADED_RAW = 0x2000, // Raw data has been loaded
ebabf5aefb76 Work on resource handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
39 DMF_LOADED_RES = 0x4000, // Resource has been loaded
0
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 /* Typedefs and structures
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 */
359
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
45 struct DMResourceLib;
26
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
46 struct DMResourceDataOps;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 struct DMResourceOps;
26
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
48 struct DMResource;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
26
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
50 typedef struct DMResource
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 // Timestamps (in seconds from time())
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 int refcount; // Reference count
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 int flags; // Resource flags (DMF_*)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 char *filename;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
58 // Raw data (or mem data)
2437
f7d54ac51880 Fix and improvements to dmres MemIO subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
59 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
60 size_t memSize; // Size of data
f7d54ac51880 Fix and improvements to dmres MemIO subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
61 size_t memAlloc; // Amount allocated
f7d54ac51880 Fix and improvements to dmres MemIO subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
62 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
63 off_t memOffset; // Current offset in data
f7d54ac51880 Fix and improvements to dmres MemIO subsystem.
Matti Hamalainen <ccr@tnsp.org>
parents: 2385
diff changeset
64 Uint8 *memData; // Pointer to data
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
65
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
66 // Decoded resource data
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
67 void *resData;
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
68 size_t resSize;
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
69 struct DMResourceDataOps *rops;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
2445
fa089a430121 Cleanup, rename DMResource::error to DMResource::status.
Matti Hamalainen <ccr@tnsp.org>
parents: 2437
diff changeset
71 int status; // Error / status code (DMERR_*)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
73 #ifdef DM_USE_STDIO
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
74 FILE * fh; // File handle for stdio
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
75 #endif
26
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
76
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
77 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
78 struct DMResourceLib *lib; // Pointer to the resource library
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
79 struct DMResource *next, *prev;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 } DMResource;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
26
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
83 typedef struct DMResourceDataOps
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
84 {
2586
9807ae37ad69 Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents: 2446
diff changeset
85 bool (*probe)(DMResource *res, const char *fext);
26
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
86 int (*load)(DMResource *res);
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
87 void (*free)(DMResource *res);
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
88 } DMResourceDataOps;
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
89
2f463a59d732 Implement rudimentary resource system.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
90
359
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
91 typedef struct DMResourceLib
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
92 {
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
93 int flags;
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
94 char *resPath;
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
95
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
96 DMResource *resources, *preload;
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
97 DMMutex *mutex;
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
98
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
99 #ifdef DM_USE_PACKFS
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
100 char *packFilename;
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
101 DMPackFile *packFile;
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
102 #endif
59045853853d Make resource management re-entrant.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
103 } DMResourceLib;
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
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 typedef struct DMResourceOps
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 {
728
867fc7f205a8 More work on resource handling cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 722
diff changeset
108 char *name;
732
2f02d9b4caa3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 731
diff changeset
109
2446
8193f62a541d Remove some useless complexity from resource system .. could remove more.
Matti Hamalainen <ccr@tnsp.org>
parents: 2445
diff changeset
110 int (*fopen)(DMResource *);
8193f62a541d Remove some useless complexity from resource system .. could remove more.
Matti Hamalainen <ccr@tnsp.org>
parents: 2445
diff changeset
111 void (*fclose)(DMResource *);
8193f62a541d Remove some useless complexity from resource system .. could remove more.
Matti Hamalainen <ccr@tnsp.org>
parents: 2445
diff changeset
112 int (*preload)(DMResource *);
8193f62a541d Remove some useless complexity from resource system .. could remove more.
Matti Hamalainen <ccr@tnsp.org>
parents: 2445
diff changeset
113
732
2f02d9b4caa3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 731
diff changeset
114 int (*freset)(DMResource *);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 int (*ferror)(DMResource *);
1106
f8e9f6b2a41a Hmm .. back out the Sint64 changes for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1088
diff changeset
116 int (*fseek)(DMResource *, const off_t, const int);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 off_t (*fsize)(DMResource *);
1106
f8e9f6b2a41a Hmm .. back out the Sint64 changes for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 1088
diff changeset
118 off_t (*ftell)(DMResource *);
2586
9807ae37ad69 Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents: 2446
diff changeset
119 bool (*feof)(DMResource *);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 int (*fgetc)(DMResource *);
59
c560703e85ed Add resource writing functions (only work for stdio backend)
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
121 int (*fputc)(int, DMResource *);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 size_t (*fread)(void *, const size_t, const size_t, DMResource *);
1086
7681f7063500 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 1047
diff changeset
123 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
124
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 } DMResourceOps;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 /* Functions
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 */
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
130 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
131 int dmResourcesClose(DMResourceLib *lib);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
2586
9807ae37ad69 Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents: 2446
diff changeset
133 int dmResourcesPreload(DMResourceLib *lib, bool start, int *loaded, int *total);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
1040
ebabf5aefb76 Work on resource handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1036
diff changeset
135 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
136 void dmResourceFree(DMResource *node);
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
137 void dmResourceInsert(DMResourceLib *lib, DMResource * node);
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
138 void dmResourceDelete(DMResourceLib *lib, DMResource * node);
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
139 DMResource * dmResourceFind(DMResourceLib *lib, const char *filename);
2446
8193f62a541d Remove some useless complexity from resource system .. could remove more.
Matti Hamalainen <ccr@tnsp.org>
parents: 2445
diff changeset
140
721
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
141 int dmResourceRef(DMResource *);
bb14d7907eb2 Rename many pack & resource handling functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 625
diff changeset
142 int dmResourceUnref(DMResource *);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 // Opening and closing resources
1607
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
146 int dmf_open(DMResourceLib *lib, const char *, DMResource **phandle);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
147 void dmf_close(DMResource *fh);
914
9ab4fb6458f9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 872
diff changeset
148
1606
93d1050eac99 Rename dmf_create_*() functions to dmf_open_*().
Matti Hamalainen <ccr@tnsp.org>
parents: 1106
diff changeset
149 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
150 #ifdef DM_USE_STDIO
1606
93d1050eac99 Rename dmf_create_*() functions to dmf_open_*().
Matti Hamalainen <ccr@tnsp.org>
parents: 1106
diff changeset
151 int dmf_open_stdio(const char *filename, const char *mode, DMResource **phandle);
1607
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
152 int dmf_open_stdio_stream(FILE *fh, DMResource **phandle);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 // Basic resource access functions
1607
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
157 int dmfreset(DMResource *fh);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
158 int dmferror(DMResource *fh);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
159 int dmfseek(DMResource *fh, const off_t offset, const int whence);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
160 off_t dmfsize(DMResource *fh);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
161 off_t dmftell(DMResource *fh);
2586
9807ae37ad69 Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents: 2446
diff changeset
162 bool dmfeof(DMResource *fh);
1607
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
163 int dmfgetc(DMResource *fh);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
164 int dmfputc(int val, DMResource *fh);
0cac3360a0aa Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1606
diff changeset
165 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
166 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
167 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
168 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
169 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
170 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
171 DM_ATTR_PRINTF_FMT(2, 3);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172
437
3d9c044ec08d Add dmf_{write,read}_byte() convenience functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
173 // Helper functions for endianess based reading etc
2586
9807ae37ad69 Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents: 2446
diff changeset
174 bool dmf_read_str(DMResource *fh, void *ptr, const size_t len);
9807ae37ad69 Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents: 2446
diff changeset
175 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
176
1088
9f06f6661cdf Cleanups for file endianess read/write helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1087
diff changeset
177 #define DM_DEFINE_FFUNC(xname, xtype, z) \
2586
9807ae37ad69 Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents: 2446
diff changeset
178 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
179
1088
9f06f6661cdf Cleanups for file endianess read/write helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1087
diff changeset
180 #include "dmfiletmpl.h"
9f06f6661cdf Cleanups for file endianess read/write helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1087
diff changeset
181
9f06f6661cdf Cleanups for file endianess read/write helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1087
diff changeset
182 #undef DM_DEFINE_FFUNC
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183
2586
9807ae37ad69 Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents: 2446
diff changeset
184 bool dmf_write_str(DMResource *fh, const void *data, const size_t len);
9807ae37ad69 Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents: 2446
diff changeset
185 bool dmf_write_byte(DMResource *fh, const Uint8 val);
1881
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
186
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
187 #define DM_DEFINE_FFUNC(xname, xtype, z) \
2586
9807ae37ad69 Require stdbool.h, we require C11 now.
Matti Hamalainen <ccr@tnsp.org>
parents: 2446
diff changeset
188 bool dmf_write_ ## xname (DMResource *fh, const xtype v);
1881
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
189
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
190 #include "dmfiletmpl.h"
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
191
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
192 #undef DM_DEFINE_FFUNC
73545a442ffe Move dmresw function declarations to dmres.h
Matti Hamalainen <ccr@tnsp.org>
parents: 1608
diff changeset
193
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 #ifdef __cplusplus
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 #endif // DMRES_H