summaryrefslogtreecommitdiff
path: root/src/system
diff options
context:
space:
mode:
authorMax Kellermann <mk@cm4all.com>2018-08-24 18:52:00 +0200
committerMax Kellermann <max@musicpd.org>2019-08-19 19:11:53 +0200
commit4c2434788f2473953b833695aa4ab5e029f25159 (patch)
treee602658de1663108535bb5bbb8fc939411ab2833 /src/system
parentca9daf5e190efa26024143632b01afa0e85001fb (diff)
system/FileDescriptor: add method IsRegularFile()
Diffstat (limited to 'src/system')
-rw-r--r--src/system/FileDescriptor.cxx7
-rw-r--r--src/system/FileDescriptor.hxx6
2 files changed, 13 insertions, 0 deletions
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
@@ -60,6 +60,13 @@ FileDescriptor::IsValid() const noexcept
}
bool
+FileDescriptor::IsRegularFile() const noexcept
+{
+ struct stat st;
+ return IsDefined() && fstat(fd, &st) == 0 && S_ISREG(st.st_mode);
+}
+
+bool
FileDescriptor::IsPipe() const noexcept
{
struct stat st;
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
@@ -79,6 +79,12 @@ public:
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.
*/
gcc_pure