From f4583fda98b578966969db7d94a0bae3c87b0c80 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 30 Jan 2012 22:48:38 +0000 Subject: Replaced most FILE operations with a cFile object git-svn-id: http://mc-server.googlecode.com/svn/trunk@196 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cWebAdmin.cpp | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'source/cWebAdmin.cpp') diff --git a/source/cWebAdmin.cpp b/source/cWebAdmin.cpp index 23348fcdc..70f89528c 100644 --- a/source/cWebAdmin.cpp +++ b/source/cWebAdmin.cpp @@ -245,6 +245,10 @@ void cWebAdmin::Request_Handler(webserver::http_request* r) } } + + + + bool cWebAdmin::Init( int a_Port ) { m_Port = a_Port; @@ -289,45 +293,44 @@ void *cWebAdmin::ListenThread( void *lpParam ) return 0; } + + + + std::string cWebAdmin::GetTemplate() { std::string retVal = ""; char SourceFile[] = "webadmin/template.html"; - FILE* f; -#ifdef _WIN32 - if( fopen_s(&f, SourceFile, "rb" ) == 0 ) // no error -#else - if( (f = fopen(SourceFile, "rb" ) ) != 0 ) // no error -#endif + cFile f; + if (!f.Open(SourceFile, cFile::fmRead)) { - // obtain file size: - fseek (f , 0 , SEEK_END); - long lSize = ftell (f); - rewind (f); + return ""; + } - // allocate memory to contain the whole file: - char* buffer = (char*) malloc (sizeof(char)*lSize); + // obtain file size: + int lSize = f.GetSize(); - // copy the file into the buffer: - size_t result = fread (buffer, 1, lSize, f); - if ((long)result != lSize) - { - LOG ("WEBADMIN: Could not read file %s", SourceFile); - free( buffer ); - return ""; - } + // allocate memory to contain the whole file: + std::auto_ptr buffer(new char[lSize]); // auto_ptr deletes the memory in its destructor - retVal.assign( buffer, lSize ); - - free( buffer ); - fclose(f); + // copy the file into the buffer: + if (f.Read(buffer.get(), lSize) != lSize) + { + LOG ("WEBADMIN: Could not read file \"%s\"", SourceFile); + return ""; } + + retVal.assign(buffer.get(), lSize ); + return retVal; } + + + void cWebAdmin::RemovePlugin( lua_State* L ) { for( PluginList::iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); ) -- cgit v1.2.3