-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresourcefork.h
More file actions
155 lines (130 loc) · 4.61 KB
/
resourcefork.h
File metadata and controls
155 lines (130 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Copyright (c) 2019 Tom Hancocks
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <stdint.h>
#include <sys/types.h>
#if !defined(libResourceFork)
#define libResourceFork
// MARK: - Forward Declarations
struct resource_file;
typedef struct resource_file *resource_file_t;
// MARK: - Constants
#define RF_OK 0
#define RF_FILE 1
#define RF_PARSE 2
#define RF_COMPRESSED 3
#define RF_TYPE 4
#define RF_RESOURCE 5
#define RF_MISSING_PATH 6
#define RF_WRITE 7
#define RF_DATA 8
enum resource_file_flags
{
/* Prevent the resource fork from being parsed when opened / created.
* This exists predominantly for the purpose of unit testing. */
rf_no_parse = (1 << 1),
/* Force the extended resource fork format to be used when saving the file */
rf_save_extended = (1 << 2),
/* Do not load resource data into memory. This forces the resource file handle
* to remain open and resource data will be read into memory when requested.
* Additionally this requires the caller to supply a block of memory in which
* the data will be read to. */
rf_no_data = (1 << 3),
};
// MARK: - Function Declarations
/* Open a resource file, and loads into the provided `resource_file_t`.
*
* - Param: A refernece to a resource_file_t structure that will hold all information
* about the loaded resource file.
* - Param: A set of configuration flags to influence how the resource file is loaded.
* - Param: The path to the resource file on disk to be opended.
*
* - Return: A status code regarding the result of opening the resource fork. */
int resource_file_open(resource_file_t *, enum resource_file_flags, const char *restrict);
/* Create a new resource file instance in memory, using the data provided.
* This doesn't create a resource fork on disk, but rather is used by
* `resource_file_open(...)` to setup the `resource_file_t` instance.
*
* - Param: A reference to a resource_file_t structure that will hold all information
* about the loaded resource file.
* - Param: A set of configuration flags to influence how the resource file is loaded.
* - Param: A pointer to the raw resource fork data.
* - Param: An indicator of how many bytes the data consists of.
*
* - Return: A status code regarding the result of creating the resource fork. */
int resource_file_create(resource_file_t *, enum resource_file_flags, void *restrict, ssize_t);
int resource_file_save(resource_file_t, enum resource_file_flags, const char *restrict);
/* Close and deallocate all resources related to the given resource_file_t. */
void resource_file_close(resource_file_t);
/* Free the memory used by the resource file. */
void resource_file_free(resource_file_t);
int resource_file_get_type_count(resource_file_t rf, int *count);
int resource_file_get_resource_count_idx(
resource_file_t rf,
int type,
int *count
);
int resource_file_get_resource_count(
resource_file_t rf,
const char *type_code,
int *count
);
int resource_file_get_type_code(
resource_file_t rf,
int type,
const char **code
);
int resource_file_get_resource_idx(
resource_file_t rf,
int type,
int resource,
int64_t *id,
const char **name,
uint64_t *size
);
int resource_file_get_resource(
resource_file_t rf,
const char *type_code,
int64_t id,
const char **name,
uint64_t *size
);
int resource_file_get_resource_data_idx(
resource_file_t rf,
int type,
int resource,
void *data
);
int resource_file_get_resource_data(
resource_file_t rf,
const char *type_code,
int64_t id,
void *data
);
int resource_file_add_resource(
resource_file_t rf,
const char *type_code,
int64_t id,
const char *name,
uint8_t *data,
uint64_t size
);
#endif