close file descriptor after read

This commit is contained in:
FelixKratz 2021-09-07 15:56:35 +02:00
parent d7068af000
commit 96a31a1d90

View file

@ -107,10 +107,12 @@ static inline char *string_copy(char *s) {
return result; return result;
} }
char* read_file(char* path) { static inline char* read_file(char* path) {
int fd = open(path, O_RDONLY); int fd = open(path, O_RDONLY);
int len = lseek(fd, 0, SEEK_END); int len = lseek(fd, 0, SEEK_END);
return mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0); char* file = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0);
close(fd);
return file;
} }
static inline char* resolve_path(char* path) { static inline char* resolve_path(char* path) {