mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-30 00:41:17 +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()
|
CFile::CFile()
|
||||||
: Size( 0 ), Mode( 0 ), Marked( false ), Time( 0 )
|
: Size( 0 ), Mode( 0 ), Marked( false ), Time( 0 )
|
||||||
{
|
{
|
||||||
|
Type = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFile::FileType CFile::getType(void) const
|
CFile::FileType CFile::getType(void) const
|
||||||
@@ -77,18 +78,20 @@ CFile::FileType CFile::getType(void) const
|
|||||||
if(S_ISDIR(Mode))
|
if(S_ISDIR(Mode))
|
||||||
return FILE_DIR;
|
return FILE_DIR;
|
||||||
|
|
||||||
|
if (Type < 0) {
|
||||||
|
Type = (int) FILE_UNKNOWN;
|
||||||
std::string::size_type ext_pos = Name.rfind('.');
|
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]);
|
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);
|
void * result = ::bsearch(&key, file_extension_list, sizeof(file_extension_list) / sizeof(const char *), sizeof(const char *), mycasecmp);
|
||||||
|
|
||||||
if (result != NULL)
|
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,6 +48,8 @@
|
|||||||
|
|
||||||
class CFile
|
class CFile
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
mutable int Type;
|
||||||
public:
|
public:
|
||||||
enum FileType
|
enum FileType
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user