From fdaf0e7eb6b9d9bdd7d5ab5f814f4ebbf791ff67 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 16 May 2018 15:02:43 +0800 Subject: v0.1.0 --- src/fs/filesystem.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/fs/filesystem.cpp (limited to 'src/fs/filesystem.cpp') diff --git a/src/fs/filesystem.cpp b/src/fs/filesystem.cpp new file mode 100644 index 0000000..72f1144 --- /dev/null +++ b/src/fs/filesystem.cpp @@ -0,0 +1,68 @@ +#include "filesystem.h" +#include +#include +#include /* defines FILENAME_MAX */ + +namespace jin +{ +namespace fs +{ + + Filesystem* Filesystem::fs = 0; + + Filesystem::Filesystem() + { + S = sm_newshared(); + } + + Filesystem* Filesystem::get() + { + return fs ? fs : (fs = new Filesystem()); + } + + /** + * r is relative path + */ + void Filesystem::mount(const char * path) + { + int err = sm_mount(S, path); + if (err) + { + printf("%s mounted path %s", sm_errstr(err), path); + exit(1); + } + } + + /** + * + */ + int Filesystem::read(const char* path, Buffer* buffer) + { + buffer->data = sm_read(S, path, &buffer->size); + if (buffer->data == 0) + return 0; + return 1; + } + + const char* Filesystem::getFull(const char* path) + { + return sm_fullpath(S, path); + } + + bool Filesystem::isDir(const char* path) + { + return sm_isdir(S, path); + } + + bool Filesystem::isFile(const char* path) + { + return sm_isreg(S, path); + } + + bool Filesystem::exists(const char* path) + { + return sm_exists(S, path) == 0; + } + +} +} \ No newline at end of file -- cgit v1.1-26-g67d0