(trunk libT) silently add a \0 after the end of files read by tr_loadFile() so that text files can be handled directly as ascii strings

This commit is contained in:
Charles Kerr
2009-04-28 20:42:55 +00:00
parent d13ac450d8
commit acb3b443f7

View File

@@ -497,7 +497,7 @@ tr_loadFile( const char * path,
errno = err;
return NULL;
}
buf = malloc( sb.st_size );
buf = malloc( sb.st_size + 1 );
if( !buf )
{
const int err = errno;
@@ -517,6 +517,7 @@ tr_loadFile( const char * path,
}
tr_close_file( fd );
buf[ sb.st_size ] = '\0';
*size = sb.st_size;
return buf;
}