system/FileDescriptor: add IsPipe(), IsSocket()
This commit is contained in:
parent
11396d4fba
commit
b5c569cd30
@ -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
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user