mirror of
https://github.com/w23/xash3d-fwgs
synced 2024-12-15 21:50:59 +01:00
engine: common: filesystem: speed up directory existense check on POSIX by using stat() instead of opendir()
This commit is contained in:
parent
81b01ac561
commit
4fbd96d201
@ -2477,7 +2477,7 @@ qboolean FS_SysFileExists( const char *path, qboolean caseinsensitive )
|
|||||||
|
|
||||||
close( desc );
|
close( desc );
|
||||||
return true;
|
return true;
|
||||||
#else
|
#elif XASH_POSIX
|
||||||
int ret;
|
int ret;
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
|
||||||
@ -2495,6 +2495,8 @@ qboolean FS_SysFileExists( const char *path, qboolean caseinsensitive )
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
return S_ISREG( buf.st_mode );
|
return S_ISREG( buf.st_mode );
|
||||||
|
#else
|
||||||
|
#error
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2529,23 +2531,18 @@ qboolean FS_SysFolderExists( const char *path )
|
|||||||
DWORD dwFlags = GetFileAttributes( path );
|
DWORD dwFlags = GetFileAttributes( path );
|
||||||
|
|
||||||
return ( dwFlags != -1 ) && ( dwFlags & FILE_ATTRIBUTE_DIRECTORY );
|
return ( dwFlags != -1 ) && ( dwFlags & FILE_ATTRIBUTE_DIRECTORY );
|
||||||
#else
|
#elif XASH_POSIX
|
||||||
DIR *dir = opendir( path );
|
struct stat buf;
|
||||||
|
|
||||||
if( dir )
|
if( stat( path, &buf ) < 0 )
|
||||||
{
|
|
||||||
closedir( dir );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if( (errno == ENOENT) || (errno == ENOTDIR) )
|
|
||||||
{
|
{
|
||||||
|
Con_Reportf( S_ERROR "FS_SysFolderExists: problem while opening dir: %s\n", strerror( errno ));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
return S_ISDIR( buf.st_mode );
|
||||||
Con_Reportf( S_ERROR "FS_SysFolderExists: problem while opening dir: %s\n", strerror( errno ) );
|
#else
|
||||||
return false;
|
#error
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user