diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-07 17:17:06 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-07 17:17:06 +0000 |
commit | 8a21bfcb21094e4ca8440c37dec4a5df3e5bddc7 (patch) | |
tree | 4a9d4c57fb306dd8663efd17d87eb27ec07344ce | |
parent | 6fa35bdb1814ef4eab42d050e283d05910dbf3d2 (diff) |
Tidy up, make a lot of char*'s const
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4769 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/dynamic.h | 15 | ||||
-rw-r--r-- | src/dynamic.cpp | 49 |
2 files changed, 33 insertions, 31 deletions
diff --git a/include/dynamic.h b/include/dynamic.h index ee43d1712..937005e11 100644 --- a/include/dynamic.h +++ b/include/dynamic.h @@ -25,14 +25,14 @@ typedef void * (initfunc) (void); class DLLManager { public: - DLLManager(char *fname); + DLLManager(const char *fname); virtual ~DLLManager(); #ifdef STATIC_LINK - bool GetSymbol( initfunc* &v, char *sym_name ); + bool GetSymbol( initfunc* &v, const char *sym_name ); #else - bool GetSymbol( void **, char *sym_name ); + bool GetSymbol( void **, const char *sym_name ); #endif char* LastError() @@ -52,7 +52,7 @@ class DLLManager class DLLFactoryBase : public DLLManager { public: - DLLFactoryBase(char *fname, char *func_name = 0); + DLLFactoryBase(const char *fname, const char *func_name = 0); virtual ~DLLFactoryBase(); #ifdef STATIC_LINK initfunc *factory_func; @@ -65,7 +65,7 @@ class DLLFactoryBase : public DLLManager template <class T> class DLLFactory : public DLLFactoryBase { public: - DLLFactory(char *fname, char *func_name=0) : DLLFactoryBase(fname,func_name) + DLLFactory(const char *fname, const char *func_name=0) : DLLFactoryBase(fname,func_name) { if (factory_func) factory = (T*)factory_func(); @@ -81,9 +81,4 @@ template <class T> class DLLFactory : public DLLFactoryBase T *factory; }; - - - - - #endif diff --git a/src/dynamic.cpp b/src/dynamic.cpp index 0e207dbd9..833f538ae 100644 --- a/src/dynamic.cpp +++ b/src/dynamic.cpp @@ -35,7 +35,7 @@ using namespace std; extern ServerConfig* Config; -DLLManager::DLLManager(char *fname) +DLLManager::DLLManager(const char *fname) { err = NULL; @@ -67,7 +67,7 @@ DLLManager::DLLManager(char *fname) FILE* x = fopen(fname,"rb"); if (!x) { - err = "Module file not found or cannot access, game over man!"; + err = strerror(errno); return; } char tmpfile_template[255]; @@ -97,12 +97,23 @@ DLLManager::DLLManager(char *fname) // Try to open the library now and get any error message. h = dlopen(tmpfile_template, RTLD_NOW ); - err = (char*)dlerror(); - close(fd); - fclose(x); + + if (!h) + { + err = dlerror(); + return; + } + if (close(fd) == -1) + err = strerror(errno); + if (fclose(x) == EOF) + err = strerror(errno); + // We can delete the tempfile once it's loaded, leaving just the inode. - if (!Config->debugging) - unlink(tmpfile_template); + if (!err && !Config->debugging) + { + if (unlink(tmpfile_template) == -1) + err = strerror(errno); + } #endif } @@ -119,7 +130,7 @@ DLLManager::~DLLManager() #ifdef STATIC_LINK -bool DLLManager::GetSymbol(initfunc* &v, char *sym_name) +bool DLLManager::GetSymbol(initfunc* &v, const char *sym_name) { log(DEBUG,"Symbol search..."); for (int j = 0; modsyms[j].name; j++) @@ -138,19 +149,16 @@ bool DLLManager::GetSymbol(initfunc* &v, char *sym_name) #else -bool DLLManager::GetSymbol(void **v, char *sym_name) +bool DLLManager::GetSymbol(void** v, const char* sym_name) { // try extract a symbol from the library // get any error message is there is any - if(h != 0) + if (h) { - *v = dlsym( h, sym_name ); - err = (char*)dlerror(); - if( err == 0 ) - return true; - else - return false; + *v = dlsym(h, sym_name); + err = dlerror(); + return !err; } else { @@ -160,18 +168,17 @@ bool DLLManager::GetSymbol(void **v, char *sym_name) #endif -DLLFactoryBase::DLLFactoryBase(char *fname, char *factory) : DLLManager(fname) +DLLFactoryBase::DLLFactoryBase(const char* fname, const char* factory) : DLLManager(fname) { // try get the factory function if there is no error yet - factory_func = 0; - if(LastError() == 0) + if (!LastError()) { #ifdef STATIC_LINK - GetSymbol( factory_func, factory ? factory : (char*)"init_module" ); + GetSymbol( factory_func, factory ? factory : "init_module" ); #else - GetSymbol( (void **)&factory_func, factory ? factory : (char*)"init_module" ); + GetSymbol( (void **)&factory_func, factory ? factory : "init_module" ); #endif } } |