summaryrefslogtreecommitdiff
path: root/src/io/read_file.h
blob: 89f738bf012bf6f08646aafc05550967705f15e0 (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
#pragma once

#include <stddef.h>
#include <stdio.h>

enum allow_flags {
  O_NOALLOWMAP = 1 << 0,
  O_NOALLOWSPONGE = 1 << 1,
};

enum mapping_type {
  MT_MMAP,
  MT_OWNED,
};

struct filebuf {
  char *buf;
  size_t sz;
  enum mapping_type mapping_type;
};

struct filebuf *stream_to_filebuf(FILE *restrict stream, int openOptions);
struct filebuf *file_to_filebuf(char *fname, int openOptions);
void free_filebuf(struct filebuf *filebuf);