system/FileDescriptor: add method IsRegularFile()

This commit is contained in:
Max Kellermann 2018-08-24 18:52:00 +02:00 committed by Max Kellermann
parent ca9daf5e19
commit 4c2434788f
2 changed files with 13 additions and 0 deletions

View File

@ -59,6 +59,13 @@ FileDescriptor::IsValid() const noexcept
return IsDefined() && fcntl(fd, F_GETFL) >= 0;
}
bool
FileDescriptor::IsRegularFile() const noexcept
{
struct stat st;
return IsDefined() && fstat(fd, &st) == 0 && S_ISREG(st.st_mode);
}
bool
FileDescriptor::IsPipe() const noexcept
{

View File

@ -78,6 +78,12 @@ public:
gcc_pure
bool IsValid() const noexcept;
/**
* Ask the kernel whether this is a regular file.
*/
gcc_pure
bool IsRegularFile() const noexcept;
/**
* Ask the kernel whether this is a pipe.
*/