all repos — mgba @ 0d1d5c988e2f60abb5c05a8cd61bdd9ec16d94f1

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 "/" // Windows can handle slashes, and backslashes confuse some libraries
 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
 32enum VFSType {
 33	VFS_UNKNOWN = 0,
 34	VFS_FILE,
 35	VFS_DIRECTORY
 36};
 37
 38struct VFile {
 39	bool (*close)(struct VFile* vf);
 40	off_t (*seek)(struct VFile* vf, off_t offset, int whence);
 41	ssize_t (*read)(struct VFile* vf, void* buffer, size_t size);
 42	ssize_t (*readline)(struct VFile* vf, char* buffer, size_t size);
 43	ssize_t (*write)(struct VFile* vf, const void* buffer, size_t size);
 44	void* (*map)(struct VFile* vf, size_t size, int flags);
 45	void (*unmap)(struct VFile* vf, void* memory, size_t size);
 46	void (*truncate)(struct VFile* vf, size_t size);
 47	ssize_t (*size)(struct VFile* vf);
 48	bool (*sync)(struct VFile* vf, const void* buffer, size_t size);
 49};
 50
 51struct VDirEntry {
 52	const char* (*name)(struct VDirEntry* vde);
 53	enum VFSType (*type)(struct VDirEntry* vde);
 54};
 55
 56struct VDir {
 57	bool (*close)(struct VDir* vd);
 58	void (*rewind)(struct VDir* vd);
 59	struct VDirEntry* (*listNext)(struct VDir* vd);
 60	struct VFile* (*openFile)(struct VDir* vd, const char* name, int mode);
 61	struct VDir* (*openDir)(struct VDir* vd, const char* name);
 62	bool (*deleteFile)(struct VDir* vd, const char* name);
 63};
 64
 65struct VFile* VFileOpen(const char* path, int flags);
 66
 67struct VFile* VFileOpenFD(const char* path, int flags);
 68struct VFile* VFileFOpen(const char* path, const char* mode);
 69struct VFile* VFileFromFD(int fd);
 70struct VFile* VFileFromMemory(void* mem, size_t size);
 71struct VFile* VFileFromConstMemory(const void* mem, size_t size);
 72struct VFile* VFileMemChunk(const void* mem, size_t size);
 73struct VFile* VFileFromFILE(FILE* file);
 74
 75struct VDir* VDirOpen(const char* path);
 76struct VDir* VDirOpenArchive(const char* path);
 77
 78#if defined(USE_LIBZIP) || defined(USE_ZLIB)
 79struct VDir* VDirOpenZip(const char* path, int flags);
 80#endif
 81
 82#ifdef USE_LZMA
 83struct VDir* VDirOpen7z(const char* path, int flags);
 84#endif
 85
 86struct VDir* VDeviceList(void);
 87
 88void separatePath(const char* path, char* dirname, char* basename, char* extension);
 89
 90struct VFile* VDirFindFirst(struct VDir* dir, bool (*filter)(struct VFile*));
 91struct VFile* VDirFindNextAvailable(struct VDir*, const char* basename, const char* infix, const char* suffix, int mode);
 92
 93ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size);
 94
 95ssize_t VFileWrite32LE(struct VFile* vf, int32_t word);
 96ssize_t VFileWrite16LE(struct VFile* vf, int16_t hword);
 97ssize_t VFileRead32LE(struct VFile* vf, void* word);
 98ssize_t VFileRead16LE(struct VFile* vf, void* hword);
 99
100#endif