From eb0ff32efb9f5220d1d7baf01078540e1e4d027e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 10 Aug 2017 19:34:44 +0200 Subject: [PATCH] system/FileDescriptor: add Open() overload with wchar_t path --- src/system/FileDescriptor.cxx | 11 +++++++++++ src/system/FileDescriptor.hxx | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/src/system/FileDescriptor.cxx b/src/system/FileDescriptor.cxx index 4e4365cf9..38fa43b2d 100644 --- a/src/system/FileDescriptor.cxx +++ b/src/system/FileDescriptor.cxx @@ -74,6 +74,17 @@ FileDescriptor::Open(const char *pathname, int flags, mode_t mode) noexcept return IsDefined(); } +#ifdef _WIN32 + +bool +FileDescriptor::Open(const wchar_t *pathname, int flags, mode_t mode) noexcept +{ + fd = ::_wopen(pathname, flags | O_NOCTTY | O_CLOEXEC, mode); + return IsDefined(); +} + +#endif + bool FileDescriptor::OpenReadOnly(const char *pathname) noexcept { diff --git a/src/system/FileDescriptor.hxx b/src/system/FileDescriptor.hxx index 57ffba3cf..a049ad71d 100644 --- a/src/system/FileDescriptor.hxx +++ b/src/system/FileDescriptor.hxx @@ -43,6 +43,10 @@ #include #endif +#ifdef _WIN32 +#include +#endif + /** * An OO wrapper for a UNIX file descriptor. * @@ -97,6 +101,11 @@ public: } bool Open(const char *pathname, int flags, mode_t mode=0666) noexcept; + +#ifdef _WIN32 + bool Open(const wchar_t *pathname, int flags, mode_t mode=0666) noexcept; +#endif + bool OpenReadOnly(const char *pathname) noexcept; #ifndef WIN32