Replace getline().

This commit is contained in:
Bartosz Taudul 2021-12-21 20:28:11 +01:00
parent 7f10265e34
commit efae847690
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -1485,21 +1485,25 @@ void SysTraceGetExternalName( uint64_t thread, const char*& threadName, const ch
f = fopen( fn, "rb" ); f = fopen( fn, "rb" );
if( f ) if( f )
{ {
char* tmp = (char*)tracy_malloc_fast( 8*1024 );
const auto fsz = (ptrdiff_t)fread( tmp, 1, 8*1024, f );
fclose( f );
int pid = -1; int pid = -1;
size_t lsz = 1024; auto line = tmp;
auto line = (char*)tracy_malloc_fast( lsz );
for(;;) for(;;)
{ {
auto rd = getline( &line, &lsz, f );
if( rd <= 0 ) break;
if( memcmp( "Tgid:\t", line, 6 ) == 0 ) if( memcmp( "Tgid:\t", line, 6 ) == 0 )
{ {
pid = atoi( line + 6 ); pid = atoi( line + 6 );
break; break;
} }
while( line - tmp < fsz && *line != '\n' ) line++;
if( *line != '\n' ) break;
line++;
} }
tracy_free_fast( line ); tracy_free_fast( tmp );
fclose( f );
if( pid >= 0 ) if( pid >= 0 )
{ {
{ {