src/util/vfs.h (view raw)
1/* Copyright (c) 2013-2014 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef VFS_H
7#define VFS_H
8
9#include "util/common.h"
10
11enum {
12 MAP_READ = 1,
13 MAP_WRITE = 2
14};
15
16struct VFile {
17 bool (*close)(struct VFile* vf);
18 off_t (*seek)(struct VFile* vf, off_t offset, int whence);
19 ssize_t (*read)(struct VFile* vf, void* buffer, size_t size);
20 ssize_t (*readline)(struct VFile* vf, char* buffer, size_t size);
21 ssize_t (*write)(struct VFile* vf, const void* buffer, size_t size);
22 void* (*map)(struct VFile* vf, size_t size, int flags);
23 void (*unmap)(struct VFile* vf, void* memory, size_t size);
24 void (*truncate)(struct VFile* vf, size_t size);
25};
26
27struct VDirEntry {
28 const char* (*name)(struct VDirEntry* vde);
29};
30
31struct VDir {
32 bool (*close)(struct VDir* vd);
33 void (*rewind)(struct VDir* vd);
34 struct VDirEntry* (*listNext)(struct VDir* vd);
35 struct VFile* (*openFile)(struct VDir* vd, const char* name, int mode);
36};
37
38struct VFile* VFileOpen(const char* path, int flags);
39struct VFile* VFileFromFD(int fd);
40
41struct VDir* VDirOpen(const char* path);
42
43#ifdef ENABLE_LIBZIP
44struct VDir* VDirOpenZip(const char* path, int flags);
45#endif
46
47struct VFile* VDirOptionalOpenFile(struct VDir* dir, const char* realPath, const char* prefix, const char* suffix, int mode);
48struct VFile* VDirOptionalOpenIncrementFile(struct VDir* dir, const char* realPath, const char* prefix, const char* infix, const char* suffix, int mode);
49
50#endif