io/FileDescriptor: add OpenReadOnly() overload with directory fd

This commit is contained in:
Max Kellermann 2022-01-19 13:54:31 +01:00 committed by Max Kellermann
parent bc3415ce8b
commit 60a3aae35f
2 changed files with 16 additions and 4 deletions

View File

@ -122,6 +122,16 @@ FileDescriptor::OpenReadOnly(const char *pathname) noexcept
return Open(pathname, O_RDONLY); return Open(pathname, O_RDONLY);
} }
#ifdef __linux__
bool
FileDescriptor::OpenReadOnly(FileDescriptor dir, const char *pathname) noexcept
{
return Open(dir, pathname, O_RDONLY);
}
#endif // __linux__
#ifndef _WIN32 #ifndef _WIN32
bool bool

View File

@ -27,8 +27,7 @@
* OF THE POSSIBILITY OF SUCH DAMAGE. * OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef FILE_DESCRIPTOR_HXX #pragma once
#define FILE_DESCRIPTOR_HXX
#include <cstddef> #include <cstddef>
#include <utility> #include <utility>
@ -135,6 +134,11 @@ public:
bool OpenReadOnly(const char *pathname) noexcept; bool OpenReadOnly(const char *pathname) noexcept;
#ifdef __linux__
bool OpenReadOnly(FileDescriptor dir,
const char *pathname) noexcept;
#endif
#ifndef _WIN32 #ifndef _WIN32
bool OpenNonBlocking(const char *pathname) noexcept; bool OpenNonBlocking(const char *pathname) noexcept;
#endif #endif
@ -271,5 +275,3 @@ public:
bool IsReadyForWriting() const noexcept; bool IsReadyForWriting() const noexcept;
#endif #endif
}; };
#endif