summaryrefslogtreecommitdiff
path: root/source/base/base_os.h
blob: ec0a3de0915f4427d531ee50ad9dd556266ba98e (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef BASE_OS_H
#define BASE_OS_H

internal void
print(const char *str)
{
    i32 len = 0;
    while (str[len]) len++;
    write(STDOUT_FILENO, str, len);
}

internal string8
load_file(const char *path)
{
    string8 result = {0};
    struct stat sbuf = {0};
    int err = 0;
    i32 file = open(path, O_RDONLY);

    if(file)
    {

        if(file != -1)
        {
            err = fstat(file, &sbuf);
            check(err != -1);

            result.size = (u64)sbuf.st_size;

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

                check(result.data != MAP_FAILED);
            }

            close(file);
        }
        else
        {
           // TODO(nasr): logging
        }

    }
    return result;
}

#endif /* BASE_OS_H */