fs/FileInfo: add fstat() wrapper
This commit is contained in:
parent
1ca5d6baa6
commit
34182990ef
@ -8,6 +8,8 @@
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windef.h> // for HWND (needed by winbase.h)
|
#include <windef.h> // for HWND (needed by winbase.h)
|
||||||
#include <winbase.h> // for FILE_*_INFO
|
#include <winbase.h> // for FILE_*_INFO
|
||||||
|
#else
|
||||||
|
#include "io/FileDescriptor.hxx"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FileInfo::FileInfo(Path path, bool follow_symlinks)
|
FileInfo::FileInfo(Path path, bool follow_symlinks)
|
||||||
@ -55,4 +57,12 @@ GetFileInfoByHandle(HANDLE handle, FileInfo &info) noexcept
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
FileInfo::FileInfo(FileDescriptor fd)
|
||||||
|
{
|
||||||
|
if (fstat(fd.Get(), &st) < 0)
|
||||||
|
throw MakeErrno("Failed to access file");
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
class FileDescriptor;
|
||||||
|
|
||||||
class FileInfo {
|
class FileInfo {
|
||||||
friend bool GetFileInfo(Path path, FileInfo &info,
|
friend bool GetFileInfo(Path path, FileInfo &info,
|
||||||
bool follow_symlinks) noexcept;
|
bool follow_symlinks) noexcept;
|
||||||
@ -21,8 +23,6 @@ class FileInfo {
|
|||||||
friend bool GetFileInfoByHandle(HANDLE handle, FileInfo &info) noexcept;
|
friend bool GetFileInfoByHandle(HANDLE handle, FileInfo &info) noexcept;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
friend class FileReader;
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WIN32_FILE_ATTRIBUTE_DATA data;
|
WIN32_FILE_ATTRIBUTE_DATA data;
|
||||||
#else
|
#else
|
||||||
@ -36,6 +36,8 @@ public:
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
explicit FileInfo(HANDLE handle);
|
explicit FileInfo(HANDLE handle);
|
||||||
|
#else
|
||||||
|
explicit FileInfo(FileDescriptor fd);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
constexpr bool IsRegular() const noexcept {
|
constexpr bool IsRegular() const noexcept {
|
||||||
|
@ -73,12 +73,7 @@ FileReader::GetFileInfo() const
|
|||||||
{
|
{
|
||||||
assert(IsDefined());
|
assert(IsDefined());
|
||||||
|
|
||||||
FileInfo info;
|
return FileInfo{fd};
|
||||||
const bool success = fstat(fd.Get(), &info.st) == 0;
|
|
||||||
if (!success)
|
|
||||||
throw MakeErrno("Failed to access file");
|
|
||||||
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t
|
std::size_t
|
||||||
|
Loading…
Reference in New Issue
Block a user