Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions CCPLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
#include <windows.h>
#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
{
Expand Down Expand Up @@ -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<decltype(localBuffer)>, format, args ) > ( std::extent_v<decltype(localBuffer)> - 1 ) )
{
Expand All @@ -229,7 +233,7 @@ CARBON_CORE_API void LogFuncChannel_v( CcpLogChannel_t& logObject, LogType type,

output = s_largeBuffer;
vsnprintf( output, std::extent_v<decltype(s_largeBuffer)>, format, argCopy2 );
assert( s_largeBuffer[65534] == '\0' );
assert( s_largeBuffer[LOG_LARGE_BUFFER_SIZE - 1] == '\0' );
}

LogFuncChannelRaw( logObject, type, userData, output );
Expand Down
21 changes: 21 additions & 0 deletions CcpFileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 4 additions & 2 deletions CcpTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FILETIME*>( &time ) );
return time;
}


#elif defined(__APPLE__)

#include <mach/mach_time.h>
Expand Down
1 change: 1 addition & 0 deletions include/CcpFileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down