Fix posix pthread_yield and readdir_r deprecations on linux

This commit is contained in:
Stephen Saunders 2023-02-16 00:06:43 -05:00
parent ea2982c445
commit 3029b80486
4 changed files with 30 additions and 23 deletions

View file

@ -277,11 +277,12 @@ Sys_Yield
*/
void Sys_Yield()
{
#if defined(__ANDROID__) || defined(__APPLE__)
// SRS - pthread_yield() is deprecated on linux
//#if defined(__ANDROID__) || defined(__APPLE__)
sched_yield();
#else
pthread_yield();
#endif
//#else
// pthread_yield();
//#endif
}
/*

View file

@ -449,9 +449,11 @@ void Sys_ReLaunch()
DIR* devfd = opendir( "/dev/fd" );
if( devfd != NULL )
{
struct dirent entry;
//struct dirent entry;
struct dirent* result;
while( readdir_r( devfd, &entry, &result ) == 0 )
//while( readdir_r( devfd, &entry, &result ) == 0 )
// SRS - readdir_r() is deprecated on linux, readdir() is thread safe with different dir streams
while( ( result = readdir( devfd ) ) != NULL )
{
const char* filename = result->d_name;
char* endptr = NULL;

View file

@ -345,9 +345,11 @@ void Sys_ReLaunch()
DIR* devfd = opendir( "/dev/fd" );
if( devfd != NULL )
{
struct dirent entry;
//struct dirent entry;
struct dirent* result;
while( readdir_r( devfd, &entry, &result ) == 0 )
//while( readdir_r( devfd, &entry, &result ) == 0 )
// SRS - readdir_r() is deprecated on linux, readdir() is thread safe with different dir streams
while( ( result = readdir( devfd ) ) != NULL )
{
const char* filename = result->d_name;
char* endptr = NULL;

View file

@ -594,23 +594,25 @@ int Sys_ListFiles( const char* directory, const char* extension, idStrList& list
// DG: use readdir_r instead of readdir for thread safety
// the following lines are from the readdir_r manpage.. fscking ugly.
int nameMax = pathconf( directory, _PC_NAME_MAX );
if( nameMax == -1 )
{
nameMax = 255;
}
int direntLen = offsetof( struct dirent, d_name ) + nameMax + 1;
//int nameMax = pathconf( directory, _PC_NAME_MAX );
//if( nameMax == -1 )
//{
// nameMax = 255;
//}
//int direntLen = offsetof( struct dirent, d_name ) + nameMax + 1;
struct dirent* entry = ( struct dirent* )Mem_Alloc( direntLen, TAG_CRAP );
//struct dirent* entry = ( struct dirent* )Mem_Alloc( direntLen, TAG_CRAP );
if( entry == NULL )
{
common->Warning( "Sys_ListFiles: Mem_Alloc for entry failed!" );
closedir( fdir );
return 0;
}
//if( entry == NULL )
//{
// common->Warning( "Sys_ListFiles: Mem_Alloc for entry failed!" );
// closedir( fdir );
// return 0;
//}
while( readdir_r( fdir, entry, &d ) == 0 && d != NULL )
//while( readdir_r( fdir, entry, &d ) == 0 && d != NULL )
// SRS - readdir_r() is deprecated on linux, readdir() is thread safe with different dir streams
while( ( d = readdir( fdir ) ) != NULL )
{
// DG end
idStr::snPrintf( search, sizeof( search ), "%s/%s", directory, d->d_name );
@ -640,7 +642,7 @@ int Sys_ListFiles( const char* directory, const char* extension, idStrList& list
}
closedir( fdir );
Mem_Free( entry );
//Mem_Free( entry );
if( debug )
{