From 4ae0c43c6f72173719322ae9e9ac093417a583ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 18 Dec 2023 20:36:05 +0800 Subject: [PATCH] IO: remove support of `FF_PATHTYPE_LINK` --- src/common/io/io.h | 42 ++++++++++++++++++++++++++++++++------ src/common/io/io_unix.c | 20 ------------------ src/common/io/io_windows.c | 20 +----------------- 3 files changed, 37 insertions(+), 45 deletions(-) diff --git a/src/common/io/io.h b/src/common/io/io.h index c311feb76..f499d1332 100644 --- a/src/common/io/io.h +++ b/src/common/io/io.h @@ -75,15 +75,45 @@ static inline bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer) //Bit flags, combine with | typedef enum FFPathType { - FF_PATHTYPE_REGULAR = 1, - FF_PATHTYPE_LINK = 2, - FF_PATHTYPE_DIRECTORY = 4 + FF_PATHTYPE_FILE = 1 << 0, + FF_PATHTYPE_DIRECTORY = 1 << 1, + FF_PATHTYPE_ANY = FF_PATHTYPE_FILE | FF_PATHTYPE_DIRECTORY, } FFPathType; -#define FF_PATHTYPE_FILE (FF_PATHTYPE_REGULAR | FF_PATHTYPE_LINK) -#define FF_PATHTYPE_ANY (FF_PATHTYPE_FILE | FF_PATHTYPE_DIRECTORY) +static inline bool ffPathExists(const char* path, FFPathType pathType) +{ + #ifdef _WIN32 + + DWORD attr = GetFileAttributesA(path); + + if(attr == INVALID_FILE_ATTRIBUTES) + return false; + + if(pathType & FF_PATHTYPE_FILE && !(attr & FILE_ATTRIBUTE_DIRECTORY)) + return true; + + if(pathType & FF_PATHTYPE_DIRECTORY && (attr & FILE_ATTRIBUTE_DIRECTORY)) + return true; + + #else + + struct stat fileStat; + if(stat(path, &fileStat) != 0) + return false; + + unsigned int mode = fileStat.st_mode & S_IFMT; + + if(pathType & FF_PATHTYPE_FILE && mode == S_IFREG) + return true; + + if(pathType & FF_PATHTYPE_DIRECTORY && mode == S_IFDIR) + return true; + + #endif + + return false; +} -bool ffPathExists(const char* path, FFPathType pathType); bool ffPathExpandEnv(const char* in, FFstrbuf* out); #define FF_IO_TERM_RESP_WAIT_MS 100 // #554 diff --git a/src/common/io/io_unix.c b/src/common/io/io_unix.c index e4b9e62e1..fcfe05718 100644 --- a/src/common/io/io_unix.c +++ b/src/common/io/io_unix.c @@ -103,26 +103,6 @@ bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) return ffAppendFDBuffer(fd, buffer); } -bool ffPathExists(const char* path, FFPathType type) -{ - struct stat fileStat; - if(stat(path, &fileStat) != 0) - return false; - - unsigned int mode = fileStat.st_mode & S_IFMT; - - if(type & FF_PATHTYPE_REGULAR && mode == S_IFREG) - return true; - - if(type & FF_PATHTYPE_DIRECTORY && mode == S_IFDIR) - return true; - - if(type & FF_PATHTYPE_LINK && mode == S_IFLNK) - return true; - - return false; -} - bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* out) { bool result = false; diff --git a/src/common/io/io_windows.c b/src/common/io/io_windows.c index f4a3747aa..3a520f098 100644 --- a/src/common/io/io_windows.c +++ b/src/common/io/io_windows.c @@ -37,7 +37,7 @@ bool ffAppendFDBuffer(HANDLE handle, FFstrbuf* buffer) LARGE_INTEGER fileSize; if(!GetFileSizeEx(handle, &fileSize)) fileSize.QuadPart = 0; - + if (fileSize.QuadPart > 0) { // optimize for files has a fixed length, @@ -87,24 +87,6 @@ bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) return ffAppendFDBuffer(handle, buffer); } -bool ffPathExists(const char* path, FFPathType type) -{ - DWORD attr = GetFileAttributesA(path); - if(attr == INVALID_FILE_ATTRIBUTES) - return false; - - if(type & FF_PATHTYPE_REGULAR && !(attr & FILE_ATTRIBUTE_DIRECTORY)) - return true; - - if(type & FF_PATHTYPE_DIRECTORY && (attr & FILE_ATTRIBUTE_DIRECTORY)) - return true; - - if(type & FF_PATHTYPE_LINK && (attr & FILE_ATTRIBUTE_REPARSE_POINT)) - return true; - - return false; -} - bool ffPathExpandEnv(const char* in, FFstrbuf* out) { DWORD length = ExpandEnvironmentStringsA(in, NULL, 0);