mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 16:31:11 +02:00
driver/file.cpp: cache file type
This commit is contained in:
@@ -70,6 +70,7 @@ int mycasecmp(const void * a, const void * b)
|
||||
CFile::CFile()
|
||||
: Size( 0 ), Mode( 0 ), Marked( false ), Time( 0 )
|
||||
{
|
||||
Type = -1;
|
||||
}
|
||||
|
||||
CFile::FileType CFile::getType(void) const
|
||||
@@ -77,18 +78,20 @@ CFile::FileType CFile::getType(void) const
|
||||
if(S_ISDIR(Mode))
|
||||
return FILE_DIR;
|
||||
|
||||
if (Type < 0) {
|
||||
Type = (int) FILE_UNKNOWN;
|
||||
std::string::size_type ext_pos = Name.rfind('.');
|
||||
|
||||
if (ext_pos != std::string::npos)
|
||||
{
|
||||
if (ext_pos != std::string::npos) {
|
||||
const char * key = &(Name.c_str()[ext_pos + 1]);
|
||||
|
||||
void * result = ::bsearch(&key, file_extension_list, sizeof(file_extension_list) / sizeof(const char *), sizeof(const char *), mycasecmp);
|
||||
|
||||
if (result != NULL)
|
||||
return file_type_list[(const char * *)result - (const char * *)&file_extension_list];
|
||||
Type = (int) file_type_list[(const char * *)result - (const char * *)&file_extension_list];
|
||||
}
|
||||
return FILE_UNKNOWN;
|
||||
}
|
||||
return (CFile::FileType) Type;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
@@ -48,7 +48,9 @@
|
||||
|
||||
class CFile
|
||||
{
|
||||
public:
|
||||
private:
|
||||
mutable int Type;
|
||||
public:
|
||||
enum FileType
|
||||
{
|
||||
FILE_UNKNOWN = 0,
|
||||
|
Reference in New Issue
Block a user