Skip to content

Commit 4ae0c43

Browse files
committed
IO: remove support of FF_PATHTYPE_LINK
1 parent e89d475 commit 4ae0c43

File tree

3 files changed

+37
-45
lines changed

3 files changed

+37
-45
lines changed

src/common/io/io.h

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,45 @@ static inline bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer)
7575
//Bit flags, combine with |
7676
typedef 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);
87117
bool ffPathExpandEnv(const char* in, FFstrbuf* out);
88118

89119
#define FF_IO_TERM_RESP_WAIT_MS 100 // #554

src/common/io/io_unix.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,6 @@ bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer)
103103
return ffAppendFDBuffer(fd, buffer);
104104
}
105105

106-
bool ffPathExists(const char* path, FFPathType type)
107-
{
108-
struct stat fileStat;
109-
if(stat(path, &fileStat) != 0)
110-
return false;
111-
112-
unsigned int mode = fileStat.st_mode & S_IFMT;
113-
114-
if(type & FF_PATHTYPE_REGULAR && mode == S_IFREG)
115-
return true;
116-
117-
if(type & FF_PATHTYPE_DIRECTORY && mode == S_IFDIR)
118-
return true;
119-
120-
if(type & FF_PATHTYPE_LINK && mode == S_IFLNK)
121-
return true;
122-
123-
return false;
124-
}
125-
126106
bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* out)
127107
{
128108
bool result = false;

src/common/io/io_windows.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bool ffAppendFDBuffer(HANDLE handle, FFstrbuf* buffer)
3737
LARGE_INTEGER fileSize;
3838
if(!GetFileSizeEx(handle, &fileSize))
3939
fileSize.QuadPart = 0;
40-
40+
4141
if (fileSize.QuadPart > 0)
4242
{
4343
// optimize for files has a fixed length,
@@ -87,24 +87,6 @@ bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer)
8787
return ffAppendFDBuffer(handle, buffer);
8888
}
8989

90-
bool ffPathExists(const char* path, FFPathType type)
91-
{
92-
DWORD attr = GetFileAttributesA(path);
93-
if(attr == INVALID_FILE_ATTRIBUTES)
94-
return false;
95-
96-
if(type & FF_PATHTYPE_REGULAR && !(attr & FILE_ATTRIBUTE_DIRECTORY))
97-
return true;
98-
99-
if(type & FF_PATHTYPE_DIRECTORY && (attr & FILE_ATTRIBUTE_DIRECTORY))
100-
return true;
101-
102-
if(type & FF_PATHTYPE_LINK && (attr & FILE_ATTRIBUTE_REPARSE_POINT))
103-
return true;
104-
105-
return false;
106-
}
107-
10890
bool ffPathExpandEnv(const char* in, FFstrbuf* out)
10991
{
11092
DWORD length = ExpandEnvironmentStringsA(in, NULL, 0);

0 commit comments

Comments
 (0)