diff --git a/CCPLog.cpp b/CCPLog.cpp index 9de4096..127df39 100644 --- a/CCPLog.cpp +++ b/CCPLog.cpp @@ -10,11 +10,15 @@ #include #endif -char s_largeBuffer[65535]{}; +constexpr size_t LOG_ERROR_BUFFER_SIZE = 256; +constexpr size_t LOG_LOCAL_BUFFER_SIZE = 256; +constexpr size_t LOG_LARGE_BUFFER_SIZE = 65535; + +char s_largeBuffer[LOG_LARGE_BUFFER_SIZE]{}; namespace { - char s_lastError[ 256 ] = ""; + char s_lastError[ LOG_ERROR_BUFFER_SIZE ] = ""; struct LogEchoFuncEntry { @@ -213,7 +217,7 @@ CARBON_CORE_API void LogFuncChannel_v( CcpLogChannel_t& logObject, LogType type, va_copy( argCopy2, args ); #endif - char localBuffer[256]; + char localBuffer[LOG_LOCAL_BUFFER_SIZE]; char* output = localBuffer; if ( vsnprintf( localBuffer, std::extent_v, format, args ) > ( std::extent_v - 1 ) ) { @@ -229,7 +233,7 @@ CARBON_CORE_API void LogFuncChannel_v( CcpLogChannel_t& logObject, LogType type, output = s_largeBuffer; vsnprintf( output, std::extent_v, format, argCopy2 ); - assert( s_largeBuffer[65534] == '\0' ); + assert( s_largeBuffer[LOG_LARGE_BUFFER_SIZE - 1] == '\0' ); } LogFuncChannelRaw( logObject, type, userData, output ); diff --git a/CcpFileUtils.cpp b/CcpFileUtils.cpp index ed59d96..415f551 100644 --- a/CcpFileUtils.cpp +++ b/CcpFileUtils.cpp @@ -76,6 +76,16 @@ void CcpCloseFile( int fd ) _close( fd ); } +bool CcpTruncateFile(const std::wstring& filename) { + int fd = CcpCreateFile( filename.c_str(), CCP_SM_RWSHARING ); + if( fd < 0 ) + { + return false; + } + CcpCloseFile( fd ); + return true; +} + ssize_t CcpReadFromFile( int fd, void* buf, size_t numBytes ) { return _read( fd, buf, (unsigned int)numBytes ); @@ -168,6 +178,17 @@ void CcpCloseFile( int fd ) close( fd ); } +bool CcpTruncateFile( const std::wstring& filename ) +{ + int fd = CcpCreateFile( filename.c_str(), CCP_SM_RWSHARING ); + if( fd < 0 ) + { + return false; + } + CcpCloseFile( fd ); + return true; +} + ssize_t CcpReadFromFile( int fd, void* buf, size_t numBytes ) { return read( fd, buf, (unsigned int)numBytes ); diff --git a/CcpTime.cpp b/CcpTime.cpp index b9dd159..5b67fa9 100644 --- a/CcpTime.cpp +++ b/CcpTime.cpp @@ -60,11 +60,13 @@ bool TimeFromDateTime( CcpTime& timeStamp, const CcpDateTime& dateTime ) CcpTime TimeNow() { CcpTime time = 0; - GetSystemTimeAsFileTime( (FILETIME*)&time ); + + // Moved to reinterpret-cast to make the pointer conversion explicit + // GetSystemTimeAsFileTime( (FILETIME*)&time ); + GetSystemTimeAsFileTime( reinterpret_cast( &time ) ); return time; } - #elif defined(__APPLE__) #include diff --git a/include/CcpFileUtils.h b/include/CcpFileUtils.h index ec729af..33fc88d 100644 --- a/include/CcpFileUtils.h +++ b/include/CcpFileUtils.h @@ -54,6 +54,7 @@ CARBON_CORE_API std::wstring CcpExecutablePath(); CARBON_CORE_API int CcpOpenFile( const wchar_t* filename, CcpOpenMode mode, CcpShareMode shareMode ); CARBON_CORE_API int CcpCreateFile( const wchar_t* filename, CcpShareMode shareMode ); CARBON_CORE_API void CcpCloseFile( int fd ); +CARBON_CORE_API bool CcpTruncateFile( const std::wstring& filename ); CARBON_CORE_API ssize_t CcpReadFromFile( int fd, void* buf, size_t numBytes ); CARBON_CORE_API ssize_t CcpWriteToFile( int fd, const void* buf, size_t numBytes ); CARBON_CORE_API off_t CcpLseek( int fd, off_t offset, int whence );