From 8b1e278ef364fff2aa7d6b805353a722db1b4b89 Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 25 Oct 2011 17:11:08 -0700 Subject: Adding the FileSystem global class with mkdir, and adding the writeString method to Handles. Also preparing the inclusion of Lua by adding LuaJIT. --- src/Handle.cc | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/Handle.cc') 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; +} -- cgit v1.2.3