0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd::fs: Add fd::opts direct and cloexec flags; reorg fd ctor related.

This commit is contained in:
Jason Volk 2018-05-30 04:12:27 -07:00
parent 9787885ca4
commit 8395a7844c
2 changed files with 12 additions and 4 deletions

View file

@ -47,6 +47,8 @@ struct ircd::fs::fd::opts
ulong flags {0};
ulong mask {0};
bool ate {false};
bool direct {false};
bool cloexec {true};
opts(const std::ios::open_mode &);
opts() = default;

View file

@ -357,7 +357,6 @@ ircd::fs::fd::opts::opts(const std::ios::open_mode &mode)
:flags
{
posix_flags(mode)
| O_CLOEXEC
}
,mask
{
@ -383,10 +382,17 @@ ircd::fs::fd::fd(const string_view &path)
ircd::fs::fd::fd(const string_view &path,
const opts &opts)
:fdno
:fdno{[&path, &opts]
() -> int
{
int(syscall(::open, path_str(path), int(opts.flags), mode_t(opts.mask)))
}
int flags(opts.flags);
flags |= opts.direct? O_DIRECT : 0U;
flags |= opts.cloexec? O_CLOEXEC : 0U;
const mode_t &mode(opts.mask);
const char *const &p(path_str(path));
return syscall(::open, p, flags, mode);
}()}
{
if(opts.ate)
syscall(::lseek, fdno, 0, SEEK_END);