Commit b5c569cd authored by Max Kellermann's avatar Max Kellermann

system/FileDescriptor: add IsPipe(), IsSocket()

parent 11396d4f
......@@ -80,6 +80,7 @@ public:
using FileDescriptor::IsDefined;
#ifndef _WIN32
using FileDescriptor::IsValid;
using FileDescriptor::IsSocket;
#endif
using FileDescriptor::Get;
using FileDescriptor::Set;
......
......@@ -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
......
......@@ -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
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment