@@ -75,15 +75,45 @@ static inline bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer)
7575//Bit flags, combine with |
7676typedef enum FFPathType
7777{
78- FF_PATHTYPE_REGULAR = 1 ,
79- FF_PATHTYPE_LINK = 2 ,
80- FF_PATHTYPE_DIRECTORY = 4
78+ FF_PATHTYPE_FILE = 1 << 0 ,
79+ FF_PATHTYPE_DIRECTORY = 1 << 1 ,
80+ FF_PATHTYPE_ANY = FF_PATHTYPE_FILE | FF_PATHTYPE_DIRECTORY ,
8181} FFPathType ;
8282
83- #define FF_PATHTYPE_FILE (FF_PATHTYPE_REGULAR | FF_PATHTYPE_LINK)
84- #define FF_PATHTYPE_ANY (FF_PATHTYPE_FILE | FF_PATHTYPE_DIRECTORY)
83+ static inline bool ffPathExists (const char * path , FFPathType pathType )
84+ {
85+ #ifdef _WIN32
86+
87+ DWORD attr = GetFileAttributesA (path );
88+
89+ if (attr == INVALID_FILE_ATTRIBUTES )
90+ return false;
91+
92+ if (pathType & FF_PATHTYPE_FILE && !(attr & FILE_ATTRIBUTE_DIRECTORY ))
93+ return true;
94+
95+ if (pathType & FF_PATHTYPE_DIRECTORY && (attr & FILE_ATTRIBUTE_DIRECTORY ))
96+ return true;
97+
98+ #else
99+
100+ struct stat fileStat ;
101+ if (stat (path , & fileStat ) != 0 )
102+ return false;
103+
104+ unsigned int mode = fileStat .st_mode & S_IFMT ;
105+
106+ if (pathType & FF_PATHTYPE_FILE && mode == S_IFREG )
107+ return true;
108+
109+ if (pathType & FF_PATHTYPE_DIRECTORY && mode == S_IFDIR )
110+ return true;
111+
112+ #endif
113+
114+ return false;
115+ }
85116
86- bool ffPathExists (const char * path , FFPathType pathType );
87117bool ffPathExpandEnv (const char * in , FFstrbuf * out );
88118
89119#define FF_IO_TERM_RESP_WAIT_MS 100 // #554
0 commit comments