#include "Vfs.h"
-
-void dmlite::ThrowExceptionFromErrno(int err, const char* extra) throw(DmException)
-{
- if (extra == 0) extra = "";
- throw DmException(err, "%s: %s", strerror(err), extra);
+void dmlite::vfsThrowHelper(const std::string& func, int code, const std::string& msg) throw (DmException) {
+ throw DmException(code, "VfsCatalog::" + func + "(): " + msg);
}
-int dmlite::wrapCall(int r) throw (DmException)
-{
- if (r < 0)
- ThrowExceptionFromErrno(errno);
+int dmlite::vfsWrapCallHelper(const std::string &func, int r, const std::string& msg) throw (DmException) {
+ if (r < 0) {
+ if (msg.length() != 0)
+ vfsThrowHelper(func, errno, msg + ": " + strerror(errno));
+ else
+ vfsThrowHelper(func, errno, strerror(errno));
+ }
return r;
}
-void* dmlite::wrapCall(void* p) throw (DmException)
-{
- if (p == NULL && errno != 0)
- ThrowExceptionFromErrno(errno);
+void *dmlite::vfsWrapCallHelper(const std::string &func, void *p, const std::string& msg) throw (DmException) {
+ if (!p) {
+ if (msg.length() != 0)
+ vfsThrowHelper(func, errno, msg + ": " + strerror(errno));
+ else
+ vfsThrowHelper(func, errno, strerror(errno));
+ }
return p;
}
#include <dmlite/cpp/io.h>
#include <dmlite/cpp/poolmanager.h>
+#define vfsThrowErrno(MSG) dmlite::vfsThrowHelper(__func__, DMLITE_SYSERR(errno), (MSG))
+#define vfsThrow(CODE, MSG) dmlite::vfsThrowHelper(__func__, (CODE), (MSG))
+
+#ifdef __GNUC__
+ #define wrapCall(RETVAL, MSG...) dmlite::vfsWrapCallHelper(__func__, (RETVAL) , ##MSG)
+#else
+ #define wrapCall(RETVAL, ...) dmlite::vfsWrapCallHelper(__func__, (RETVAL) , ##__VA_ARGS__)
+#endif
+
namespace dmlite {
/// Concrete factory for DPM wrapper
unsigned tokenLife_;
};
- void ThrowExceptionFromErrno(int err, const char* extra = 0x00) throw(DmException);
- int wrapCall(int ret) throw (DmException);
- void* wrapCall(void* ret) throw (DmException);
+ void vfsThrowHelper(const std::string& func, int code, const std::string& msg = "") throw (DmException);
+ int vfsWrapCallHelper(const std::string &func, int r, const std::string& msg = "") throw (DmException);
+ void *vfsWrapCallHelper(const std::string &func, void *p, const std::string& msg = "") throw (DmException);
};
privateDir->dir = opendir(path.c_str());
if (privateDir->dir == NULL) {
delete privateDir;
- ThrowExceptionFromErrno(errno);
+ vfsThrowErrno("error opening directory '" + path + "'");
return NULL;
}