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:
parent
9787885ca4
commit
8395a7844c
|
@ -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;
|
||||
|
|
14
ircd/fs.cc
14
ircd/fs.cc
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue