file.c (588B)
1 #include <stdint.h>
2 #include <stdlib.h>
3 #include <stddef.h>
4 #include "file.h"
5 #include "tab.h"
6
7 ta_file *ta_file_open(uint8_t file) {
8 const uint8_t *data;
9 uint32_t size;
10
11 if (!ta_tab_find(file, &data, &size)) {
12 return NULL;
13 }
14
15 ta_file *opened = (ta_file *)malloc(sizeof(ta_file) + size);
16
17 if (opened == NULL) {
18 return NULL;
19 }
20
21 opened->file = file;
22 opened->size = size;
23
24 for (uint32_t i = 0; i < size; i++) {
25 opened->data[i] = (char)data[i];
26 }
27
28 return opened;
29 }
30
31 void ta_file_close(ta_file *file) {
32 free(file);
33 }