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

#include <stdbool.h>
#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, bool *isdir);
void free_filebuf(struct filebuf *filebuf);