in agent/native/ext/platform.cpp [269:320]
void streamCurrentProcessCommandLineImpl( TextOutputStream* txtOutStream, size_t maxLength, FILE* procSelfCmdLineFile )
{
ELASTIC_APM_ASSERT_VALID_PTR( txtOutStream );
ELASTIC_APM_ASSERT_VALID_PTR( procSelfCmdLineFile );
enum { auxBufferSize = 100 };
char auxBuffer[ auxBufferSize ];
bool reachedEndOfFile = false;
bool isRightAfterSeparator = false;
size_t numberOfCharsProcessed = 0;
while ( ! reachedEndOfFile )
{
size_t actuallyReadBytes = fread( auxBuffer, /* data item size: */ 1, /* max data items count: */ auxBufferSize, procSelfCmdLineFile );
if ( actuallyReadBytes < auxBufferSize )
{
if ( ferror( procSelfCmdLineFile ) != 0 )
{
streamPrintf( txtOutStream, "<Failed to read from %s>", g_procSelfCmdLineFileName );
return;
}
reachedEndOfFile = ( feof( procSelfCmdLineFile ) != 0 );
if ( ! reachedEndOfFile )
{
streamPrintf( txtOutStream, "<fread did not read full buffer from %s but feof() returned false>", g_procSelfCmdLineFileName );
return;
}
}
ELASTIC_APM_FOR_EACH_INDEX( i, actuallyReadBytes )
{
if ( auxBuffer[ i ] == '\0' )
{
isRightAfterSeparator = true;
continue;
}
if ( isRightAfterSeparator )
{
streamCharUpToMaxLength( txtOutStream, ' ', maxLength, &numberOfCharsProcessed );
isRightAfterSeparator = false;
}
streamCharUpToMaxLength( txtOutStream, auxBuffer[ i ], maxLength, &numberOfCharsProcessed );
}
}
if ( numberOfCharsProcessed > maxLength )
{
streamPrintf( txtOutStream, " <skipped remaining %" PRIu64 " characters>", (UInt64)( numberOfCharsProcessed - maxLength ) );
}
}