-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtrtl_loader_file.c
51 lines (41 loc) · 1019 Bytes
/
trtl_loader_file.c
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
#include "trtl_loader_file.h"
#include "blobby.h"
#include <talloc.h>
struct trtl_loader_file {
struct trtl_loader loader;
const char *path;
};
struct blobby *
floader_load(struct trtl_loader *loader, const char *objname)
{
struct trtl_loader_file *floader = talloc_get_type(loader, struct trtl_loader_file);
char *path;
struct blobby *blobby;
path = talloc_asprintf(NULL, "%s/%s", floader->path, objname);
printf("file loader loading: %s\n", path);
if (!path) {
return NULL;
}
blobby = blobby_from_file(path);
if (blobby) {
blobby->source = talloc_steal(blobby, path);
return blobby;
}
talloc_free(path);
if (loader->next) {
return loader->next->load(loader->next, objname);
}
return NULL;
}
struct trtl_loader *
trtl_loader_file(const char *path)
{
struct trtl_loader_file *floader;
if (!path) {
return NULL;
}
floader = talloc_zero(NULL, struct trtl_loader_file);
floader->path = talloc_strdup(floader, path);
floader->loader.load = floader_load;
return &floader->loader;
}