diff options
author | Max Kellermann <max@duempel.org> | 2015-02-27 19:08:04 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-02-27 19:15:31 +0100 |
commit | 6b3b1cbd995ec2313427a6fe0b1607938cc71794 (patch) | |
tree | fd92f7ee6607a84c81718e97bfe3d1d4b4321dad /src | |
parent | 4dd861ee2351a9e3ac32b6aa744965a683f52955 (diff) | |
download | mpd-6b3b1cbd995ec2313427a6fe0b1607938cc71794.tar.gz mpd-6b3b1cbd995ec2313427a6fe0b1607938cc71794.tar.xz mpd-6b3b1cbd995ec2313427a6fe0b1607938cc71794.zip |
fs/FileSystem: use GetFileAttributes() on WIN32 if possible
Diffstat (limited to '')
-rw-r--r-- | src/fs/FileSystem.hxx | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/fs/FileSystem.hxx b/src/fs/FileSystem.hxx index 6f19c8ed3..c0c77129c 100644 --- a/src/fs/FileSystem.hxx +++ b/src/fs/FileSystem.hxx @@ -26,10 +26,15 @@ #include "Path.hxx" +#ifdef WIN32 +#include <fileapi.h> +#endif + #include <sys/stat.h> #include <unistd.h> #include <stdio.h> + class AllocatedPath; namespace FOpenMode { @@ -128,8 +133,15 @@ CheckAccess(Path path, int mode) static inline bool FileExists(Path path, bool follow_symlinks = true) { +#ifdef WIN32 + (void)follow_symlinks; + + const auto a = GetFileAttributes(path.c_str()); + return a != INVALID_FILE_ATTRIBUTES && (a & FILE_ATTRIBUTE_NORMAL); +#else struct stat buf; return StatFile(path, buf, follow_symlinks) && S_ISREG(buf.st_mode); +#endif } /** @@ -138,8 +150,15 @@ FileExists(Path path, bool follow_symlinks = true) static inline bool DirectoryExists(Path path, bool follow_symlinks = true) { +#ifdef WIN32 + (void)follow_symlinks; + + const auto a = GetFileAttributes(path.c_str()); + return a != INVALID_FILE_ATTRIBUTES && (a & FILE_ATTRIBUTE_DIRECTORY); +#else struct stat buf; return StatFile(path, buf, follow_symlinks) && S_ISDIR(buf.st_mode); +#endif } /** @@ -149,8 +168,7 @@ static inline bool PathExists(Path path) { #ifdef WIN32 - struct stat buf; - return StatFile(path, buf); + return GetFileAttributes(path.c_str()) != INVALID_FILE_ATTRIBUTES; #else return CheckAccess(path, F_OK); #endif |