diff options
author | Pixel <pixel@nobis-crew.org> | 2011-10-25 17:11:08 -0700 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2011-10-25 17:11:21 -0700 |
commit | 8b1e278ef364fff2aa7d6b805353a722db1b4b89 (patch) | |
tree | f317199fd11e3c396fae4aa7e786b1c6bb7da339 | |
parent | 246feab29cf4696048628f0ad7d3d48cafe23f3b (diff) |
Adding the FileSystem global class with mkdir, and adding the writeString method to Handles. Also preparing the inclusion of Lua by adding LuaJIT.
-rw-r--r-- | .gitmodules | 3 | ||||
m--------- | LuaJIT | 0 | ||||
-rw-r--r-- | includes/Handle.h | 7 | ||||
-rw-r--r-- | src/Handle.cc | 37 |
4 files changed, 47 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules index 727224b..e78fd64 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "win32/pthreads-win32"] path = win32/pthreads-win32 url = git.grumpycoder.net:/pub/repo.git/pthreads-win32 +[submodule "LuaJIT"] + path = LuaJIT + url = http://luajit.org/git/luajit-2.0.git diff --git a/LuaJIT b/LuaJIT new file mode 160000 +Subproject e80478c44b7e4bf32a509c480edb39bd39ede51 diff --git a/includes/Handle.h b/includes/Handle.h index 2f2a029..96f1736 100644 --- a/includes/Handle.h +++ b/includes/Handle.h @@ -5,6 +5,11 @@ namespace Balau { +class FileSystem { + public: + static int mkdir(const char * path) throw (GeneralException); +}; + class ENoEnt : public GeneralException { public: ENoEnt(const char * name) : GeneralException(String("No such file or directory: `") + name + "'") { } @@ -27,6 +32,8 @@ class Handle { virtual const char * getName() = 0; virtual ssize_t read(void * buf, size_t count) throw (GeneralException); virtual ssize_t write(const void * buf, size_t count) throw (GeneralException); + void writeString(const char * str, size_t len = -1) { if (len < 0) len = strlen(str); write(str, len); } + void writeString(const String & str) { write(str.to_charp(), str.strlen()); } virtual void rseek(off_t offset, int whence = SEEK_SET) throw (GeneralException); virtual void wseek(off_t offset, int whence = SEEK_SET) throw (GeneralException); virtual off_t rtell() throw (GeneralException); diff --git a/src/Handle.cc b/src/Handle.cc index b3458a8..0ec39be 100644 --- a/src/Handle.cc +++ b/src/Handle.cc @@ -6,6 +6,17 @@ #include "Handle.h" #include "Printer.h" +#ifdef _WIN32 +static const char * strerror_r(int errorno, char * buf, size_t bufsize) { +#ifdef _MSVC + strerror_s(buf, bufsize, errorno); + return buf; +#else + return strerror(errorno); +#endif +} +#endif + class eioInterface : public Balau::AtStart { public: eioInterface() : AtStart(100) { } @@ -159,3 +170,29 @@ off_t Balau::SeekableHandle::wtell() throw (GeneralException) { bool Balau::SeekableHandle::isEOF() { return m_rOffset == getSize(); } + +struct cbResults_t { + Balau::Events::Custom evt; + int result, errorno; +}; + +static int eioDone(eio_req * req) { + cbResults_t * cbResults = (cbResults_t *) req->data; + cbResults->result = req->result; + cbResults->errorno = req->errorno; + cbResults->evt.doSignal(); + return 0; +} + +int Balau::FileSystem::mkdir(const char * path) throw (GeneralException) { + cbResults_t cbResults; + eio_req * r = eio_mkdir(path, 0755, 0, eioDone, &cbResults); + Assert(r != 0); + Task::yield(&cbResults.evt); + + char str[4096]; + if (cbResults.result < 0) + throw GeneralException(String("Unable to create directory ") + path + ": " + strerror_r(cbResults.errorno, str, sizeof(str)) + " (err#" + cbResults.errorno + ")"); + + return cbResults.result; +} |