all repos — mgba @ 250d3b940dc06961a320811678dac67e5a77484f

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