summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-01 14:43:47 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-01 14:43:47 +0100
commit2568bad3cc1ae70350f5ad31e97b4c13194e437e (patch)
tree31d0713dfe1b4e42c1f17ddae8ea0114c420fc61 /source
parentRemoved a few duplicate includes (diff)
downloadcuberite-2568bad3cc1ae70350f5ad31e97b4c13194e437e.tar
cuberite-2568bad3cc1ae70350f5ad31e97b4c13194e437e.tar.gz
cuberite-2568bad3cc1ae70350f5ad31e97b4c13194e437e.tar.bz2
cuberite-2568bad3cc1ae70350f5ad31e97b4c13194e437e.tar.lz
cuberite-2568bad3cc1ae70350f5ad31e97b4c13194e437e.tar.xz
cuberite-2568bad3cc1ae70350f5ad31e97b4c13194e437e.tar.zst
cuberite-2568bad3cc1ae70350f5ad31e97b4c13194e437e.zip
Diffstat (limited to '')
-rw-r--r--source/Globals.h11
-rw-r--r--source/cChunk.cpp6
-rw-r--r--source/cChunkLoader.cpp14
-rw-r--r--source/cChunkMap.cpp11
-rw-r--r--source/cClientHandle.cpp20
-rw-r--r--source/cEvent.cpp6
-rw-r--r--source/cFile.cpp6
-rw-r--r--source/cFile.h4
-rw-r--r--source/cHeartBeat.cpp36
-rw-r--r--source/cIsThread.cpp4
-rw-r--r--source/cLog.cpp95
-rw-r--r--source/cLog.h22
-rw-r--r--source/cMCLogger.cpp14
-rw-r--r--source/cPlayer.cpp16
-rw-r--r--source/cSemaphore.cpp46
-rw-r--r--source/cWebAdmin.cpp12
16 files changed, 189 insertions, 134 deletions
diff --git a/source/Globals.h b/source/Globals.h
index 1ca16fec1..8d42d6341 100644
--- a/source/Globals.h
+++ b/source/Globals.h
@@ -80,11 +80,12 @@
/// Evaluates to the number of elements in an array (compile-time!)
#define ARRAYCOUNT(X) (sizeof(X) / sizeof(*(X)))
-// sprintf_s is the preferred call in MSVC ("secure"); make it *nix-compatible:
-#ifndef _WIN32
- #define sprintf_s(dst, size, format, ...) sprintf(dst, format, __VA_ARGS__ )
- #define vsnprintf_s(buffer, buffer_size, maxcount, stringbuffer, ...) (vsnprintf(buffer, maxcount, stringbuffer, __VA_ARGS__))
-#endif // _WIN32
+#ifdef _MSC_VER
+ #define OBSOLETE __declspec(deprecated)
+#else
+ // TODO: how do other compilers mark functions as obsolete, so that their usage results in a compile-time warning?
+ #define OBSOLETE
+#endif
diff --git a/source/cChunk.cpp b/source/cChunk.cpp
index 992a4e71a..83f7a0ffc 100644
--- a/source/cChunk.cpp
+++ b/source/cChunk.cpp
@@ -899,8 +899,8 @@ cBlockEntity* cChunk::GetBlockEntity( int a_X, int a_Y, int a_Z )
/// Loads the chunk from the old-format disk file, erases the file afterwards. Returns true if successful
bool cChunk::LoadFromDisk()
{
- char SourceFile[128];
- sprintf_s(SourceFile, ARRAYCOUNT(SourceFile), "world/X%i_Y%i_Z%i.bin", m_PosX, m_PosY, m_PosZ );
+ AString SourceFile;
+ Printf(SourceFile, "world/X%i_Y%i_Z%i.bin", m_PosX, m_PosY, m_PosZ );
cFile f;
if (!f.Open(SourceFile, cFile::fmRead))
@@ -974,7 +974,7 @@ bool cChunk::LoadFromDisk()
f.Close();
// Delete old format file
- if (std::remove(SourceFile) != 0)
+ if (std::remove(SourceFile.c_str()) != 0)
{
LOGERROR("Could not delete file %s", SourceFile );
}
diff --git a/source/cChunkLoader.cpp b/source/cChunkLoader.cpp
index 94ce6153d..41d61cfaf 100644
--- a/source/cChunkLoader.cpp
+++ b/source/cChunkLoader.cpp
@@ -105,8 +105,8 @@ bool cChunkLoader::SaveChunk( const cChunk & a_Chunk )
cChunk* cChunkLoader::LoadOldFormat( int a_X, int a_Y, int a_Z )
{
- char SourceFile[128];
- sprintf_s(SourceFile, 128, "world/X%i_Y%i_Z%i.bin", a_X, a_Y, a_Z );
+ AString SourceFile;
+ Printf(SourceFile, "world/X%i_Y%i_Z%i.bin", a_X, a_Y, a_Z );
FILE* f = 0;
#ifdef _WIN32
@@ -181,10 +181,10 @@ cChunk* cChunkLoader::LoadOldFormat( int a_X, int a_Y, int a_Z )
bool cChunkLoader::SaveOldFormat( const cChunk & a_Chunk )
{
- char SourceFile[128];
- sprintf_s(SourceFile, 128, "world/X%i_Y%i_Z%i.bin", a_Chunk.m_PosX, a_Chunk.m_PosY, a_Chunk.m_PosZ );
+ AString SourceFile;
+ Printf(SourceFile, "world/X%i_Y%i_Z%i.bin", a_Chunk.m_PosX, a_Chunk.m_PosY, a_Chunk.m_PosZ );
- #ifdef _WIN32
+ #ifdef _WIN32
{
SECURITY_ATTRIBUTES Attrib;
Attrib.nLength = sizeof(SECURITY_ATTRIBUTES);
@@ -310,8 +310,8 @@ cChunk* cChunkLoader::LoadFormat1( int a_X, int a_Y, int a_Z )
cChunkLoader::ChunkPack* cChunkLoader::LoadPak1( int PakX, int PakY, int PakZ )
{
- char SourceFile[128];
- sprintf_s(SourceFile, 128, "world/X%i_Y%i_Z%i.pak", PakX, PakY, PakZ );
+ AString SourceFile;
+ Printf(SourceFile, "world/X%i_Y%i_Z%i.pak", PakX, PakY, PakZ );
FILE* f = 0;
#ifdef _WIN32
diff --git a/source/cChunkMap.cpp b/source/cChunkMap.cpp
index 8e2257858..92a9b67eb 100644
--- a/source/cChunkMap.cpp
+++ b/source/cChunkMap.cpp
@@ -455,9 +455,8 @@ void cChunkMap::SaveLayer( cChunkLayer* a_Layer )
std::string WorldName = m_World->GetName();
cMakeDir::MakeDir( WorldName.c_str() );
- char SourceFile[128];
-
- sprintf_s(SourceFile, ARRAYCOUNT(SourceFile), ( WorldName + "/X%i_Z%i.pak").c_str(), a_Layer->m_X, a_Layer->m_Z );
+ AString SourceFile;
+ Printf(SourceFile, "%s/X%i_Z%i.pak", WorldName.c_str(), a_Layer->m_X, a_Layer->m_Z );
cFile f;
if (!f.Open(SourceFile, cFile::fmWrite))
@@ -538,9 +537,9 @@ void cChunkMap::SaveLayer( cChunkLayer* a_Layer )
cChunkMap::cChunkLayer* cChunkMap::LoadLayer(int a_LayerX, int a_LayerZ )
{
std::string WorldName = m_World->GetName();
- char SourceFile[128];
-
- sprintf_s(SourceFile, ARRAYCOUNT(SourceFile), (WorldName + "/X%i_Z%i.pak").c_str(), a_LayerX, a_LayerZ );
+
+ AString SourceFile;
+ Printf(SourceFile, "%s/X%i_Z%i.pak", WorldName.c_str(), a_LayerX, a_LayerZ);
cFile f(SourceFile, cFile::fmRead);
if (!f.IsOpen())
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index 1f7045d2b..53d2a40cf 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -507,11 +507,15 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
case E_PING: // Somebody tries to retrieve information about the server
{
LOGINFO("Got ping");
- char NumPlayers[8], cMaxPlayers[8];
- sprintf_s(NumPlayers, 8, "%i", cRoot::Get()->GetWorld()->GetNumPlayers());
- sprintf_s(cMaxPlayers, 8, "%i", cRoot::Get()->GetWorld()->GetMaxPlayers());
- std::string response = std::string(cRoot::Get()->GetWorld()->GetDescription() + cChatColor::Delimiter + NumPlayers + cChatColor::Delimiter + cMaxPlayers );
- Kick( response.c_str() );
+ AString Reply;
+ Printf(Reply, "%s%s%i%s%i",
+ cRoot::Get()->GetWorld()->GetDescription().c_str(),
+ cChatColor::Delimiter.c_str(),
+ cRoot::Get()->GetWorld()->GetNumPlayers(),
+ cChatColor::Delimiter.c_str(),
+ cRoot::Get()->GetWorld()->GetMaxPlayers()
+ );
+ Kick(Reply.c_str());
}
break;
case E_HANDSHAKE:
@@ -1659,9 +1663,9 @@ void cClientHandle::ReceiveThread( void *lpParam )
LOG("Unknown packet: 0x%02x \'%c\' %i", (unsigned char)temp, (unsigned char)temp, (unsigned char)temp );
- char c_Str[128];
- sprintf_s( c_Str, 128, "[C->S] Unknown PacketID: 0x%02x", (unsigned char)temp );
- cPacket_Disconnect DC(c_Str);
+ AString Reason;
+ Printf(Reason, "[C->S] Unknown PacketID: 0x%02x", (unsigned char)temp );
+ cPacket_Disconnect DC(Reason);
DC.Send( socket );
cSleep::MilliSleep( 1000 ); // Give packet some time to be received
diff --git a/source/cEvent.cpp b/source/cEvent.cpp
index 4ed8f65f5..9b3ddcfdf 100644
--- a/source/cEvent.cpp
+++ b/source/cEvent.cpp
@@ -34,9 +34,9 @@ cEvent::cEvent(void)
delete m_Event;
m_bIsNamed = true;
- char c_Str[64];
- sprintf(c_Str, "cEvent%p", this);
- m_Event = sem_open( c_Str, O_CREAT, 777, 0 );
+ AString EventName;
+ Printf(EventName, "cEvent%p", this);
+ m_Event = sem_open(EventName.c_str(), O_CREAT, 777, 0 );
if (m_Event == SEM_FAILED)
{
LOGERROR("cEvent: Cannot create event, errno = %i. Aborting server.", errno);
diff --git a/source/cFile.cpp b/source/cFile.cpp
index b2332cbaf..2026f1fe2 100644
--- a/source/cFile.cpp
+++ b/source/cFile.cpp
@@ -28,7 +28,7 @@ cFile::cFile(void) :
/// Constructs and opens / creates the file specified, use IsOpen() to check for success
-cFile::cFile(const char * iFileName, EMode iMode) :
+cFile::cFile(const AString & iFileName, EMode iMode) :
#ifdef USE_STDIO_FILE
m_File(NULL)
#else
@@ -55,7 +55,7 @@ cFile::~cFile()
-bool cFile::Open(const char * iFileName, EMode iMode)
+bool cFile::Open(const AString & iFileName, EMode iMode)
{
assert(!IsOpen()); // You should close the file before opening another one
@@ -76,7 +76,7 @@ bool cFile::Open(const char * iFileName, EMode iMode)
return false;
}
}
- m_File = fopen(iFileName, Mode);
+ m_File = fopen(iFileName.c_str(), Mode);
return (m_File != NULL);
}
diff --git a/source/cFile.h b/source/cFile.h
index 9f14c93f6..674ce93a2 100644
--- a/source/cFile.h
+++ b/source/cFile.h
@@ -58,12 +58,12 @@ public:
cFile(void);
/// Constructs and opens / creates the file specified, use IsOpen() to check for success
- cFile(const char * iFileName, EMode iMode);
+ cFile(const AString & iFileName, EMode iMode);
/// Auto-closes the file, if open
~cFile();
- bool Open(const char * iFileName, EMode iMode);
+ bool Open(const AString & iFileName, EMode iMode);
void Close(void);
bool IsOpen(void) const;
bool IsEOF(void) const;
diff --git a/source/cHeartBeat.cpp b/source/cHeartBeat.cpp
index c1aa327c5..fd1cdc805 100644
--- a/source/cHeartBeat.cpp
+++ b/source/cHeartBeat.cpp
@@ -19,10 +19,18 @@ cHeartBeat::cHeartBeat()
Authenticate();
}
+
+
+
+
cHeartBeat::~cHeartBeat()
{
}
+
+
+
+
void cHeartBeat::ReceivedData( char a_Data[256], int a_Size )
{
if( a_Size < 0 ) // Disconnected
@@ -97,28 +105,40 @@ void cHeartBeat::ReceivedData( char a_Data[256], int a_Size )
} while( bLoop );
}
+
+
+
+
void cHeartBeat::SendUpdate()
{
CloseSocket();
if( Connect( "mc-server.org", 80 ) )
{
int Port = cRoot::Get()->GetServer()->GetPort();
- char c_Port[16];
- sprintf_s( c_Port, 16, "%i", Port );
-
- std::string sPort = std::string( c_Port );
- std::string sChecksum = md5( m_ServerID + sPort );
- SendMessage( (std::string("GET http://master.mc-server.org/?update=") + m_ServerID + std::string("&checksum=") + sChecksum + std::string("&port=") + sPort + "\n").c_str() );
+ AString Msg;
+ AString sPort;
+ Printf(sPort, "%i", Port);
+ AString sChecksum = md5( m_ServerID + sPort );
+ Printf(Msg, "GET http://master.mc-server.org/?update=%s&checksum=%s&port=%d\n", m_ServerID, sChecksum , Port);
+ SendMessage(Msg.c_str());
}
}
+
+
+
+
void cHeartBeat::Authenticate()
{
CloseSocket();
- if( Connect( "mc-server.org", 80 ) )
+ if (Connect( "mc-server.org", 80))
{
m_State = 1;
int RetVal = SendMessage( "GET http://master.mc-server.org/\r\n\r\n");
- LOGINFO("Returned %i", RetVal );
+ LOGINFO("Returned %i", RetVal);
}
}
+
+
+
+
diff --git a/source/cIsThread.cpp b/source/cIsThread.cpp
index cee4d4477..4aa25b534 100644
--- a/source/cIsThread.cpp
+++ b/source/cIsThread.cpp
@@ -13,7 +13,7 @@
// When in MSVC, the debugger provides "thread naming" by catching special exceptions. Interface here:
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && defined(_DEBUG)
//
// Usage: SetThreadName (-1, "MainThread");
//
@@ -41,7 +41,7 @@ static void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName)
{
}
}
-#endif // _MSC_VER
+#endif // _MSC_VER && _DEBUG
diff --git a/source/cLog.cpp b/source/cLog.cpp
index 8f24b24ad..b83d3cc37 100644
--- a/source/cLog.cpp
+++ b/source/cLog.cpp
@@ -6,6 +6,7 @@
#include <fstream>
#include <ctime>
#include <stdarg.h>
+#include "cMakeDir.h"
@@ -13,35 +14,31 @@
cLog* cLog::s_Log = NULL;
-cLog::cLog( const char* a_FileName )
+cLog::cLog(const AString & a_FileName )
: m_File(NULL)
{
s_Log = this;
// create logs directory
-#ifdef _WIN32
- {
- SECURITY_ATTRIBUTES Attrib;
- Attrib.nLength = sizeof(SECURITY_ATTRIBUTES);
- Attrib.lpSecurityDescriptor = NULL;
- Attrib.bInheritHandle = false;
- ::CreateDirectory("logs", &Attrib);
- }
-#else
- {
- mkdir("logs", S_IRWXU | S_IRWXG | S_IRWXO);
- }
-#endif
+ cMakeDir::MakeDir("logs");
- OpenLog( (std::string("logs/") + std::string(a_FileName)).c_str() );
+ OpenLog( (std::string("logs/") + a_FileName).c_str() );
}
+
+
+
+
cLog::~cLog()
{
CloseLog();
s_Log = NULL;
}
+
+
+
+
cLog* cLog::GetInstance()
{
if(s_Log)
@@ -51,6 +48,10 @@ cLog* cLog::GetInstance()
return s_Log;
}
+
+
+
+
void cLog::CloseLog()
{
if( m_File )
@@ -58,6 +59,10 @@ void cLog::CloseLog()
m_File = 0;
}
+
+
+
+
void cLog::OpenLog( const char* a_FileName )
{
if(m_File) fclose (m_File);
@@ -68,9 +73,13 @@ void cLog::OpenLog( const char* a_FileName )
#endif
}
+
+
+
+
void cLog::ClearLog()
{
- #ifdef _WIN32
+ #ifdef _WIN32
if( fopen_s( &m_File, "log.txt", "w" ) == 0)
fclose (m_File);
#else
@@ -81,43 +90,43 @@ void cLog::ClearLog()
m_File = 0;
}
-void cLog::Log(const char* a_Format, va_list argList )
-{
- char c_Buffer[1024];
- if( argList != 0 )
- {
- vsnprintf_s(c_Buffer, 1024, 1024, a_Format, argList );
- }
- else
- {
- sprintf_s( c_Buffer, 1024, "%s", a_Format );
- }
+
+
+
+void cLog::Log(const char* a_Format, va_list argList)
+{
+ AString Message;
+ AppendVPrintf(Message, a_Format, argList);
time_t rawtime;
time ( &rawtime );
-#ifdef _WIN32
- struct tm timeinfo;
- localtime_s( &timeinfo, &rawtime );
-#else
+
struct tm* timeinfo;
- timeinfo = localtime( &rawtime );
-#endif
- char c_Buffer2[1024];
#ifdef _WIN32
- sprintf_s(c_Buffer2, 1024, "[%02d:%02d:%02d] %s\n", timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, c_Buffer);
+ struct tm timeinforeal;
+ timeinfo = &timeinforeal;
+ localtime_s(timeinfo, &rawtime );
#else
- sprintf(c_Buffer2, "[%02d:%02d:%02d] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, c_Buffer);
+ timeinfo = localtime( &rawtime );
#endif
- if(m_File){
- fputs(c_Buffer2, m_File);
+
+ AString Line;
+ Printf(Line, "[%02d:%02d:%02d] %s\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, Message.c_str());
+ if (m_File)
+ {
+ fputs(Line.c_str(), m_File);
fflush(m_File);
}
- printf("%s", c_Buffer2 );
+ printf("%s", Line.c_str());
}
+
+
+
+
void cLog::Log(const char* a_Format, ...)
{
va_list argList;
@@ -126,7 +135,15 @@ void cLog::Log(const char* a_Format, ...)
va_end(argList);
}
+
+
+
+
void cLog::SimpleLog(const char* a_String)
{
Log("%s", a_String );
}
+
+
+
+
diff --git a/source/cLog.h b/source/cLog.h
index b2292ba7b..b218580ce 100644
--- a/source/cLog.h
+++ b/source/cLog.h
@@ -4,19 +4,21 @@
#include "FileDefine.h"
#ifndef _WIN32
-#include <stdarg.h>
+ #include <stdarg.h>
#endif
-class cLog { // tolua_export
+
+
+
+
+class cLog
+{ // tolua_export
private:
- FILE* m_File;
- static cLog* s_Log;
+ FILE * m_File;
+ static cLog * s_Log;
-#ifdef _WIN32
- typedef char* va_list;
-#endif
public:
- cLog( const char* a_FileName );
+ cLog(const AString & a_FileName);
~cLog();
void Log(const char* a_Format, va_list argList );
void Log(const char* a_Format, ...);
@@ -28,3 +30,7 @@ public:
static cLog* GetInstance();
};
//tolua_end
+
+
+
+
diff --git a/source/cMCLogger.cpp b/source/cMCLogger.cpp
index a084c62bf..b3f43333f 100644
--- a/source/cMCLogger.cpp
+++ b/source/cMCLogger.cpp
@@ -16,17 +16,25 @@ cMCLogger* cMCLogger::GetInstance()
return s_MCLogger;
}
+
+
+
+
cMCLogger::cMCLogger()
{
m_CriticalSection = new cCriticalSection();
- char c_Buffer[128];
- sprintf_s(c_Buffer, 128, "LOG_%d.txt", (int)time(0) );
- m_Log = new cLog(c_Buffer);
+ AString FileName;
+ Printf(FileName, "LOG_%d.txt", (int)time(0) );
+ m_Log = new cLog(FileName);
m_Log->Log("--- Started Log ---");
s_MCLogger = this;
}
+
+
+
+
cMCLogger::cMCLogger( char* a_File )
{
m_CriticalSection = new cCriticalSection();
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp
index 0dd5695a4..f10dc3586 100644
--- a/source/cPlayer.cpp
+++ b/source/cPlayer.cpp
@@ -784,8 +784,8 @@ bool cPlayer::LoadFromDisk()
if( itr->second ) LOGINFO("%s", itr->first.c_str() );
}
- char SourceFile[128];
- sprintf_s(SourceFile, 128, "players/%s.json", m_pState->PlayerName.c_str() );
+ AString SourceFile;
+ Printf(SourceFile, "players/%s.json", m_pState->PlayerName.c_str() );
cFile f;
if (!f.Open(SourceFile, cFile::fmRead))
@@ -796,8 +796,8 @@ bool cPlayer::LoadFromDisk()
// Get file size
long FileSize = f.GetSize();
- char * buffer = new char[FileSize];
- if (f.Read(buffer, FileSize) != FileSize )
+ std::auto_ptr<char> buffer(new char[FileSize]);
+ if (f.Read(buffer.get(), FileSize) != FileSize)
{
LOGERROR("ERROR READING FROM FILE \"%s\"", SourceFile);
return false;
@@ -806,12 +806,12 @@ bool cPlayer::LoadFromDisk()
Json::Value root;
Json::Reader reader;
- if( !reader.parse( buffer, root, false ) )
+ if (!reader.parse(buffer.get(), root, false))
{
LOGERROR("ERROR WHILE PARSING JSON FROM FILE %s", SourceFile);
}
- delete [] buffer;
+ buffer.reset();
Json::Value & JSON_PlayerPosition = root["position"];
if( JSON_PlayerPosition.size() == 3 )
@@ -876,8 +876,8 @@ bool cPlayer::SaveToDisk()
Json::StyledWriter writer;
std::string JsonData = writer.write( root );
- char SourceFile[128];
- sprintf_s(SourceFile, 128, "players/%s.json", m_pState->PlayerName.c_str() );
+ AString SourceFile;
+ Printf(SourceFile, "players/%s.json", m_pState->PlayerName.c_str() );
cFile f;
if (!f.Open(SourceFile, cFile::fmWrite))
diff --git a/source/cSemaphore.cpp b/source/cSemaphore.cpp
index 3bc83f393..438b83e2c 100644
--- a/source/cSemaphore.cpp
+++ b/source/cSemaphore.cpp
@@ -7,33 +7,33 @@
cSemaphore::cSemaphore( unsigned int a_MaxCount, unsigned int a_InitialCount /* = 0 */ )
#ifndef _WIN32
- : m_bNamed( false )
+ : m_bNamed( false )
#endif
{
#ifndef _WIN32
- (void)a_MaxCount;
- m_Handle = new sem_t;
- if( sem_init( (sem_t*)m_Handle, 0, 0 ) )
- {
- LOG("WARNING cSemaphore: Could not create unnamed semaphore, fallback to named.");
- delete (sem_t*)m_Handle; // named semaphores return their own address
- m_bNamed = true;
+ (void)a_MaxCount;
+ m_Handle = new sem_t;
+ if (sem_init( (sem_t*)m_Handle, 0, 0))
+ {
+ LOG("WARNING cSemaphore: Could not create unnamed semaphore, fallback to named.");
+ delete (sem_t*)m_Handle; // named semaphores return their own address
+ m_bNamed = true;
- char c_Str[32];
- sprintf( c_Str, "cSemaphore%p", this );
- m_Handle = sem_open( c_Str, O_CREAT, 777, a_InitialCount );
- if( m_Handle == SEM_FAILED )
- {
- LOG("ERROR: Could not create Semaphore. (%i)", errno );
- }
- else
- {
- if( sem_unlink( c_Str ) != 0 )
- {
- LOG("ERROR: Could not unlink cSemaphore. (%i)", errno);
- }
- }
- }
+ AString Name;
+ Printf(Name, "cSemaphore%p", this );
+ m_Handle = sem_open(Name.c_str(), O_CREAT, 777, a_InitialCount);
+ if( m_Handle == SEM_FAILED )
+ {
+ LOG("ERROR: Could not create Semaphore. (%i)", errno );
+ }
+ else
+ {
+ if( sem_unlink( c_Str ) != 0 )
+ {
+ LOG("ERROR: Could not unlink cSemaphore. (%i)", errno);
+ }
+ }
+ }
#else
m_Handle = CreateSemaphore(
NULL, // security attribute
diff --git a/source/cWebAdmin.cpp b/source/cWebAdmin.cpp
index ff4ef8a96..9707d3158 100644
--- a/source/cWebAdmin.cpp
+++ b/source/cWebAdmin.cpp
@@ -224,18 +224,18 @@ void cWebAdmin::Request_Handler(webserver::http_request* r)
}
else
{
- char MemUsage[32];
- sprintf( MemUsage, "%0.2f", ((double)resource_usage.ru_maxrss / 1024 / 1024) );
- ReplaceString( Template, std::string("{MEM}"), MemUsage );
+ AString MemUsage;
+ Printf(MemUsage, "%0.2f", ((double)resource_usage.ru_maxrss / 1024 / 1024) );
+ ReplaceString(Template, std::string("{MEM}"), MemUsage);
}
#else
HANDLE hProcess = GetCurrentProcess();
PROCESS_MEMORY_COUNTERS pmc;
if( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc) ) )
{
- char MemUsage[32];
- sprintf( MemUsage, "%0.2f", (pmc.WorkingSetSize / 1024.f / 1024.f) );
- ReplaceString( Template, std::string("{MEM}"), MemUsage );
+ AString MemUsage;
+ Printf(MemUsage, "%0.2f", (pmc.WorkingSetSize / 1024.f / 1024.f) );
+ ReplaceString( Template, "{MEM}", MemUsage );
}
#endif
// end mem usage