all repos — mgba @ 67072e649ca12ccf8e60e0b76d9c7f21a657a644

mGBA Game Boy Advance Emulator

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
11#ifndef _WIN32
12#include <sys/mman.h>
13#define PATH_SEP "/"
14#else
15#include <io.h>
16#include <windows.h>
17#define PATH_SEP "\\"
18#endif
19
20#ifndef PATH_MAX
21#ifdef MAX_PATH
22#define PATH_MAX MAX_PATH
23#else
24#define PATH_MAX 128
25#endif
26#endif
27
28enum {
29	MAP_READ = 1,
30	MAP_WRITE = 2
31};
32
33struct VFile {
34	bool (*close)(struct VFile* vf);
35	off_t (*seek)(struct VFile* vf, off_t offset, int whence);
36	ssize_t (*read)(struct VFile* vf, void* buffer, size_t size);
37	ssize_t (*readline)(struct VFile* vf, char* buffer, size_t size);
38	ssize_t (*write)(struct VFile* vf, const void* buffer, size_t size);
39	void* (*map)(struct VFile* vf, size_t size, int flags);
40	void (*unmap)(struct VFile* vf, void* memory, size_t size);
41	void (*truncate)(struct VFile* vf, size_t size);
42	ssize_t (*size)(struct VFile* vf);
43};
44
45struct VDirEntry {
46	const char* (*name)(struct VDirEntry* vde);
47};
48
49struct VDir {
50	bool (*close)(struct VDir* vd);
51	void (*rewind)(struct VDir* vd);
52	struct VDirEntry* (*listNext)(struct VDir* vd);
53	struct VFile* (*openFile)(struct VDir* vd, const char* name, int mode);
54};
55
56struct VFile* VFileOpen(const char* path, int flags);
57struct VFile* VFileFromFD(int fd);
58struct VFile* VFileFromMemory(void* mem, size_t size);
59
60struct VDir* VDirOpen(const char* path);
61
62#ifdef USE_LIBZIP
63struct VDir* VDirOpenZip(const char* path, int flags);
64#endif
65
66#ifdef USE_LZMA
67struct VDir* VDirOpen7z(const char* path, int flags);
68#endif
69
70struct VFile* VDirOptionalOpenFile(struct VDir* dir, const char* realPath, const char* prefix, const char* suffix, int mode);
71struct VFile* VDirOptionalOpenIncrementFile(struct VDir* dir, const char* realPath, const char* prefix, const char* infix, const char* suffix, int mode);
72
73ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size);
74
75ssize_t VFileWrite32LE(struct VFile* vf, int32_t word);
76ssize_t VFileWrite16LE(struct VFile* vf, int16_t hword);
77ssize_t VFileRead32LE(struct VFile* vf, void* word);
78ssize_t VFileRead16LE(struct VFile* vf, void* hword);
79
80#endif