0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 01:59:33 +02:00

ircd::fs::fd: Replace open(2) with openat(2); additional constructor.

This commit is contained in:
Jason Volk 2020-05-20 18:20:47 -07:00
parent 56219f9eaa
commit a1de7e8e08
2 changed files with 25 additions and 5 deletions

View file

@ -42,6 +42,7 @@ struct ircd::fs::fd
int release() noexcept;
explicit fd(const int &);
fd(const int &dirfd, const string_view &path, const opts &);
fd(const string_view &path, const opts &);
fd(const string_view &path);
fd() = default;

View file

@ -1994,19 +1994,38 @@ ircd::fs::fd::opts::opts(const std::ios::openmode &mode)
//
ircd::fs::fd::fd(const int &fdno)
:fdno{fdno}
:fdno
{
fdno
}
{
}
ircd::fs::fd::fd(const string_view &path)
:fd{path, opts{}}
:fd
{
path, opts{}
}
{
}
ircd::fs::fd::fd(const string_view &path,
const opts &opts)
:fd
{
AT_FDCWD, path, opts
}
{
}
ircd::fs::fd::fd(const int &dirfd,
const string_view &path,
const opts &opts)
try
:fdno{-1}
:fdno
{
-1 // sentinel value for inert dtor
}
{
const mode_t mode
{
@ -2033,11 +2052,11 @@ try
const prof::syscall_usage_warning message
{
"fs::fs::fd(): open(2): %s", path
"fs::fs::fd(): openat(2): %s", path
};
assert((flags & ~O_CREAT) || mode != 0);
fdno = syscall(::open, path_cstr(path), flags, mode);
fdno = syscall(::openat, dirfd, path_cstr(path), flags, mode);
if(advise)
fs::advise(*this, advise);