Update the C++ code.

This commit is contained in:
Jonathan Naylor
2025-03-15 17:03:06 +00:00
parent 29397cf65e
commit ec5c32b57a
63 changed files with 848 additions and 849 deletions

22
Log.cpp
View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX
* Copyright (C) 2015,2016,2020,2025 by Jonathan Naylor G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -37,7 +37,7 @@ static std::string m_filePath;
static std::string m_fileRoot;
static bool m_fileRotate = true;
static FILE* m_fpLog = NULL;
static FILE* m_fpLog = nullptr;
static bool m_daemon = false;
static unsigned int m_displayLevel = 2U;
@@ -59,10 +59,10 @@ static bool logOpenRotate()
struct tm* tm = ::gmtime(&now);
if (tm->tm_mday == m_tm.tm_mday && tm->tm_mon == m_tm.tm_mon && tm->tm_year == m_tm.tm_year) {
if (m_fpLog != NULL)
if (m_fpLog != nullptr)
return true;
} else {
if (m_fpLog != NULL)
if (m_fpLog != nullptr)
::fclose(m_fpLog);
}
@@ -73,7 +73,7 @@ static bool logOpenRotate()
::sprintf(filename, "%s/%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
#endif
if ((m_fpLog = ::fopen(filename, "a+t")) != NULL) {
if ((m_fpLog = ::fopen(filename, "a+t")) != nullptr) {
status = true;
#if !defined(_WIN32) && !defined(_WIN64)
@@ -94,7 +94,7 @@ static bool logOpenNoRotate()
if (m_fileLevel == 0U)
return true;
if (m_fpLog != NULL)
if (m_fpLog != nullptr)
return true;
char filename[200U];
@@ -104,7 +104,7 @@ static bool logOpenNoRotate()
::sprintf(filename, "%s/%s.log", m_filePath.c_str(), m_fileRoot.c_str());
#endif
if ((m_fpLog = ::fopen(filename, "a+t")) != NULL) {
if ((m_fpLog = ::fopen(filename, "a+t")) != nullptr) {
status = true;
#if !defined(_WIN32) && !defined(_WIN64)
@@ -141,13 +141,13 @@ bool LogInitialise(bool daemon, const std::string& filePath, const std::string&
void LogFinalise()
{
if (m_fpLog != NULL)
if (m_fpLog != nullptr)
::fclose(m_fpLog);
}
void Log(unsigned int level, const char* fmt, ...)
{
assert(fmt != NULL);
assert(fmt != nullptr);
char buffer[501U];
#if defined(_WIN32) || defined(_WIN64)
@@ -157,7 +157,7 @@ void Log(unsigned int level, const char* fmt, ...)
::sprintf(buffer, "%c: %04u-%02u-%02u %02u:%02u:%02u.%03u ", LEVELS[level], st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
#else
struct timeval now;
::gettimeofday(&now, NULL);
::gettimeofday(&now, nullptr);
struct tm* tm = ::gmtime(&now.tv_sec);
@@ -167,7 +167,7 @@ void Log(unsigned int level, const char* fmt, ...)
va_list vl;
va_start(vl, fmt);
::vsnprintf(buffer + ::strlen(buffer), 500, fmt, vl);
::vsnprintf(buffer + ::strlen(buffer), 500 - ::strlen(buffer), fmt, vl);
va_end(vl);