summaryrefslogtreecommitdiff
path: root/src/system
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-08-20 16:05:03 +0200
committerMax Kellermann <max@musicpd.org>2018-08-20 16:05:03 +0200
commitb5c569cd30f8a657b543356e0b563f86b23ab832 (patch)
tree55c284272760127f048744b6a07a10a22340ac80 /src/system
parent11396d4fba1346ccbd534b13b1a4aa8500a9a60c (diff)
system/FileDescriptor: add IsPipe(), IsSocket()
Diffstat (limited to 'src/system')
-rw-r--r--src/system/FileDescriptor.cxx14
-rw-r--r--src/system/FileDescriptor.hxx12
2 files changed, 26 insertions, 0 deletions
diff --git a/src/system/FileDescriptor.cxx b/src/system/FileDescriptor.cxx
index 403aee068..e8760f370 100644
--- a/src/system/FileDescriptor.cxx
+++ b/src/system/FileDescriptor.cxx
@@ -65,6 +65,20 @@ FileDescriptor::IsValid() const noexcept
return IsDefined() && fcntl(fd, F_GETFL) >= 0;
}
+bool
+FileDescriptor::IsPipe() const noexcept
+{
+ struct stat st;
+ return IsDefined() && fstat(fd, &st) == 0 && S_ISFIFO(st.st_mode);
+}
+
+bool
+FileDescriptor::IsSocket() const noexcept
+{
+ struct stat st;
+ return IsDefined() && fstat(fd, &st) == 0 && S_ISSOCK(st.st_mode);
+}
+
#endif
bool
diff --git a/src/system/FileDescriptor.hxx b/src/system/FileDescriptor.hxx
index 1cc780050..a6e32b963 100644
--- a/src/system/FileDescriptor.hxx
+++ b/src/system/FileDescriptor.hxx
@@ -75,6 +75,18 @@ public:
*/
gcc_pure
bool IsValid() const noexcept;
+
+ /**
+ * Ask the kernel whether this is a pipe.
+ */
+ gcc_pure
+ bool IsPipe() const noexcept;
+
+ /**
+ * Ask the kernel whether this is a socket descriptor.
+ */
+ gcc_pure
+ bool IsSocket() const noexcept;
#endif
/**