From 182bff76382d59f44f0ac3c69beb55dacde75eb5 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 16 Oct 2020 18:13:24 +0300 Subject: add path.hpp: CanonicalPath class, etc. Apparently, relative paths in the Win32 namespace (e.g. \\?\test.txt) are not a thing. --- include/winapi/file.hpp | 3 +++ include/winapi/path.hpp | 25 +++++++++++++++++++++++++ include/winapi/stream.hpp | 4 ++++ 3 files changed, 32 insertions(+) create mode 100644 include/winapi/path.hpp (limited to 'include') diff --git a/include/winapi/file.hpp b/include/winapi/file.hpp index 60a8f1d..221047b 100644 --- a/include/winapi/file.hpp +++ b/include/winapi/file.hpp @@ -6,6 +6,7 @@ #pragma once #include "handle.hpp" +#include "path.hpp" #include #include @@ -17,7 +18,9 @@ public: explicit File(Handle&& handle) : Handle{std::move(handle)} {} static Handle open_for_reading(const std::string&); + static Handle open_for_reading(const CanonicalPath&); static Handle open_for_writing(const std::string&); + static Handle open_for_writing(const CanonicalPath&); using Handle::close; diff --git a/include/winapi/path.hpp b/include/winapi/path.hpp new file mode 100644 index 0000000..f2b0aa9 --- /dev/null +++ b/include/winapi/path.hpp @@ -0,0 +1,25 @@ +// Copyright (c) 2020 Egor Tensin +// This file is part of the "winapi-common" project. +// For details, see https://github.com/egor-tensin/winapi-common. +// Distributed under the MIT License. + +#pragma once + +#include + +namespace winapi { + +class CanonicalPath { +public: + static std::string canonicalize(const std::string&); + + explicit CanonicalPath(const std::string&); + + std::string get() const { return m_path; } + std::string path() const { return get(); } + +private: + std::string m_path; +}; + +} // namespace winapi diff --git a/include/winapi/stream.hpp b/include/winapi/stream.hpp index 6b4bc38..ed5b40c 100644 --- a/include/winapi/stream.hpp +++ b/include/winapi/stream.hpp @@ -6,6 +6,7 @@ #pragma once #include "handle.hpp" +#include "path.hpp" #include "pipe.hpp" #include @@ -45,6 +46,7 @@ inline void swap(Stream& a, Stream& b) BOOST_NOEXCEPT_OR_NOTHROW { struct Stdin : Stream { Stdin(); explicit Stdin(const std::string& file); + explicit Stdin(const CanonicalPath& file); explicit Stdin(Pipe&); // VS 2013 won't generate these automatically. @@ -62,6 +64,7 @@ struct Stdin : Stream { struct Stdout : Stream { Stdout(); explicit Stdout(const std::string& file); + explicit Stdout(const CanonicalPath& file); explicit Stdout(Pipe&); // VS 2013 won't generate these automatically. @@ -79,6 +82,7 @@ struct Stdout : Stream { struct Stderr : Stream { Stderr(); explicit Stderr(const std::string& file); + explicit Stderr(const CanonicalPath& file); explicit Stderr(Pipe&); // VS 2013 won't generate these automatically. -- cgit v1.2.3