system/FileDescriptor: add openat() wrapper

This commit is contained in:
Max Kellermann 2018-08-21 18:15:37 +02:00
parent 9151b84c25
commit d036e20826
2 changed files with 17 additions and 0 deletions

View File

@ -76,6 +76,18 @@ FileDescriptor::IsSocket() const noexcept
#endif
#ifdef __linux
bool
FileDescriptor::Open(FileDescriptor dir, const char *pathname,
int flags, mode_t mode) noexcept
{
fd = ::openat(dir.Get(), pathname, flags | O_NOCTTY | O_CLOEXEC, mode);
return IsDefined();
}
#endif
bool
FileDescriptor::Open(const char *pathname, int flags, mode_t mode) noexcept
{

View File

@ -116,6 +116,11 @@ public:
return FileDescriptor(-1);
}
#ifdef __linux
bool Open(FileDescriptor dir, const char *pathname,
int flags, mode_t mode=0666) noexcept;
#endif
bool Open(const char *pathname, int flags, mode_t mode=0666) noexcept;
#ifdef _WIN32