summaryrefslogtreecommitdiffstatshomepage
path: root/py/lexerfile.c
blob: 74bb5a061a63b82476047f66a4118aa7cdc1188b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

#include "misc.h"
#include "lexer.h"

py_lexer_t *py_lexer_from_file(const char *filename) {
    // TODO abstract away file functionality
    int fd = open(filename, O_RDONLY);
    if (fd < 0) {
        printf("cannot open file %s\n", filename);
        return NULL;
    }
    uint size = lseek(fd, 0, SEEK_END);
    lseek(fd, 0, SEEK_SET);
    char *data = m_new(char, size);
    read(fd, data, size);
    close(fd);

    return py_lexer_from_str_len(filename, data, size, true);
}