0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

ircd::fs: Add fd::opts getter from open fd.

This commit is contained in:
Jason Volk 2019-04-22 09:09:20 -07:00
parent d08bcc2f32
commit 7d55468511
2 changed files with 24 additions and 0 deletions

View file

@ -33,6 +33,7 @@ struct ircd::fs::fd
operator const int &() const;
operator bool() const;
bool operator!() const;
opts options() const;
int release() noexcept;

View file

@ -1630,6 +1630,29 @@ noexcept
return fdno;
}
ircd::fs::fd::opts
ircd::fs::fd::options()
const
{
opts ret;
ret.flags = syscall(::fcntl, int(*this), F_GETFL, 0);
if((ret.flags & O_RDONLY) == O_RDONLY)
ret.mode = std::ios::in;
if((ret.flags & O_WRONLY) == O_WRONLY)
ret.mode = std::ios::out;
if((ret.flags & O_RDWR) == O_RDWR)
ret.mode = std::ios::in | std::ios::out;
ret.direct = ret.flags & O_DIRECT;
ret.cloexec = ret.flags & O_CLOEXEC;
ret.nocreate = ~ret.flags & O_CREAT;
ret.blocking = ret.flags & O_NONBLOCK;
return ret;
}
///////////////////////////////////////////////////////////////////////////////
//
// fs/device.h