summaryrefslogtreecommitdiff
path: root/source/base/base_os.h
blob: abe86288c2ff11277f6b75518b64270bf777976d (plain)
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
#ifndef BASE_OS_H
#define BASE_OS_H

internal string8
load_file(const char *path)
{
    string8 result = {0};
    struct stat sbuf = {0};

    s32 file = open(path, O_RDONLY);
    if(file == -1) return result;

    if(fstat(file, &sbuf) == -1)
    {
        print("error: fstat failed");
        close(file);
        return result;
    }

    result.size = (u64)sbuf.st_size;
    if(result.size != 0)
    {
        result.data = (u8 *)mmap(0, result.size, PROT_READ, MAP_PRIVATE, file, 0);
    }

    close(file);
    return result;
}

#endif /* BASE_OS_H */