diff options
author | chai <chaifix@163.com> | 2018-05-17 19:12:18 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2018-05-17 19:12:18 +0800 |
commit | 9edf2ba9fe8524976d2f298767fff0149e8c0d41 (patch) | |
tree | 38d74676a57de508a40ac581286255c2a18dce12 /src/libjin/fs/filesystem.cpp | |
parent | 70cdd89e887641b7423e5d4d05928d14ee014aba (diff) |
change file tree
Diffstat (limited to 'src/libjin/fs/filesystem.cpp')
-rw-r--r-- | src/libjin/fs/filesystem.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/libjin/fs/filesystem.cpp b/src/libjin/fs/filesystem.cpp new file mode 100644 index 0000000..72f1144 --- /dev/null +++ b/src/libjin/fs/filesystem.cpp @@ -0,0 +1,68 @@ +#include "filesystem.h" +#include <string.h> +#include <stdlib.h> +#include <stdio.h> /* 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 |