-
Notifications
You must be signed in to change notification settings - Fork 110
/
p_load.c
48 lines (39 loc) · 1.04 KB
/
p_load.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
#include <pal.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "pal_base.h"
#include "pal_base_private.h"
/**
*
* Loads a program from a file into an object in memory and prepares the program
* for execution.
*
* @param dev Pointer to object containing device information
* @param file File name of executable to load.
* @param flags Optional flags
*
* @return Returns a reference. Negative value indicates error.
*
*/
p_prog_t p_load(p_dev_t dev, const char *file, int flags)
{
size_t len;
struct prog *prog;
if (p_ref_is_err(dev))
return p_ref_err(EINVAL);
len = strnlen(file, 4096);
if (len == 4096)
return p_ref_err(ENAMETOOLONG);
prog = malloc(sizeof(*prog));
if (!prog)
return p_ref_err(ENOMEM);
prog->path = strndup(file, len);;
if (!prog->path) {
free(prog);
return p_ref_err(ENOMEM);
}
return prog;
// TODO: Load into memory etc.
// TODO: Add to global prog table. We're leaking memory here people.
}