2014-12-03 08:39:06 +00:00
|
|
|
/* Copyright (c) 2013-2014 Jeffrey Pfau
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2014-07-17 06:55:09 +00:00
|
|
|
#ifndef VFS_H
|
|
|
|
#define VFS_H
|
2014-07-16 08:31:10 +00:00
|
|
|
|
2014-10-12 01:18:47 +00:00
|
|
|
#include "util/common.h"
|
2014-07-16 08:31:10 +00:00
|
|
|
|
2014-07-20 08:36:18 +00:00
|
|
|
enum {
|
|
|
|
MAP_READ = 1,
|
|
|
|
MAP_WRITE = 2
|
|
|
|
};
|
2014-07-16 09:08:54 +00:00
|
|
|
|
2014-07-16 08:31:10 +00:00
|
|
|
struct VFile {
|
|
|
|
bool (*close)(struct VFile* vf);
|
2014-07-16 10:02:16 +00:00
|
|
|
off_t (*seek)(struct VFile* vf, off_t offset, int whence);
|
|
|
|
ssize_t (*read)(struct VFile* vf, void* buffer, size_t size);
|
|
|
|
ssize_t (*readline)(struct VFile* vf, char* buffer, size_t size);
|
2014-10-14 10:08:39 +00:00
|
|
|
ssize_t (*write)(struct VFile* vf, const void* buffer, size_t size);
|
2014-07-16 09:08:54 +00:00
|
|
|
void* (*map)(struct VFile* vf, size_t size, int flags);
|
|
|
|
void (*unmap)(struct VFile* vf, void* memory, size_t size);
|
|
|
|
void (*truncate)(struct VFile* vf, size_t size);
|
2015-01-11 08:35:22 +00:00
|
|
|
ssize_t (*size)(struct VFile* vf);
|
2014-07-16 08:31:10 +00:00
|
|
|
};
|
|
|
|
|
2014-07-17 06:55:09 +00:00
|
|
|
struct VDirEntry {
|
|
|
|
const char* (*name)(struct VDirEntry* vde);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VDir {
|
|
|
|
bool (*close)(struct VDir* vd);
|
2014-07-17 07:53:17 +00:00
|
|
|
void (*rewind)(struct VDir* vd);
|
2014-07-17 06:55:09 +00:00
|
|
|
struct VDirEntry* (*listNext)(struct VDir* vd);
|
|
|
|
struct VFile* (*openFile)(struct VDir* vd, const char* name, int mode);
|
|
|
|
};
|
|
|
|
|
2014-07-16 08:31:10 +00:00
|
|
|
struct VFile* VFileOpen(const char* path, int flags);
|
|
|
|
struct VFile* VFileFromFD(int fd);
|
2015-03-06 02:44:28 +00:00
|
|
|
struct VFile* VFileFromMemory(void* mem, size_t size);
|
2014-07-16 08:31:10 +00:00
|
|
|
|
2014-07-17 06:55:09 +00:00
|
|
|
struct VDir* VDirOpen(const char* path);
|
|
|
|
|
2014-07-17 09:45:17 +00:00
|
|
|
#ifdef ENABLE_LIBZIP
|
|
|
|
struct VDir* VDirOpenZip(const char* path, int flags);
|
|
|
|
#endif
|
|
|
|
|
2015-01-25 08:11:05 +00:00
|
|
|
#ifdef ENABLE_LZMA
|
|
|
|
struct VDir* VDirOpen7z(const char* path, int flags);
|
|
|
|
#endif
|
|
|
|
|
2014-10-10 06:55:02 +00:00
|
|
|
struct VFile* VDirOptionalOpenFile(struct VDir* dir, const char* realPath, const char* prefix, const char* suffix, int mode);
|
2014-10-18 23:25:48 +00:00
|
|
|
struct VFile* VDirOptionalOpenIncrementFile(struct VDir* dir, const char* realPath, const char* prefix, const char* infix, const char* suffix, int mode);
|
2014-10-10 06:55:02 +00:00
|
|
|
|
2015-03-06 02:40:33 +00:00
|
|
|
ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size);
|
|
|
|
|
2014-07-16 08:31:10 +00:00
|
|
|
#endif
|