From 60a3aae35f6a4174ab9596fe713f8a8d84cbf949 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 19 Jan 2022 13:54:31 +0100 Subject: [PATCH] io/FileDescriptor: add OpenReadOnly() overload with directory fd --- src/io/FileDescriptor.cxx | 10 ++++++++++ src/io/FileDescriptor.hxx | 10 ++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/io/FileDescriptor.cxx b/src/io/FileDescriptor.cxx index f8dd37b31..a7337db8c 100644 --- a/src/io/FileDescriptor.cxx +++ b/src/io/FileDescriptor.cxx @@ -122,6 +122,16 @@ FileDescriptor::OpenReadOnly(const char *pathname) noexcept 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 bool diff --git a/src/io/FileDescriptor.hxx b/src/io/FileDescriptor.hxx index acc6778a3..1259edf11 100644 --- a/src/io/FileDescriptor.hxx +++ b/src/io/FileDescriptor.hxx @@ -27,8 +27,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef FILE_DESCRIPTOR_HXX -#define FILE_DESCRIPTOR_HXX +#pragma once #include #include @@ -135,6 +134,11 @@ public: bool OpenReadOnly(const char *pathname) noexcept; +#ifdef __linux__ + bool OpenReadOnly(FileDescriptor dir, + const char *pathname) noexcept; +#endif + #ifndef _WIN32 bool OpenNonBlocking(const char *pathname) noexcept; #endif @@ -271,5 +275,3 @@ public: bool IsReadyForWriting() const noexcept; #endif }; - -#endif