From 1a882936e91826e4d69584745e16a79650272015 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 26 Jul 2018 23:58:12 +0800 Subject: *change name --- src/libjin/Filesystem/Filesystem.cpp | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/libjin/Filesystem/Filesystem.cpp (limited to 'src/libjin/Filesystem/Filesystem.cpp') diff --git a/src/libjin/Filesystem/Filesystem.cpp b/src/libjin/Filesystem/Filesystem.cpp new file mode 100644 index 0000000..af94034 --- /dev/null +++ b/src/libjin/Filesystem/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 = smtnewshared(); + } + + Filesystem* Filesystem::get() + { + return fs ? fs : (fs = new Filesystem()); + } + + /** + * r is relative path + */ + void Filesystem::mount(const char * path) + { + int err = smtmount(S, path); + if (err) + { + printf("%s mounted path %s", smterrstr(err), path); + exit(1); + } + } + + /** + * + */ + int Filesystem::read(const char* path, Buffer* buffer) + { + buffer->data = smtread(S, path, &buffer->size); + if (buffer->data == 0) + return 0; + return 1; + } + + const char* Filesystem::getFull(const char* path) + { + return smtfullpath(S, path); + } + + bool Filesystem::isDir(const char* path) + { + return smtisdir(S, path); + } + + bool Filesystem::isFile(const char* path) + { + return smtisreg(S, path); + } + + bool Filesystem::exists(const char* path) + { + return smtexists(S, path) == 0; + } + +} +} \ No newline at end of file -- cgit v1.1-26-g67d0