diff --git a/src/system/FileDescriptor.cxx b/src/system/FileDescriptor.cxx index 51a57512b..1f6bf0808 100644 --- a/src/system/FileDescriptor.cxx +++ b/src/system/FileDescriptor.cxx @@ -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 { diff --git a/src/system/FileDescriptor.hxx b/src/system/FileDescriptor.hxx index 11e32caf3..92cdddce6 100644 --- a/src/system/FileDescriptor.hxx +++ b/src/system/FileDescriptor.hxx @@ -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. */